From 3f740e64c77cbee2aa31cca160748d7387b8474b Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sat, 30 Aug 2025 11:29:32 +0200 Subject: [PATCH] chore(postgres): slightly extend knowledge on tools --- knowledge base/postgresql/README.md | 6 +++++- knowledge base/postgresql/pg_dump.md | 26 ++++++++++++++++++++++++- knowledge base/postgresql/pg_dumpall.md | 23 +++++++++++++++++++++- knowledge base/postgresql/pg_restore.md | 2 ++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/knowledge base/postgresql/README.md b/knowledge base/postgresql/README.md index 2743061..82bc886 100644 --- a/knowledge base/postgresql/README.md +++ b/knowledge base/postgresql/README.md @@ -178,7 +178,8 @@ SELECT * FROM entries_in_column('vendors','vendor_id'); ## Backup -PostgreSQL offers the `pg_dump` and `pg_dumpall` native client utilities to dump databases to files.
+PostgreSQL offers the [`pg_dump`][pg_dump] and [`pg_dumpall`][pg_dumpall] native client utilities to dump databases to +files.
They produce sets of SQL statements that can be executed to reproduce the original databases' object definitions and table data. @@ -241,6 +242,7 @@ pg_dumpall … -g --no-role-passwords > A list of common backup tools can be found in the [PostgreSQL Wiki][wiki], in the [Backup][wiki backup] page.
+See also [dimitri/pgcopydb].
For the _limited_™ experience accrued until now, the TL;DR is: - Prefer [pg_dumpall], and eventually [pg_dump], for **logical** backups.
@@ -357,6 +359,7 @@ See also [yugabyte/yugabyte-db]. - [How to Scale a Single-Server Database: A Guide to Distributed PostgreSQL] - [yugabyte/yugabyte-db] - [Logical Decoding Concepts] +- [dimitri/pgcopydb] ### Sources @@ -403,6 +406,7 @@ See also [yugabyte/yugabyte-db]. [the password file]: https://www.postgresql.org/docs/current/libpq-pgpass.html [wiki]: https://wiki.postgresql.org/wiki/ [wiki backup]: https://wiki.postgresql.org/wiki/Ecosystem:Backup +[dimitri/pgcopydb]: https://github.com/dimitri/pgcopydb [an in-depth guide to postgres data masking with anonymizer]: https://thelinuxcode.com/postgresql-anonymizer-data-masking/ diff --git a/knowledge base/postgresql/pg_dump.md b/knowledge base/postgresql/pg_dump.md index 0dcf5d7..6d87f11 100644 --- a/knowledge base/postgresql/pg_dump.md +++ b/knowledge base/postgresql/pg_dump.md @@ -3,7 +3,9 @@ > [!caution] > TODO -Intro +Command-line tool for creating backups of a **single** PostgreSQL database.
+Consider using [`pg_dumpall`][pg_dumpall] to create backups of entire clusters, or global objects like roles and +tablespaces. @@ -14,6 +16,26 @@ Intro ## 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`][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. + [A Complete Guide to pg_dump With Examples, Tips, and Tricks]: https://www.dbvis.com/thetable/a-complete-guide-to-pg-dump-with-examples-tips-and-tricks/ +[How to speed up pg_dump when dumping large databases]: https://postgres.ai/docs/postgres-howtos/database-administration/backup-recovery/how-to-speed-up-pg-dump diff --git a/knowledge base/postgresql/pg_dumpall.md b/knowledge base/postgresql/pg_dumpall.md index de8d4e5..61381b1 100644 --- a/knowledge base/postgresql/pg_dumpall.md +++ b/knowledge base/postgresql/pg_dumpall.md @@ -3,7 +3,9 @@ > [!caution] > TODO -Intro +Command-line tool for creating backups of entire PostgreSQL clusters, and/or global objects like roles and +tablespaces.
+Consider using [`pg_dump`][pg_dump] to create backups of a single database when nothing else is needed. @@ -14,6 +16,25 @@ Intro ## TL;DR +It can dump databases in their entirety, or just specific parts of them such as individual tables or schemas.
+It **can** dump objects like roles, groups, tablespace and others. + +It produces sets of SQL statements that can be executed to reproduce the original databases' object definitions and +table data. + +Suitable when: + +- The databases' size is **less** than 100 GB.
+ It tends to start giving issues for bigger databases. +- One plans to migrate the databases' metadata as well as the table data. +- There is a relatively large number of tables to migrate. + +> [!important] +> `pg_dumpall` 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_dumpall` will **always** produce +> consistent results thanks to ACID properties. + +[How to use pg_restore]: https://postgres.ai/docs/postgres-howtos/database-administration/backup-recovery/how-to-use-pg-restore