简体   繁体   English

如何从SQL脚本中还原PostgreSQL数据库

[英]How to restore a PostgreSQL database from within an SQL script

How to restore a PostgreSQL database from within an SQL script. 如何从SQL脚本中还原PostgreSQL数据库。 I want to be able to restore a PostgreSQL using SQL or psql code. 我希望能够使用SQL或psql代码还原PostgreSQL。

Assuming you are working with pg_dump, then it can depend on how it was dumped. 假设您正在使用pg_dump,那么它取决于转储的方式。 If it was dumped to a text or sql file: 如果将其转储到文本或sql文件中:

psql -U [user] -d [dbname] -1 -f <filename>.sql

Alternatively you can use pg_restore: 另外,您可以使用pg_restore:

pg_restore -U [user] -d [dbname] [filename].dump

The following postgres docs might be helpful as well. 以下postgres 文档也可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM