Files
oam/knowledge base/postgresql/pg_dump.md
2025-08-30 11:29:32 +02:00

2.4 KiB

pg_dump

Caution

TODO

Command-line tool for creating backups of a single PostgreSQL database.
Consider using pg_dumpall to create backups of entire clusters, or global objects like roles and tablespaces.

  1. TL;DR
  2. Further readings
    1. Sources

TL;DR

It can dump a database in its entirety, or just specific parts of it such as individual tables or schemas.
It does not dump objects like roles, groups, tablespace and others. Consider using pg_dumpall for those.

It produces sets of SQL statements that can be executed to reproduce the original databases' object definitions and table data.

Suitable when:

  • The database' size is less than 100 GB.
    It tends to start giving issues for bigger databases.
  • One plans to migrate the database' metadata as well as the table data.
  • There is a relatively large number of tables to migrate.

Important

pg_dump works better when the database is taken offline, but it does keep the database available and will not prevent users from accessing it.
Even with other users accessing the database during the backup process, pg_dump will always produce consistent results thanks to ACID properties.

Further readings

Sources