PostgreSQL Backup & Recovery
pgadmin4
Backup
Restore
If the target database already exists, consider dropping it and recreating it before starting the restore.
pg_dump/pg_restore
Backup
To export...
pg_dump -U username dbname > outputfile.sql
To export schema only (no data)...
pg_dump -s myschema > myschema.sqlÂ
To do this from a remote machine...
pg_dump -s -h myhost -U myuser -C myschema > myschema.sql
To backup all databases...
pg_dumpall -h myhost -U postgres -W > outputfile.sql
To backup all tables that start with "AO_8542F1"
pg_dump -h myhost -U atljira -W -t "\"AO_8542F1\"*" -f AO_8542F1.sql jira
In Jira, tables starting with AO_8542F1 relate to the Assets (previosuly Mindville Insight) functionality.Note that the escaped quotes \" ensure that the text is not "folded" to lower case. The * is a wildcard.See: https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-PATTERNS for more information.PGDATABASEPGHOSTPGOPTIONSPGPORTPGUSERPG_COLOR
-?
character setoutput to fileplain,custom,directory,tarhostnamerun in parallelonly matching schemasexclude matchingdon't set ownershipportobsoleteno datause when disable triggersonly matching tablesexclude matchingusernameverbose modeshow versionnever prompt passwrdforce password promptno grant/revokecompression leveldo not useuse INSERT commands
exclude data keep def
use with --clean
use INSERT commands
role name used for dump
help
Restore
To restore from a 'plain' text file...
psql -U username dbname -f outputfile.sql
To restore from any file type, other than plain text (see above), created by pg_dump...
pg_restore -h myhost -U username -W -d mydatabase -v outputfile.sql
To restore our backup of all tables that start with "AO_8542F1"
pg_restore -h myhost -U atljira -W -d jira -v -c AO_8542F1.sql
In Jira, tables starting with AO_8542F1 relate to the Assets (previosuly Mindville Insight) functionality.-?
help
Bibliography
https://www.postgresql.org/docs/8.1/backup-online.html
https://www.postgresql.org/docs/9.2/backup.htmlhttps://www.postgresql.org/docs/11/backup.html
https://docs.vmware.com/en/Site-Recovery-Manager/8.1/com.vmware.srm.install_config.doc/GUID-E1FC67CD-48E3-4B25-AA1D-8A2408F5B517.html
SQL Dumphttps://www.postgresql.org/docs/11/backup-dump.html
pg_dump/pg_restorehttps://www.a2hosting.com/kb/developer-corner/postgresql/import-and-export-a-postgresql-databasehttps://www.enterprisedb.com/download-postgresql-binarieshttps://tecadmin.net/backup-and-restore-database-in-postgresql/https://www.postgresqltutorial.com/postgresql-administration/postgresql-backup-databasehttps://stackoverflow.com/questions/7359827/creating-a-database-dump-for-specific-tables-and-entries-postgreshttps://askubuntu.com/questions/501091/command-pg-dump-not-foundhttps://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-PATTERNShttps://dba.stackexchange.com/questions/242992/how-to-restore-a-postgres-database-created-via-an-older-version-of-postgreshttps://stackoverflow.com/questions/2732474/restore-a-postgres-backup-file-using-the-command-linehttps://www.postgresql.org/docs/current/app-pgrestore.htmlhttps://www.postgresql.org/docs/9.3/app-pgdump.htmlhttps://www.postgresql.org/docs/current/app-pgdump.htmlhttps://www.postgresql.org/docs/9.3/app-pgrestore.htmlhttps://www.postgresql.org/docs/current/app-pgrestore.html
File System Level Backupshttps://www.postgresql.org/docs/11/backup-file.html
Continuous Archiving and Point In Time Recovery (PITR)https://www.postgresql.org/docs/11/continuous-archiving.html
Otherhttps://stackoverflow.com/questions/33594039/pg-dump-and-pg-restore-across-different-major-versions-of-postgresqlhttps://stackoverflow.com/questions/12836312/postgresql-9-2-pg-dump-version-mismatchhttps://askubuntu.com/questions/646603/how-do-i-solve-a-server-version-mismatch-with-pg-dump-when-i-need-both-postgrehttps://www.eversql.com/exporting-mysql-schema-structure-to-xml-using-mysql-clients/