Skip to content

How to import and export a PostgreSQL Database

  • by
import and export a PostgreSQL database

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.

  1. Log in to cPanel.
  2. Click phpPgAdmin in the Database section.
  3. In the phpPgAdmin window, expand Servers and then PostgreSQL.
  4. Click the name of the database you want to export.
  5. Click Export at the top of the menu bar.
  6. Click [Structure and Data].
  7. Select SQL.
  8. Click [Download].
  9. Click [Output].
  10. 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

  1. Log in to your cPanel account.
  2. Click PostgreSQL Database in the Database section of the cPanel home screen.
  3. Enter the name of the database in the Database Name text box under Create New Database.
  4. Click [Create Database].
  5. When the database is created, click [Back].
  6. From the Users list box under Add User to Database, select the user you want to add.
  7. Select a new database from the Database list box.
  8. 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?

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *