This article describes how to import and export a PostgreSQL database. You can import and export databases for a variety of scenarios, including:
- Transferring a database from one web hosting account or provider to another.
- Importing a third-party database.
- Backing up a database.
Export a PostgreSQL database
You can export a PostgreSQL database to a file by using the pg_dump command line program, or you can use phpPgAdmin.
Method #1: Use the pg_dump program
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 USERNAME with your username, and DBNAME with the name of the database that you want to export:
pg_dump -U USERNAME DBNAME > dbexport.pgsql
This article uses the dbexport.pgsql filename for the exported database, but you can name the file whatever you want. - Type your password at the Password prompt.
- The dbexport.pgsql file now contains all of the data for the DBNAME database. If thedbexport.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 USERNAME DBNAME -N topology -T spatial_ref_sys > dbexport.pgsql
Method #2: Use phpPgAdmin
To export a PostgreSQL database using phpPgAdmin, follow these steps:
- Log in to cPanel.
- In the Databases section of the cPanel home screen, click phpPgAdmin.
- 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 .
- In the file dialog, select a location to save the file, and then click .
Create a new PostgreSQL database and assign a user
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:
- Log in to your A2 Hosting cPanel account.
- In the Databases section of the cPanel home screen, click PostgreSQL Databases.
- Under Create New Database, type the name of the database in the Database Name text box.
- Click .
- When the database is created, click .
- Under Add User to Database, select the user that you want to add in the User list box.
- In the Database list box, select the new database.
- Click .
Import a PostgreSQL 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.
You 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.
Method #1: Use the psql program
To import a PostgreSQL database using the psql program, follow these steps:
- Transfer the dbexport.pgsql file to your A2 Hosting account using SCP, SFTP, or FTP.
- Log in to your A2 Hosting SSH account.
- Type the following command, and then press Enter. Replace USERNAME with your username and 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.
Method #2: Use phpPgAdmin
To import a PostgreSQL database using phpPgAdmin, follow these steps:
- Log in to cPanel.
- In the Databases section of the cPanel home screen, click phpPgAdmin.
- 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.The SQL link is located between the Schemas and Find links.
- Click
- In the file dialog, select where the import file is located, and then click .
- Click . phpPgAdmin imports the data from the file into the database.
More Information
- To view the online documentation for psql in PostgreSQL 8.4, please visithttp://www.postgresql.org/docs/8.4/static/app-psql.html.
- To view the online documentation for psql in PostgreSQL 9.1, please visithttp://www.postgresql.org/docs/9.1/static/app-psql.html.
- To view the online documentation for pg_dump in PostgreSQL 8.4, please visithttp://www.postgresql.org/docs/8.4/static/app-pgdump.html.
- To view the online documentation for pg_dump in PostgreSQL 9.1, please visithttp://www.postgresql.org/docs/9.1/static/app-pgdump.html.
Related Articles
- Connecting to PostgreSQL from the command lineYou use the psql program to connect directly to PostgreSQL from the command line. Learn how here.
Sakarya
ReplyDeleteKayseri
Van
Konya
Samsun
TNTC
yalova
ReplyDeleteyozgat
elazığ
van
sakarya
RZSL
manisa
ReplyDeletesakarya
sivas
van
elazığ
EHPK
elazığ
ReplyDeletegümüşhane
kilis
siirt
sakarya
4EM2
van evden eve nakliyat
ReplyDeletesivas evden eve nakliyat
çankırı evden eve nakliyat
bartın evden eve nakliyat
erzincan evden eve nakliyat
JH36H
kırklareli evden eve nakliyat
ReplyDeleteısparta evden eve nakliyat
istanbul evden eve nakliyat
ankara evden eve nakliyat
kırıkkale evden eve nakliyat
W8O
737A8
ReplyDeleteEskişehir Şehir İçi Nakliyat
Eskişehir Parça Eşya Taşıma
Gümüşhane Parça Eşya Taşıma
Tekirdağ Evden Eve Nakliyat
Hotbit Güvenilir mi
Çerkezköy Halı Yıkama
Nevşehir Şehirler Arası Nakliyat
Muş Lojistik
Cate Coin Hangi Borsada
4256F
ReplyDeleteHakkari Şehirler Arası Nakliyat
Denizli Lojistik
Kocaeli Evden Eve Nakliyat
Balıkesir Evden Eve Nakliyat
Osmaniye Lojistik
Bingöl Evden Eve Nakliyat
Düzce Şehirler Arası Nakliyat
Adana Parça Eşya Taşıma
Mardin Şehirler Arası Nakliyat
4F9C7
ReplyDeletereferanskodunedir.com.tr
BB2F4
ReplyDeletebinance indirim
2A821
ReplyDeleteBinance Kaldıraçlı İşlem Nasıl Yapılır
Binance Para Kazanma
Bulut Madenciliği Nedir
Coin Nasıl Üretilir
Bitcoin Kazma
Bitcoin Üretme Siteleri
Bitcoin Hesap Açma
Kripto Para Kazma Siteleri
Bitcoin Üretme Siteleri
00E28
ReplyDeletevan ücretsiz sohbet siteleri
sinop canlı sohbet et
mardin ücretsiz görüntülü sohbet
agri chat sohbet
karaman sohbet odaları
ücretsiz sohbet siteleri
parasız sohbet siteleri
elazığ kızlarla rastgele sohbet
giresun random görüntülü sohbet
59179
ReplyDeleteNexa Coin Hangi Borsada
Coin Madenciliği Nedir
Threads Yeniden Paylaş Hilesi
Binance Hangi Ülkenin
Raca Coin Hangi Borsada
Bitcoin Kazanma Siteleri
Area Coin Hangi Borsada
Parasız Görüntülü Sohbet
Youtube Beğeni Satın Al