如何使用 pg_dump 或 psql 从 *.sql 恢复 PostgreSQL 表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9428170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How restore a PostgreSQL table from *.sql using pg_dump or psql?
提问by NiLL
I need to restore a big table (250mb) in PostgreSQL database in console tool. How I can do this using ps_dump or psql?
我需要在控制台工具中恢复 PostgreSQL 数据库中的一个大表 (250mb)。我如何使用 ps_dump 或 psql 做到这一点?
回答by Tometzky
Just connect to database with psql
and run \i /path/to/filename.sql
.
只需连接到数据库psql
并运行\i /path/to/filename.sql
。
回答by Audrius Meskauskas
psql --username yourusername --dbname yourdatabasename -f yourfile.sql
as clarified here. Depending on configuration, may ask for your password.
为澄清这里。根据配置,可能会要求您输入密码。
If it is a newly installed database engine with no your database yet, use postgres
for the database name and try to omit the username part (new installation should normally grant the full access to the current user who installed it).
如果它是新安装的数据库引擎,还没有您的数据库,请使用postgres
数据库名称并尝试省略用户名部分(新安装通常应授予安装它的当前用户的完全访问权限)。
If you still can't login, edit temporarily pg_hba.confwherever it could be in your installation and temporarily set the localhost to trusted. Then you can specify postgres both as username and as the database name.
如果您仍然无法登录,请临时编辑pg_hba.conf在您安装中的任何位置,并将本地主机临时设置为受信任。然后您可以将 postgres 指定为用户名和数据库名称。
Don't forget to revert pg_hba.conf changes when done.
完成后不要忘记恢复 pg_hba.conf 更改。
回答by Ruslan Kabalin
psql dbname < /path/to/dump.sql
You may even modify your dump on the fly if required:
如果需要,您甚至可以动态修改转储:
sed 's/OWNER TO olduser/OWNER TO newuser/g' < /path/to/dump.sql | psql dbname
回答by Bhimasen Rautaray
psql -U postgres -d doctor_dev < /home/ravi/mydevelopment