How do I do a schema only backup and restore in PostgreSQL?

user1671630 picture user1671630 · Sep 24, 2012 · Viewed 86.4k times · Source

How do I take a schema level backup in PostgreSQL database and restore on the another database? Is there any single command available for this? For example, can I pg_dump and restore in single line?

Answer

solaimuruganv picture solaimuruganv · Sep 24, 2012
pg_dump --schema=masters oldDB > masters1.sql
cat masters1.sql | psql newDB

or

in single command you can do by this

pg_dump oldDB --schema masters  | psql -h localhost newDB;