snippetsqlMajor
PostgreSQL: How to create full copy of database schema in same database?
Viewed 0 times
postgresqlsamefullcreatedatabasehowschemacopy
Problem
How I can copy my
My version of Postgres is 8.4
P.S. I need to copy schema NOT database
public schema into the same database with full table structure, data, functions, fk, pk and etc.My version of Postgres is 8.4
P.S. I need to copy schema NOT database
Solution
There's no simple way to do this in pg_dump/pg_restore itself. You could try the following if you are able to remove the database temporarily.
- Take a dump of your public schema using pg_dump
- run "ALTER SCHEMA public RENAME TO public_copy"
- Restore your dump of your public schema from step 1 using pg_restore
Context
StackExchange Database Administrators Q#10474, answer score: 28
Revisions (0)
No revisions yet.