Import PostgreSQL
Overview
Export a PostgreSQL database from your current setup and import it into a Cloudron app.
Dump
Create a dump of your existing PostgreSQL database using pg_dump:
$ PGPASSWORD=password pg_dump --no-owner --no-privileges --username=username --host=myserver databasename > pgdump.sql
If this database is on a Cloudron, you can use the following command:
# PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} pg_dump --no-owner --no-privileges --username=${CLOUDRON_POSTGRESQL_USERNAME} --host=${CLOUDRON_POSTGRESQL_HOST} ${CLOUDRON_POSTGRESQL_DATABASE} > /tmp/pgdump.sql
Import
- Enable
Recovery Modein theRepairsection. This pauses the app while you import data.
- Open a Web Terminal using the Terminal button in the
Consolesection.
- Upload the dump file using the
Uploadbutton.
- Comment out extension information in the dump file:
# sed -e 's/CREATE EXTENSION/-- CREATE EXTENSION/g' -e 's/COMMENT ON EXTENSION/-- COMMENT ON EXTENSION/g' /tmp/pgdump.sql > /tmp/pgdump_mod.sql
- Clear the existing database:
# PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE} -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public"
- Import the dump using the
psqlcommand:
# PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE} --set ON_ERROR_STOP=on --file=/tmp/pgdump_mod.sql
Verify
Verify the import:
- Click the
PostgreSQLbutton at the top of the terminal to paste the connection command. - Press Enter to access the PostgreSQL shell.
