Search code examples
postgresqlpg-dump

Where does pgdump do its compression?


Here is the command I am using

pgdump -h localhost -p 54321 -U example_user --format custom

which dumps a database on a remote server which I have connected to with a port forward on port 54321.

I know that the custom format does some compression by default.

Does this compression happen on the database server, or does everything get sent across to my local machine where the compression happens.


Solution

  • Compression is done on the client side so everything gets sent to your computer. What pg_dump does to the database is that it just executes ordinary queries to get the data.

    PostgreSQL Documentation: 24.1. SQL Dump:

    pg_dump is a regular PostgreSQL client application (albeit a particularly clever one).

    PostgreSQL Documentation - II. PostgreSQL Client Applications - pg_dump:

    pg_dump internally executes SELECT statements. If you have problems running pg_dump, make sure you are able to select information from the database using, for example, psql.

    If you need more information about the inner workings of pg_dump I would suggest asking it from PostgreSQL mailing list or looking at the source code.