我用
pg_dump db_production > postgres_db.dump
然后使用scp将其复制到localhost。
现在当我导入我的本地db时,它给出了一个错误
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
使用命令行
pg_restore -d db_development postgres_db.dump
我用
pg_dump db_production > postgres_db.dump
然后使用scp将其复制到localhost。
现在当我导入我的本地db时,它给出了一个错误
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
使用命令行
pg_restore -d db_development postgres_db.dump
当前回答
对我来说,当我试图从远程主机恢复我使用
psql -U username -p 5432 -h 10.10.10.1 -d database < db.dump
工作得很好。如果不是远程,只是下面的命令工作。
psql -d database < db.dump
其他回答
如果使用pg_dump和-Fp进行明文备份,则使用以下命令:
cat db.txt | psql dbname
将所有数据复制到名为dbname的数据库
对我来说,就像这样。
C:\Program Files\PostgreSQL\12\bin> psql -U postgres -p 5432 -d dummy -f C:\Users\Downloads\d2cm_test.sql
创建备份时,可能希望在另一个网络中恢复它或创建远程恢复。
我们需要使用——format=custom [-Fc]创建一个备份文件,然后使用pg_restore恢复它。我们可以使用连接字符串postgresql://<user>:<pass>@localhost:5432/<dbname>并替换<user>, <pass>和<dbname>与您的信息。
pg_dump -v -Fc \
postgresql://<user>:<pass>@localhost:5432/<dbname> \
> db-20211122-163508.sql
要恢复,我们将使用——clean [-c]和——create [-c]来调用它,在恢复之前删除数据库。将<用户>,<主机>,<端口>,<dbname>替换为您的信息。
pg_restore -vcC \
-U <user> \
-h <host> \
-p <port> \
-d <dbname> \
< db-20211122-163508.sql
上面的答案对我没用,下面这个有用:
PSQL db_development < postgres_db.dump
为了使用pg_dump创建与pg_restore兼容的备份,在创建转储时必须使用——format=custom / -Fc。
从文档中可以看出:
输出适合输入到pg_restore的自定义格式的存档。
所以你的pg_dump命令可能是这样的:
pg_dump --file /tmp/db.dump --format=custom --host localhost --dbname my-source-database --username my-username --password
你的pg_restore命令:
pg_restore --verbose --clean --no-acl --no-owner --host localhost --dbname my-destination-database /tmp/db.dump