我用

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

当前回答

当我尝试用DBeaver备份db时,我得到了相同的错误。如果有人在Windows上使用DBeaver界面而不是命令行,请确保在备份和恢复设置时选择的格式为tar。

其他回答

如果使用pg_dump和-Fp进行明文备份,则使用以下命令:

cat db.txt | psql dbname

将所有数据复制到名为dbname的数据库

这是解,

pg_restore -U username -p 5432 -h 10.10.10.1 -d database_name < dump_file . pg_restore -U username -p 5432

为了使用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

如果你用这种方式备份,我想这会更容易导入数据库。

pg_dump -h(远端数据库地址)-a——column-inserts -U postgres(数据库名)>(文件名).sql

对于进口,

psql -f(文件名).sql ——host(远程数据库地址) ——端口5432 ——用户名postgres ——password(你的密码) ——dbname(你要导入的数据库)

我也一直在为这个问题挣扎。这是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