Overview

Logical backup refers to simple export of a data, achieved by the pg_dump. Logical backups are vastly used between different versions. For example transfer of a database between PostgreSQL 9.6 → 11. It is important to note that logical backup cannot be used in conjunction of XLOG or other incremental features, but it is very convenient for data migration.

Logical backup can also be configured in many ways, as simple as to dump a particular database in SQL script file. In nutshell there are two things which you should remember:

Dump global data: like roles and users with pg_dumpall

Dump a particular database: with pg_dump

Furthermore, the best way is to use a customer format “-Fc” in order to preserve consistency across versions:

Our backup will not be so much readable with text editors:

Or even, further to dump the database in a directory using 5 slaves:

Restore

In terms of logical backup, restore and recovery are the same thing. It means, execute the script in order to REDO the changes. Simple way will be just to execute the script as follows:

Backup taken in plain SQL

However BARE IN MIND ONE PROBLEM :)

pg_dump: Restore with psql

pg_dump -Fc: Restore with pg_restore

Appendix

Here is a nice script to automate the export of all databases on a server:

Which can be put in crontab as follows: