pg_dump vs pg_dumpall? which one to use to database backups?

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

I tried pg_dump and then on a separate machine I tried to import the sql and populate the database, I see

CREATE TABLE ERROR:  role "prod" does not exist CREATE TABLE ERROR:  role "prod" does not exist CREATE TABLE ERROR:  role "prod" does not exist CREATE TABLE ERROR:  role "prod" does not exist ALTER TABLE ALTER TABLE ALTER TABLE ALTER TABLE ALTER TABLE ALTER TABLE ALTER TABLE WARNING:  no privileges could be revoked for "public" REVOKE ERROR:  role "postgres" does not exist ERROR:  role "postgres" does not exist WARNING:  no privileges were granted for "public" GRANT 

which means my user and roles and grant information is not in pg_dump

On the other hand we have pg_dumpall, I read conversation, and this does not lead me anywhere?

Question
- Which one should I be using for database backups? pg_dump or pg_dumpall?
- the requirement is that I can take the backup and should be able to import to any machine and it should work just fine.

回答1:

The usual process is:

  • pg_dumpall --globals-only to get users/roles/etc
  • pg_dump -Fc for each database to get a nice compressed dump suitable for use with pg_restore.

Yes, this kind of sucks. I'd really like to teach pg_dump to embed pg_dumpall output into -Fc dumps, but right now unfortunately it doesn't know how so you have to do it yourself.

At time of writing (9.4) there's also a nasty caveat with this approach: Neither pg_dump, nor pg_dumpall in --globals-only mode, will dump user access GRANTs on DATABASEs.


You should also know about physical backups - pg_basebackup, PgBarman and WAL archiving, PITR, etc. These offer much "finer grained" recovery, down to the minute or individual transaction. The downside is that they take up more space, are only restoreable to the same PostgreSQL version on the same platform, and back up all tables in all databases with no ability to exclude anything.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!