This article describes how to import and export a PostgreSQL database. You can import and export databases for a variety of scenarios, including:
You can export a PostgreSQL database to a file by using the pg_dump command line program, or you can use phpPgAdmin.
To export a PostgreSQL database using the pg_dump program, follow these steps:
pg_dump -U dbusername dbname > dbexport.pgsql
The dbexport.pgsql file now contains all of the data for the dbname database. If the dbexport.pgsql file is on a remote computer, download the file to your local computer.
You may receive the following error messages when you try to export a database:
pg_dump: SQL command failed pg_dump: Error message from server: ERROR: permission denied for schema topology pg_dump: The command was: LOCK TABLE topology.topology IN ACCESS SHARE MODE
These errors occur because some server database templates include PostGIS with restricted access permissions. To export a PostgreSQL database without this data, type the following command instead of the command listed in step 2:
pg_dump -U dbusername dbname -N topology -T spatial_ref_sys > dbexport.pgsql
To export a PostgreSQL database using phpPgAdmin, follow these steps:
If you are using the Paper Lantern theme, in the DATABASES section of the cPanel home page, click phpPgAdmin:
Before you can import the database, you must create a new database in cPanel and assign a user to it. To do this, follow these steps:
If you are using the Paper Lantern theme, in the DATABASES section of the cPanel home page, click PostgreSQL Databases:
Under Create New Database, in the Database Name text box, type the name of the database.
After you have created a new database in cPanel, you can import the database's contents by using the psql command line program, or you can phpPgAdmin.
To import a PostgreSQL database using the psql program, follow these steps:
psql -U username dbname < dbexport.pgsql
To import a PostgreSQL database using phpPgAdmin, follow these steps:
If you are using the Paper Lantern theme, in the DATABASES section of the cPanel home page, click phpPgAdmin:
On the top menu bar, click SQL.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.