Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schema only restore to new postgreSQL DB with a text format dump

psql --version
psql (PostgreSQL) 9.3.5

I am trying to restore only the schema. I have tried the following command:

pg_restore -s -d rh /path/to/dump.sql
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

I have tried looking in the documentation of psql and have not found a schema-only flag.

If you know of any other technique to acheieve this I would be very appreciative.

If it helps I am using OSX Version 10.10

like image 230
dan-mi-sun Avatar asked Nov 27 '14 14:11

dan-mi-sun


1 Answers

You can generate a text dumpfile using -s to generate only schema dump like this :

pg_dump -s <database name> > pg_dump_text_filename

You should use psql command to connect to your database :

psql -U <username> -d <databasename> 

and then at the psql prompt use this :

\i <pg_dump_text_file_path>

You can also use the archive file format of pg_dump :

pg_dump -Fc -f <archive file> <database name> 

And then pg_restore only the schema :

pg_restore -d <database name> -s <archive file>
like image 176
WMD Avatar answered Sep 27 '22 19:09

WMD