patternsqlMajor
Backup only one schema and restore it on another server
Viewed 0 times
serverrestoreoneanotherandonlyschemabackup
Problem
I have a database named "A" which has two schemas "B" and "C".
I want to backup and restore Schema "B" (including data) on a different server. Not sure how to do this as I am new to Postgres.
Do I have to create a new database on the new sever as of name "A" and then restore the Schema "B" on it?
Please help with the necessary commands.
PostgreSQL 9.1 running on Ubuntu 12.04
I want to backup and restore Schema "B" (including data) on a different server. Not sure how to do this as I am new to Postgres.
Do I have to create a new database on the new sever as of name "A" and then restore the Schema "B" on it?
Please help with the necessary commands.
PostgreSQL 9.1 running on Ubuntu 12.04
Solution
You can select which schemas to dump with the
Restore the dump file:
The target database does not have to have the same name as the original one.
Note that you will have problems if schema B has dependencies on schema C. Then you won't be able to restore it separately.
Also note that when dumping one schema, you will not dump blobs (LOB type). Use
-n option of pg_dump. Create a dump of schema B:pg_dump ...other...options... -Fc -n B >dump.dmpRestore the dump file:
pg_restore -d somedb dump.dmpThe target database does not have to have the same name as the original one.
Note that you will have problems if schema B has dependencies on schema C. Then you won't be able to restore it separately.
Also note that when dumping one schema, you will not dump blobs (LOB type). Use
-b option to dump with blobs. With -b all blobs are added, not just for a single schema.Code Snippets
pg_dump ...other...options... -Fc -n B >dump.dmppg_restore -d somedb dump.dmpContext
StackExchange Database Administrators Q#53185, answer score: 45
Revisions (0)
No revisions yet.