1

I have large databases which im dumping with pg_dump and I need to make dump file smaller. What is the best way to compress this postgres database dump file?

3 Answers 3

2

pg_dump comes with compression feature built-in:

  • -Z 0..9
  • --compress 0..9

Specify the compression level to use. Zero means no compression. For the custom archive format, this specifies compression of individual table-data segments, and the default is to compress at a moderate level. For plain text output, setting a nonzero compression level causes the entire output file to be compressed, as though it had been fed through gzip; but the default is not to compress. The tar archive format currently does not support compression at all.

There are 9 levels of compression - higher the level, higher the compression. 0 means no compression.

pg_dump [connection-option...] --compress=9 [dbname] 

for maximum compression.

1
  • @masonrye if you believe my answer was helpful, you should consider accepting it so the question won't stay as unanswered. Commented Jun 17, 2021 at 19:10
2

xz compresses data better than gzip. Running xz -6 <dumpfile> will compress the database dump with maximum compression.

1
  • 1
    "Better" is an understatement, actually. I've seen ratios of 1:100 for some dumps. Commented Oct 19, 2021 at 16:18
0

there's also parallel gzip https://zlib.net/pigz/ for when you really need to maximize all your cores on a big compression job.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.