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 127.0.0.1 -U webappfix -p 5432 -O webappfix > webappfix.sql
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
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.
We always thanks to you for reading our blogs.
Dharmesh Chauhan(Swapinfoway Founder)
We Are Also Recommending You :
- How To Install MongoDB In Ubuntu
- Install PostgreSQL Ubuntu 20.04 With pgAdmin4
- MongoDB Database Connection In Laravel
- The Syntax of MySQL
- How to See Pgsql Database List in Ubuntu
- How To Improve SQL Query Performance
- SOLVED # 1118 Row size too large 8126. Changing some columns to TEXT or BLOB
- Unique violation: 7 ERROR: duplicate key value violates unique constraint "users_pkey" DETAIL: Key (id)=(1) already exists.
- MongoDB Database Installation
- ERROR: database "laravel" is being accessed by other users DETAIL: There is 1 other session using the database.