principlesqlMajor
restoring Postgres database: pg_restore -vs- just using psql
Viewed 0 times
postgresjustrestoringdatabasepsqlusingpg_restore
Problem
I am dumping my Postgres database using pg_dump (in plain-text format) and then restore it simply by using psql (with the
Which begs the question: am I missing anything by not using pg_restore which seems like a specialized restore tool (compared to the generic
I can control options like disabling of triggers and such by using
-f option).Which begs the question: am I missing anything by not using pg_restore which seems like a specialized restore tool (compared to the generic
psql)?I can control options like disabling of triggers and such by using
pg_dump parameters. What, then, is pg_restore used for? non-plain-text dump formats ?Solution
If you created an SQL-format dump, all you can use is
If you created a custom-format (
Custom and directory format dumps offer a lot of advantages over plain SQL script dumps, and I use them exclusively. You can selectively restore only some tables/schema, can choose whether to include only schema, only data, or both at restore time, etc. Lots of the options you have to specify at
If it weren't for backward compatibility I'm sure the default for
You can't convert an SQL-format dump into custom-format or directory-format without restoring it to a PostgreSQL database and then dumping the restored DB.
psql.If you created a custom-format (
pg_dump -Fc) or directory-format (pg_dump -Fd) dump, you can and must use pg_restore.Custom and directory format dumps offer a lot of advantages over plain SQL script dumps, and I use them exclusively. You can selectively restore only some tables/schema, can choose whether to include only schema, only data, or both at restore time, etc. Lots of the options you have to specify at
pg_dump time with SQL-format dumps can be chosen at restore-time if you use a custom-format dump and pg_restore.If it weren't for backward compatibility I'm sure the default for
pg_dump would be -Fc (custom) format.You can't convert an SQL-format dump into custom-format or directory-format without restoring it to a PostgreSQL database and then dumping the restored DB.
Context
StackExchange Database Administrators Q#76417, answer score: 46
Revisions (0)
No revisions yet.