Postgres Database Export

  • 14-10-2022
  • 381
  • Postgres
  • Haresh Chauhan

This tutorial will help you to export your Postgres database from your server. There are several ways you can backup your database, like using the command, direct from the database panel. generally, the database backup file has SQL files but you still can backup different file formats.

So this article will solve your problem on how to export your pgsql database and take a backup from the server. At an end of this tutorial, you will able to backup your Postgres database very easily.

We will export the Postgres database to an SQL file, I have mentioned here some different methods to backup or export your Postgres SQL database very simple. Before that make sure you have an SFTP credential the access your server terminal.

Using SSH we will execute the command and enter the password then your database will backup on your root project.

Method 1. Using Command(Server)

Copy this suggested command and paste it into your text editor, and set your credential as per asking in the command. Therefore you required your database hostname, username, database name, and your database port.

pg_dump -Fc -h (host) -U (username) -p (post) -O (dbname) > example.sql

For example, I have a webappfix database on my local server. the command I will enter something like the below provided.

pg_dump -Fc -h -U webappfix -p 5432 -O webappfix > webappfix.sql

Postgres Database Export

Open your SFTP and go to your project root, this is not required to go root, the database file will generate where you are in the SFTP terminal. Once you enter your command fill up all the details. they will ask for the database password, just enter your database password and hit enter. The database file will generate where you are in your terminal root. This will export the .sql file extension.


Method 2. Using Command(Local)

If you are working in a local system service and want to export your database hit the below-given command in your terminal. it will directly from the .sql file from the database with .sql file where you are given the path. In my case given the leo.sql path in my D: drive, there will generate a leo.sql file.

pg_dump -U postgres -p 5432 -O leonew > D:\leo.sql

Method 3. From pgAdmin4 Panel

Install PostgreSQL Ubuntu 20.04 With pgAdmin4

You can also export from the pgAdmin4 panel directly. you may not need to enter any command. You just log in to your database panel using login credentials. There will be a server list to select your database server.


Once you select your database server, inside the server select your database, right-click on that database and click on the backup database option.


Then after, create a .sql file in your system and select from that file from the Filename Option, see the below-given image. There will be a backup button highlighted click on the database, The whole database will be put in the file, which your created and your system.


How To Connect PostgreSQL With Laravel Application

We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :