PostgreSQL includes a utility called
pg_dump that can be used to dump database information into a file for backup purposes.
pg_dump utility is run from the Linux command line. The basic syntax of the command is:
pg_dump name_of_database > name_of_backup_file
The command must be run by a user with privileges to read all of the database information, so it is run as the superuser most of the time.
For a real-world example, we can log into the
postgresuser user and execute the command on the default database, called
$ sudo su - postgresuser $ pg_dump postgresdb > postgresdb_backup
To restore a backup created by pg_dump, you can redirect the file into psql standard input, but you need an empty database created prior to restore.
psql empty_database < backup_file
Note: This redirection operation does not create the database in question. This must be done in a separate step prior to running the command.
$ psql postgresnewdb < postgresdb_backup
You need to login before you can make any post submission.