Backing Up and Restoring PostgreSQL Databases

By Ercan S. - 17/04/2025 - 0 comments

This guide outlines the steps to back up and restore PostgreSQL databases using command-line tools on Windows.

Backing Up a Database

To back up a PostgreSQL database, use the `pg_dump` utility:

.\pg_dump.exe -U <username> -d <database_name> > <dump_path>

Example:

.\pg_dump.exe -U postgres -d testdb > C:\Users\Ercan\Desktop\dump.sql

Restoring a Database

To restore a PostgreSQL database from a backup, use the `psql` utility:

.\psql.exe -U <username> -d <database_name> < <dump_path>

Example:

.\psql.exe -U postgres -d testdb < C:\Users\Ercan\Desktop\dump.sql

Ensure that the specified user has the necessary privileges to perform backup and restore operations.

 

Tags: postgresql, dump, restore