在pg_restore中,如何使用postgres连接字符串指定主机/数据库/用户名/密码? [英] In pg_restore, how can you use a postgres connection string to specify the host/database/username/password?

查看:517
本文介绍了在pg_restore中,如何使用postgres连接字符串指定主机/数据库/用户名/密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pg_dump时,可以使用postgres连接字符串指定主机/数据库/用户名/密码:

When using pg_dump, you can use a postgres connection string to specify the host/database/username/password:

pg_dump postgres://someuser:somepassword@somehost.com:5432/somedatabase

我想使用相同的pg_restore的一种连接字符串:

I want to use the same sort of connection string for 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工具中,只要您可以指定数据库名称,就可以指定连接字符串

In PostgreSQL tools wherever you can specify a database name you can instead specify a connection string.

pg_restore 的语法中,dbname带有标志而不是位置参数:

In the syntax for pg_restore the dbname is passed with a flag, not as a positional parameter:

$ 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之间不匹配很烂,我希望我们可以更改它,但现在有点晚了。

Yes, that user interface mismatch between pg_dump and pg_restore sucks, and I wish we could change it, but it's a bit late now.

这篇关于在pg_restore中,如何使用postgres连接字符串指定主机/数据库/用户名/密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆