0

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

1 Answer 1

1

You can copy just the schema using pg_dump, then restore it in your new database.

pg_dump --schema-only
Sign up to request clarification or add additional context in comments.

3 Comments

How would you create a new database with that schema?
@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.
Provided both databases exist already you can do this in a single command. pg_dump oldDB --schema-only | psql -h localhost newDB;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.