diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml index c4215be..4db52fa 100644 --- a/doc/src/sgml/backup.sgml +++ b/doc/src/sgml/backup.sgml @@ -102,6 +102,43 @@ pg_dump dbname > + + However, the backup created from this method has limited usefulness. It + can be used to restore a single database in full. A more useful form of + PostgreSQL backup syntax looks like this: + +pg_dump -U username --format=c --file=mydatabase.sqlc dbname + + The options in detail are: + + -U, --username=NAME connect as specified database user + -F, --format=c|t|p output file format (custom, tar, plain text) + -f, --file=FILENAME output file name + + The most important of which is --format. + By default pg_dump uses the plaintext format. In + practice, the plaintext format is useful for very small databases with + a minimal number of objects but other than that, it should be avoided. + The custom format allows for a wealth of customizability. + + + + Using the custom format you are able to restore single objects from a + backup. For example to restore only a specified index from a backup + file: + +pg_restore -U username --dbname=dbname --index=indexname + + If you wanted to restore only a single function: + +pg_restore -U username --dbname=dbname --function=functionname(args) + + If you wanted to restore only a single table: + +pg_restore -U username --dbname=dbname --table=tablename + + + Restoring the Dump @@ -176,6 +213,35 @@ pg_dump -h host1 dbname | psql -h h + When it comes to restoring a dump with a custom format the command + used to restore a backup file is pg_restore. It has + similar options to pg_dump. A simple restore: + +pg_restore -U username --dbname=databasename filename + + Where filename is the name of the backup file. + + + + + Do not confuse + + + + If you make the mistake of creating a plaintext backup, + pg_restore can not be used as a restoration + mechanism. You can use psql to restore it: + +psql dbname < backupfile + + + + After restoring a backup, it is wise to run on each database so the query optimizer has useful statistics; @@ -222,6 +288,22 @@ psql -f infile postgres each database will be internally consistent, the snapshots of different databases might not be exactly in-sync. + + + Unfortunately, pg_dumpall can only create plaintext + backups and should be considered deprecated. However, it is the only way + to backup the globals in your cluster. A reasonable backup strategy to + backup your globals and produce a flexible backup of every database in + the cluster would look like this: + +pg_dumpall -g -Uusername --file=globals.sql; +psql -AtU postgres -c "SELECT datname FROM pg_database \ + WHERE NOT datistemplate"| \ +while read f; + do pg_dump -Upostgres --format=c --file=$f.sqlc $f; +done; + +