To export a PostgreSQL database using the pg_dump program, follow these steps:
Access the command line on the computer where the database is stored. For example, if the database is on another web hosting account or with another web hosting provider, log in to the account using SSH. If you have physical access to the computer, you can open a DOS or terminal window to access the command line.
Type the following command, and then press Enter. Replace dbusername with aย username that has permissions to access the database, and replace dbname with the name of the database that you want to export:
pg_dump -U dbusername dbname > dbexport.pgsql
๐ NoteThis article uses the dbexport.pgsql filename for the exported database, but you can name the file anything you want.
Type your hosting.com account password at the Password prompt.
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.
๐ NoteYou may receive the following error messages when you try to export a database:
pg_dump: SQL command failedpg_dump: Error message from server: ERROR:ย permission denied for schema topologypg_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:
To export a PostgreSQL database using phpPgAdmin, follow these steps:
Log in to cPanel.
๐ NoteIf you do not know how to log in to your cPanel account, please see this article.
On the Tools page, in the Databases section, click phpPgAdmin:
The phpPgAdmin administration page appears in a new window. In the left pane of the phpPgAdmin window, expand Servers, expand PostgreSQL, and then click the name of the database that you want to export.
On the top menu bar, click Export.
Under Format, click Structure and data.
Under Options, in the Format list box, select SQL.
Under Options, click Download.
Click Export.
In the file dialog, select a location to save the file, and then click Save.
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.
ImportantYou should import all PostgreSQL data as the primary PostgreSQL user (that is, by using your domain username). If you import PostgreSQL data as a regular user, you will be unable to see or manipulate the data properly using phpPgAdmin. After you have imported the data as the primary PostgreSQL user, you can grant a regular user access to the data. Then you do not have to use the primary domain username and password in scripts that access the database.
Type the following command, and then press Enter. Replace username with your username and replace dbname with the name of the database that you want to import the data into:
psql -U username dbname < dbexport.pgsql
The dbname database should now contain the data that is in the dbexport.pgsql file.
To import a PostgreSQL database using phpPgAdmin, follow these steps:
Log in to cPanel.
๐ NoteIf you do not know how to log in to your cPanel account, please see this article.
On the Tools page, in the Databases section, click phpPgAdmin:
The phpPgAdmin administration page appears in a new window. In the left pane of the phpPgAdmin window, expand Servers, expand PostgreSQL, and then click the name of the database that you want to import the data into.
On the top menu bar, click SQL.
๐ NoteThe SQL link is located between the Schemas and Find links.
Click Choose File.
In the file dialog, select where the import file is located, and then click Open.
Click Execute. phpPgAdmin imports the data from the file into the database.