Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg_dump does not write "CREATE EXTENSION postgis;"

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.

like image 200
piokuc Avatar asked Jun 08 '17 17:06

piokuc


People also ask

Does pg_dump include extensions?

pg_dump is NOT including extensions.

What does pg_dump command do?

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 .

Does Pg_restore create database?

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.


1 Answers

You can use this to dump schema and extensions (tested on 11.2):

pg_dump -U postgres -d mydb -s > dump.sql
like image 192
Mihai Tomescu Avatar answered Sep 28 '22 08:09

Mihai Tomescu