加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 在pg_restore中,如何使用postgres连接字符串指定

发布时间:2020-12-13 16:21:42 所属栏目:百科 来源:网络整理
导读:使用pg_dump时,可以使用postgres连接字符串指定主机/数据库/用户名/密码: pg_dump postgres://someuser:somepassword@somehost.com:5432/somedatabase 我想为pg_restore使用相同类型的连接字符串: pg_restore -f dump.dump postgres://userb:somepassword@
使用pg_dump时,可以使用postgres连接字符串指定主机/数据库/用户名/密码:
pg_dump postgres://someuser:somepassword@somehost.com:5432/somedatabase

我想为pg_restore使用相同类型的连接字符串:

pg_restore -f dump.dump postgres://userb:somepassword@somehost.com:5432/otherdatabase

但是我收到一个错误:

pg_restore: [archiver] could not open input file "postgres://userb:somepassword@somehost.com:5432/otherdatabase": No such file or directory
在PostgreSQL工具中,只要指定数据库名称,就可以指定连接字符串.

在pg_restore的语法中,dbname与标志一起传递,而不是作为位置参数传递:

$pg_restore --help
pg_restore restores a PostgreSQL database from an archive created by pg_dump.

Usage:
  pg_restore [OPTION]... [FILE]

General options:
  -d,--dbname=NAME        connect to database name
  ...

所以你应该使用:

pg_restore -d 'postgres://userb:somepassword@somehost.com:5432/otherdatabase' dump.dump

是的,pg_dump和pg_restore之间的用户界面不匹配很糟糕,我希望我们可以改变它,但现在有点晚了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读