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?
1 Answer
You can copy just the schema using pg_dump, then restore it in your new database.
pg_dump --schema-only
3 Comments
user1802143
How would you create a new database with that schema?
Joshua Moore
@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
Provided both databases exist already you can do this in a single command. pg_dump oldDB --schema-only | psql -h localhost newDB;