【问题标题】:Create Databse in Windows from command-line or VBScript?从命令行或 VBScript 在 Windows 中创建数据库?
【发布时间】:2018-05-21 18:48:47
【问题描述】:

如何在 Windows 中通过命令行或 VBScript 为 PostgreSQL 10 (pgAdmin 4) 创建新数据库?

我在命令行中使用了以下命令:

pg_dump --dbname=postgresql://postgres:123@localhost:5432/myDB --format=p --clean

但是它返回了以下错误:

pg_dump: [archiver (db)] 连接到数据库“myDB”失败:无法连接到服务器:连接被拒绝 (0x0000274D/10061)

服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?

无法连接到服务器:连接被拒绝 (0x0000274D/10061)

服务器是否在主机“localhost”(127.0.0.1) 上运行并接受端口 5432 上的 TCP/IP 连接?

如何在“localhost”(127.0.0.1)中运行服务器?如何解决这个问题?

编辑: 另外,我也试过这个,

createdb --dbname=postgresql://postgres:123@localhost:5432/myDB --format=p --clean

得到了这个错误,

createdb: 非法选项 -- dbname=postgresql://postgres:123@localhost:5432/myDB

尝试“createdb --help”了解更多信息。

【问题讨论】:

  • 嗯...是什么让您想到pg_dump创建 数据库?也许令人惊讶的是,PostgreSQL 数据库是使用 createdb 工具创建的。
  • Ansgar Wiechers,我已经更新了问题。可以查一下吗?
  • 请自行阅读documentation

标签: database windows postgresql cmd vbscript


【解决方案1】:

感谢JasenMladen Uzelac,我在here 找到了解决方案。这是创建数据库的命令行,

cd "C:\Program Files (x86)\PostgreSQL\10\bin"
psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 2012-11-03
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    相关资源
    最近更新 更多