简体   繁体   English

从 .pgdump 文件恢复 postgresql 数据库

[英]Restore a postgresql database from a .pgdump file

I have a.pgdump file, which I want to use it to restore the database.我有一个.pgdump 文件,我想用它来恢复数据库。 I've tried pg_restore -d dbname datadump_filename in psql, but I got nothing.我在 psql 中尝试过pg_restore -d dbname datadump_filename ,但我什么也没得到。 I ensured the path for PostgreSQL Binary Path in pgAdmin4 is the correct work directory where the dump file is.我确保 pgAdmin4 中PostgreSQL Binary Path的路径是转储文件所在的正确工作目录。

The data dump file is binary file.数据转储文件是二进制文件。

There are several things I changed to make it work.我改变了几件事以使其工作。

I changed the pgAdmin4 path to the pg_restore path.我将 pgAdmin4 路径更改为 pg_restore 路径。 To get the path on Mac, I ran which psql in the terminal.为了在 Mac 上获取路径,我在终端中运行了which psql

Then I created a new db manually in pgAdmin4 mydb然后我在 pgAdmin4 mydb中手动创建了一个新的数据库

Lastly, ran the command in the terminal pg_restore -x --no-owner mydb <DATA DUMP FILE>最后,在终端pg_restore -x --no-owner mydb <DATA DUMP FILE>中运行命令

The -x --no-owner flags stops pg_restore trying to set the ownership of the objects to the original owner. -x --no-owner标志停止 pg_restore 尝试将对象的所有权设置为原始所有者。

-d flag can be ignored if the db was created manually.如果数据库是手动创建的,则可以忽略-d标志。

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

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