HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

Does my choice of pg_dump format impact restore speed?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
formatpg_dumpimpactchoicedoesspeedrestore

Problem

According to the docs for my version of Postgres (8.4.2), pg_dump can "output in script or archive file formats." The script-formatted dump (4GB) takes 1.5 hours to restore, and I'm wondering if the archive format is any faster.

My script-formatted dump is using COPY commands, by the way, so it's not like I'm doing one insert at a time.

Thanks in advance.

Solution

Archive format has small impact on restore time.

That's because actually, when you restore from plain format, it is equivalent to:

cat backup.file | psql emptydb


and when you restore from "compressed" format, it is equivalent to:

pg_restore backup.file | psql emptydb


, and the cost of decompression with pg_restore is usually negligible, compared to write-intensive COPY/CREATE INDEX commands which happen during restore.

For large dumps, restoring from compressed dumps may be a bit faster (less disk reads).

It might be even faster with -j (--jobs) option. It can be used only with "compressed" format, and it allows paralell restore with N concurrent jobs (sessions).

For more details about -j option, see http://www.postgresql.org/docs/8.4/static/app-pgrestore.html. Example:

pg_restore -j 4 -d emptydb backup.file

Code Snippets

cat backup.file | psql emptydb
pg_restore backup.file | psql emptydb
pg_restore -j 4 -d emptydb backup.file

Context

StackExchange Database Administrators Q#8855, answer score: 9

Revisions (0)

No revisions yet.