备份postgresql数据库的最佳方法是什么?
我试过在www.postgresql.org上使用这个文档,但是在恢复的时候我总是得到完整性错误。
现在我正在使用这个备份:
pg_dump -U myuser -d mydatabase db.pg.dump
恢复:
pg_restore -c -r -U myuser -d mydatabase db.pg.dump
但是我没有得到理想的结果
编辑:我应该注意到,我的数据库有很多外键。
我看到的一些错误是:
ERROR: current transaction is aborted, commands ignored until end of transaction block ERROR: zero-length delimited identifier at or near """" LINE 1: ..._text_id_fkey" FOREIGN KEY ("text_id") REFERENCES ""."wiki_t...
从pg_restore手册页:
pg_restore是一个实用程序,用于从pg_dump(1)以非纯文本格式之一创build的归档中恢复PostgreSQL数据库。
从pg_dump手册页:
转储可以以脚本或档案文件格式输出。 脚本转储是纯文本文件,包含将数据库重build为保存时的状态所需的SQL命令。 要从这样的脚本中恢复,请将其提供给psql(1)。 即使在其他机器和其他架构上,也可以使用脚本文件重build数据库; 即使在其他SQL数据库产品上也有一些修改。
替代档案文件格式必须与pg_restore(1)一起使用来重build数据库。 它们允许pg_restore对恢复的内容进行select,甚至可以在恢复之前对项目进行重新sorting。
你不会告诉它以非纯文本格式转储。 你正在告诉它恢复一个非纯文本格式。 显然这是不行的。
从pg_dump手册页:
EXAMPLES To dump a database called mydb into a SQL-script file: $ pg_dump mydb > db.sql To reload such a script into a (freshly created) database named newdb: $ psql -d newdb -f db.sql To dump a database into a custom-format archive file: $ pg_dump -Fc mydb > db.dump To reload an archive file into a (freshly created) database named newdb: $ pg_restore -d newdb db.dump