Importing and exporting PostgreSQL databases
PostgreSQL provides built‑in tools for backing up and restoring databases. On ruachost.com, you can use command‑line utilities or phpPgAdmin to import and export PostgreSQL databases for migration, backup, or recovery purposes.
Why Import/Export Databases?
Section titled “Why Import/Export Databases?”- Transfer a database between hosting accounts or providers.
- Back up data for disaster recovery.
- Restore a database from a previous backup.
- Share a database with developers or third‑party applications.
Exporting a PostgreSQL Database
Section titled “Exporting a PostgreSQL Database”Method 1: Using pg_dump
Section titled “Method 1: Using pg_dump”-
Log in to your hosting account via SSH.
-
Run the following command:
Terminal window pg_dump -U dbusername dbname > dbexport.pgsql- Replace
dbusernamewith your PostgreSQL username. - Replace
dbnamewith the name of the database. - The file
dbexport.pgsqlwill contain all database data.
- Replace
???? Note: If you encounter permission errors with PostGIS templates, use:
pg_dump -U dbusername dbname -N topology -T spatial_ref_sys > dbexport.pgsqlMethod 2: Using phpPgAdmin
Section titled “Method 2: Using phpPgAdmin”- Log in to cPanel.
- Go to Databases → phpPgAdmin.
- Select the database.
- Click Export.
- Choose Structure and data → Format: SQL → Option: Download.
- Save the file locally.
Importing a PostgreSQL Database
Section titled “Importing a PostgreSQL Database”Step 1: Create a New Database
Section titled “Step 1: Create a New Database”- Log in to cPanel.
- Go to Databases → PostgreSQL Databases.
- Enter a name for the new database.
- Assign a user to the database.
Step 2: Import Data
Section titled “Step 2: Import Data”Method 1: Using psql
-
Transfer the backup file (
dbexport.pgsql) to your hosting account via SCP, SFTP, or FTP. -
Log in via SSH.
-
Run:
Terminal window pg_dump -U dbusername dbname > dbexport.pgsql
Method 2: Using phpPgAdmin
Section titled “Method 2: Using phpPgAdmin”- Log in to cPanel → phpPgAdmin.
- Select the target database.
- Click SQL.
- Upload the backup file.
- Click Execute to import data.