clone_schema function

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: clone_schema function
Date: 2015-09-09 16:31:00
Message-ID: CANu8FixK9P8UD43nv2s+c-9jHkyy8wPUc_f5K3HcrmJYVPr-wQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I noted there was an inquiry as to how to copy or clone_schema
an entire schema. The standard method for doing that is to
1. pg_dump the schema in plain format
2. edit the dump file and change all occurrences of the schema name
3. reload the dump into the new schema.

The attached function is an alternate method for doing that.
It is a revision of the clone_schema by by Emanuel '3manuek'
from https://wiki.postgresql.org/wiki/Clone_schema

Originally, it did not copy views, functions or data from
the source schema despite the claim that it "copies everything".

I've added error checking and verified that it now copies the
current sequnce values, table data, views and functions.

As always, use with caution.
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

Attachment Content-Type Size
clone_schema.sql text/plain 4.9 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Florin Andrei 2015-09-09 17:54:12 avoid lock conflict between SELECT and TRUNCATE
Previous Message Teodor Sigaev 2015-09-09 16:27:05 Re: jsonb value retrieval performance