Backup and Restore a database in PostgreSQL using PG_DUMP

Logical Backup and restore a database in PostgreSQL

Backup the database with pg_dump utility:

pg_dump -d [source-database] -f [database_backup.sql]

Example: Go to the bin directory of postgreSQL and execute the following command:

pg_dump -d testdb -U postgres -f C:\testwork\test_backup.sql

Restore the database with psql command:

psql -d [destination_database] -f [database_backup.sql]

Example:
C:\Program Files\PostgreSQL\15\bin>psql -d hello -U postgres -f C:\testwork\test_backup.sq
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.