pg_dump backup compression

When executing a pg_dump which should I use and why?

pg_dump -U <user> <database> | gzip -c > backup.gz

or

pg_dump -F c -f backup.tar.gz -U <user> <database>


Solution 1:

According to the pg_dump documentation the custom format is:

the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default

You can also select the compression level with the -Z option.

For simplicity I would definitely go for pg_dump -F c over piping to gzip.