We have dumped a database that uses the postgis extension using pg_dump. After manually creating the database on a different machine an attempt to load the dump into it using psql failed. It turned out the dump did not contain the necessary statement
CREATE EXTENSION postgis;
The postgis extension was installed in the target instance of Postgres but only after manual execution of the CREATE EXTENSION
loading of the dump succeeded. This doesn't seem like a big deal, but the question is: is it possible to force pg_dump
to write all required CREATE EXTENSION foo;
statements into the dump so I don't have to do it manually? I don't see any option for that in pg_dump
online documentation.
pg_dump is NOT including extensions.
The pg_dump command extracts a PostgreSQL database into a script file or another archive file. This utility is for backing up databases. The utility makes consistent backups even if the database is being used concurrently. Readers, writers, and other users won't be blocked from using the database while using pg_dump .
It will NOT create that database. It creates a database with the name from the archive you are restoring and restores the data into that database.
You can use this to dump schema and extensions (tested on 11.2):
pg_dump -U postgres -d mydb -s > dump.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With