The difference between pg_dump and pg_dumpall is that pg_dump is not as suitable for backing up database clusters. A database cluster is a group of databases that can be accessed from an instance of running the database server. The file system for a database cluster has a single directory which stores all data items.

If a pg_dumpall is performed, it backs up all databases, users, passwords, as well as other objects. The only thing required upon restoring a dumpall is access to a database (you can use the default template1 database). It needs this access to re-create the dumped databases and database objects. Superuser permission may be required depending on your system. See note on Permissions.

Pg_dumpall is a wrapper around the pg_dump command. The options for a pg_dumpall are:

-c, --clean

Cleans the schema before it creates the schema.

-h, --host= host_name

Specifies which host database server is to be contacted. If this option is not specified, it defaults to the local host or the PGHOST environment variable.

-p, --port= port_num

Specifies which port number to use. If this option is not used in the command, it defaults to the port indicated in the PGPORT environment variable.

-g, --globals-only

Using this option causes it to only dump global objects.

To do a simple dumpall, supply the following command:

  pg_dumpall >  output_file

Note Permissions

You will need access to the postgres superuser to perform a dumpall because it dumps all of the users and databases on the system. You also need superuser permission to restore the dumpall because it creates users, groups, databases, and other objects upon restoration.

The only issue with pg_dumpall is that it cannot continually authenticate to each database it dumps data into. If your database setup requires password authentication, then you will need to set the PGPASSWORD environment variable. If you have a different set of password for each database, then the dumpall will fail. You can choose a different type of authentication method or onfigure the pg_dumpall script to fit your needs.