How to restore PostgreSQL database

Today I'm going to share how to restore the PostgreSQL database. First, let me tell you what problem I have solved with it. I was working with some existing columns of a table and needed some data that was not in my local host so it was really in need of uploading the production database to the local host so that I could access all the updated data, table, and column.

So I got a .gz folder that contains the main database. I have downloaded that file and extracted it into the downloads folder. Suppose the file name was productionDb.gz now after extraction new file is productionDb.

Now visit your PostgreSQL bin folder here is the example of my installed location in the c drive.

C:\Program Files\PostgreSQL\14\bin

Open cmd on this location and write this command,

psql -U [username] -p 5432 -d [databaseName] -f [file-path]

Here you must replace [username] with your postgreSQL username and [databaseName] with your new database name and also the [file-path] with your downloaded database file path that you want to restore.

psql -U [username] -p 5432 -d [databaseName] -f C:\Users\shoha\Downloads\productionDb

After you write this command properly press enter then it will ask to insert password, so type PostgreSQL password and then it starts creating, altering the database.

You are successfully done.

0 Comments