PostgreSQL database Backup Restore
Backup Database:
A. Open Command Prompt as administrator, Go to PostgreSQL\10\bin>
B. Enter command: pg_dump -U [Username] -W -F t [database_name] > C:[backup file].tar
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}
D. Check the path (C:\filename.tar) where the backup file is created.
Restore Backup Database: A. Open command prompt as administrator, Go to PostgreSQL\10\bin>
B. Login into PostgreSQL login command: psql –d [database name] –U [username]
C. Enter password to get into PostgreSQL.
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:
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:
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]]
- Then, Enter Postgres Password, as shown in the figure below:
- After restoring the CMD looks like as shown figure below: