Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple database backup using pg_dump

Is it possible to backup multiple databases with a single pg_dump command, instead of running a pg_dump command for each database

like image 860
user3837299 Avatar asked Oct 20 '25 06:10

user3837299


1 Answers

It looks like it is possible using the pg_dumpall command: https://www.postgresql.org/docs/9.6/static/app-pg-dumpall.html.

From the documentation:

Description

pg_dumpall is a utility for writing out ("dumping") all PostgreSQL databases of a cluster into one script file. The script file contains SQL commands that can be used as input to psql to restore the databases. It does this by calling pg_dump for each database in a cluster. pg_dumpall also dumps global objects that are common to all databases. (pg_dump does not save these objects.) This currently includes information about database users and groups, tablespaces, and properties such as access permissions that apply to databases as a whole.

Since pg_dumpall reads tables from all databases you will most likely have to connect as a database superuser in order to produce a complete dump. Also you will need superuser privileges to execute the saved script in order to be allowed to add users and groups, and to create databases.

The SQL script will be written to the standard output. Use the [-f|file] option or shell operators to redirect it into a file.

like image 77
ZedTuX Avatar answered Oct 21 '25 22:10

ZedTuX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!