我用
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> -d <database-name> -h <host-name> -f <backup.sql> . p
其他回答
这是解,
pg_restore -U username -p 5432 -h 10.10.10.1 -d database_name < dump_file . pg_restore -U username -p 5432
创建备份时,可能希望在另一个网络中恢复它或创建远程恢复。
我们需要使用——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
对我来说,就像这样。
C:\Program Files\PostgreSQL\12\bin> psql -U postgres -p 5432 -d dummy -f C:\Users\Downloads\d2cm_test.sql
我也一直在为这个问题挣扎。这是dump和restore命令的组合,对我来说很有效:
pg_dump -Ft -C -h database_host -U username database > DATA.dump
恢复
pg_restore -x --no-owner -d database DATA.dump
如果您想在您的DB中保持相同的访问权限(acl),请删除-x标志。为此,在数据库中必须具有相同的角色和用户。
https://www.postgresql.org/docs/15/app-pgdump.html
https://www.postgresql.org/docs/15/app-pgrestore.html
如果您恢复。sql文件。 在pgAdmin中创建一个新数据库。 进入终端,浏览.sql文件所在的文件夹/目录。然后在终端中写入以下命令。
让: 超自然用户后
Examaple:
sudo -u postgres psql newDb < restoreDb.sql