Last Updated on November 1, 2021 by admin
I would like to share with you a new thing which is called PostgreSQL Database so today we will learn how to import and export a PostgreSQL Database so let’s go and start.
Export a PostgreSQL database
Export the PostgreSQL database to a file using the pg_dump command line program. pg_dump is a powerful tool for backing up Postgres databases. pg_dump is used to back up the local database and at the same time restore it to the remote database with a single command.
- Log in to your web host account via SSH.
- Enter this command to replace the username and database name.
- Pg_dump username DBNAME > dbexport.pgsql
- Enter your password when prompted.
- All the contents of the DBNAME database will be moved to the DBexport.pgsql file. Start the PostgreSQL database with phpPgAdmin
phpPgAdmin is a web-based administration tool for PostgreSQL written in PHP. It is based on the popular phpMyAdmin interface created for MySQL administration.
- Log in to cPanel.
- Click phpPgAdmin in the Database section.
- In the phpPgAdmin window, expand Servers and then PostgreSQL.
- Click the name of the database you want to export.
- Click Export at the top of the menu bar.
- Click [Structure and Data].
- Select SQL.
- Click [Download].
- Click [Output].
- In the File dialog box, select the location where you want to save the file and click Save. Enter the PostgreSQL database using the psql program
Import and Export a PostgreSQL Database
The main interface of PostgreSQL is the psql command-line program. It can use to import SQL queries directly or from a file. psql provides some metacommands and some shell-like features to simplify scripts and automate multiple tasks. For example, enter the name of the object and the type of SQL syntax.
- Use SCP, SFTP, or FTP to transfer the DB export.pgsql file to your host account.
- Log in to your host account via SSH.
- Enter the following command, replacing USERNAME with the user name and DBNAME with the name of the database where you want to enter the data. # Psql username DBNAME <dbexport.pgsql
- 4) The DBNAME database must contain the data found in the DB export.pgsql file.
- Create a new PostgreSQL database and assign a user
import a PostgreSQL database
- Log in to your cPanel account.
- Click PostgreSQL Database in the Database section of the cPanel home screen.
- Enter the name of the database in the Database Name text box under Create New Database.
- Click [Create Database].
- When the database is created, click [Back].
- From the Users list box under Add User to Database, select the user you want to add.
- Select a new database from the Database list box.
- Click [Send].
After you create a new database in cPanel, you can import the contents of the database.
Read More: Why Should You Use React JS?