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

流过昼夜 提交于 2019-12-31 08:44:22

问题


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?


回答1:


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;



回答2:


Backup schema and restore it on system for postgresql as below:

Dump schema for database

pg_dump -s database_name > db.sql

Dump schema for specific table

pg_dump -s database_name -t table_name > db.sql 

Restore backed up schema using below command

psql -d database_name -h localhost -U postgres < path/db.sql



回答3:


What's wrong with the documentation?

Example from the manual:

To dump all schemas whose names start with east or west and end in gsm, excluding any schemas whose names contain the word test:

$ pg_dump -n 'east*gsm' -n 'west*gsm' -N 'test' mydb > db.sql




回答4:


-s or --schema-only to exclude data from dump Documentation



来源:https://stackoverflow.com/questions/12564777/how-do-i-do-a-schema-only-backup-and-restore-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!