2

我正在尝试恢复数据库。数据库 sql 文件大约 4.5 GB,所以我无法在编辑器上编辑它。我在 postgres 12 中使用以下命令转储数据库;

pg_dump -d postgres > backup.sql

但我在 postgres 9.6 中需要相同的数据库。为此,我编写了以下代码来恢复它

psql -d postgres < backup.sql

它显示这样的错误(创建序列时出错)。但这不是给定问题的重复项。错误信息;

SET
ERROR:  unrecognized configuration parameter "default_table_access_method"
CREATE TABLE
ALTER TABLE
ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
ERROR:  relation "epicenter.epicenter_gid_seq" does not exist
ERROR:  relation "epicenter.epicenter_gid_seq" does not exist
CREATE TABLE
ALTER TABLE
ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
ERROR:  relation "public.725_4.5_tur_gid_seq" does not exist
ERROR:  relation "public.725_4.5_tur_gid_seq" does not exist
CREATE TABLE
ALTER TABLE

我看到了这个问题的答案。答案已经说过 sql 文件不适用于旧版本。但我想知道,有没有办法使用这个sql文件恢复?

4

1 回答 1

3

感谢@jjanes 和@JGH 的友好合作。我找到了一个解决方案。首先,我使用以下命令备份数据库;

pg_dump -U postgres -h localhost -p 5432 -W earthquake | gzip -c > backup.gz

然后我从pgadmin 4. 获取backup.gz文件后,我在终端中使用以下命令恢复它;

gzip -d -c backup.gz | sed -e '/AS integer/d' | psql -U postgres -h localhost -p 5432 -W earthquake
于 2019-12-16T04:00:37.740 回答