I'd like to create a new database with the same tables/fields as an existing database. I don't need any of the rows, I just need the schema. Is there a way to do this?
Asked
Active
Viewed 40 times
0
-
Try this: http://stackoverflow.com/questions/808735/postgresql-how-to-create-a-copy-of-a-database-or-schema – The Blue Dog Dec 20 '13 at 23:11
1 Answers
1
You can copy just the schema using pg_dump, then restore it in your new database.
pg_dump --schema-only

Joshua Moore
- 24,706
- 6
- 50
- 73
-
-
@user1802143 Just use createdb to create a new database then pg_restore to restore the backup (which has only the schema) to that new database. – Joshua Moore Dec 20 '13 at 23:30
-
Provided both databases exist already you can do this in a single command. pg_dump oldDB --schema-only | psql -h localhost newDB; – Joshua Moore Dec 20 '13 at 23:32