Skip to content

PostgreSQL database Backup Restore

Backup Database:

A. Open Command Prompt as administrator, Go to PostgreSQL\10\bin>

Image

B. Enter command: pg_dump -U [Username] -W -F t [database_name] > C:[backup file].tar

Image

C. Give your PostgreSQL’s Password. {while user type the password during that time, it may not be visible, just insert the password and hit enter button}

Image

D. Check the path (C:\filename.tar) where the backup file is created.

Image

Restore Backup Database: A. Open command prompt as administrator, Go to PostgreSQL\10\bin>

Image

B. Login into PostgreSQL login command: psql –d [database name] –U [username]

Image

C. Enter password to get into PostgreSQL.

Image

D. Create a new database in PostgreSQL. E. Enter command to create new database name: create database [database name]; F. Enter Postgres Password, as shown in the figure below:

Image

Image

Note: The Command Prompt shows CREATE DATABASE alert, as the database created successfully. G. The press CTRL + z to exit the command area of Postgres SQL, as shown in the figure below:

Image

H. Enter Command to restore the database in created database: Command:
pg_restore -h localhost -p 5432 –U [username] –d [backup database name] –v [“backup file path”] OR [psql -h localhost -p 5432 -U [Postgres username] -f “[C:\path location\filename.tar]” [database name]]

Image

  • Then, Enter Postgres Password, as shown in the figure below:

Image

  • After restoring the CMD looks like as shown figure below:

Image