Re: feature request: pg_restore renaming target schema

From: Shreeyansh Dba <shreeyansh2014(at)gmail(dot)com>
To: CN <cnliou9(at)fastmail(dot)fm>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: feature request: pg_restore renaming target schema
Date: 2015-12-17 13:20:58
Message-ID: CAGDYbUNK2tQZz4SfFBZit8o5wqHgy3Hz3SOgVhxkHh3aZ1DOwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi CN,

The procedure you have followed in the beginning is right.

But if you are trying to do with second option like from source schema(s1)
of db1 to target schema(t1) of db2, it is not possible with pg_restore
because while restoring from backup dump, it follows the sequence of
commands like
"CREATE SCHEMA s1"
"SET SEARCH_PATH=s1"
"CREATE TABLE table_name(id int)"
"INSERT INTO table_name VALUES(1)"

2: If you are taking the dump in plan text format you can edit the plain
text file and replace schema old name to new name and then you can restore
the file using psql -d <db> -U <user> -f <path of plain text file>.

--
Thanks & Regards
Venkataramana Aitla
Database Administrator
Shreeyansh Technologies

On Thu, Dec 17, 2015 at 1:14 PM, CN <cnliou9(at)fastmail(dot)fm> wrote:

> Hi!
>
> I need to restore one source schema to multiple target schema currently.
> For example,
>
> source database: db1
> source schema: s1
> target database: db2
>
> The existing approach I know is following these steps:
>
> (1) pg_dump -n s1 -Fc -f source.db db1
> (2a) pg_restore -d db2 -n s1 source.db
> (2b) psql -c "ALTER SCHEMA s1 RENAME TO t1" db2
> (3a) pg_restore -d db2 -n s1 source.db
> (3b) psql -c "ALTER SCHEMA s1 RENAME TO t2" db2
>
> So far so good.
> However, with existing tool I know, obviously step groups (2) and (3)
> can only run sequentially.
>
> If pg_restore allows "redirecting" source schema to target schema, then
> I can concurrently issue some imaginary commands like these:
>
> pg_restore -d db2 -n s1 --target-schema=t1 source.db
> pg_restore -d db2 -n s1 --target-schema=t2 source.db
> pg_restore -d db2 -n s1 --target-schema=t3 source.db
>
> Best Regards,
> CN
>
> --
> http://www.fastmail.com - Faster than the air-speed velocity of an
> unladen european swallow
>
>
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message CN 2015-12-17 15:19:46 Re: feature request: pg_restore renaming target schema
Previous Message CN 2015-12-17 07:44:05 feature request: pg_restore renaming target schema