简体   繁体   中英

How to restore a PostgreSQL database from within an SQL script

How to restore a PostgreSQL database from within an SQL script. I want to be able to restore a PostgreSQL using SQL or psql code.

Assuming you are working with pg_dump, then it can depend on how it was dumped. If it was dumped to a text or sql file:

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

Alternatively you can use pg_restore:

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

The following postgres docs might be helpful as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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