[prev] [index] [next]

Saving/Restoring Databases

PostgreSQL provides the pg_dump command:
  • to export the entire contents of a database to a file
  • in a format that can be used to reconstruct the database
Example: cloning a database:

$ pg_dump mydb > mydb.dump
$ createdb newdb
CREATE DATABASE
$ psql newdb -f mydb.dump
... lots of messages ...

After this, newdb is a complete copy of mydb.

This is a particularly efficient method for loading a database.