Обсуждение: pg_restore schema dump to schema with different name

Поиск
Список
Период
Сортировка

pg_restore schema dump to schema with different name

От
Nagaraj Raj
Дата:
Hi,

I know I can alter schema name after restoring but the problem is the name already exist and I don't want to touch that existing schema.
The dump type is "custom".



So effectively I want something like.
pg_dump -U postgres --schema "source_schema" --format "c" --create --file "source_schema.bak" my_db
pg_restore -U postgres --exit-on-error --dbname "my_db"  --destination-schema "destination_schema"  

Currently this is not something can do. this functionality is there in oracle. 



Is this future considering to add?  (it would really help for create any test schemas without disturbing current schema. )


Thanks,
Rj

Re: pg_restore schema dump to schema with different name

От
Laurenz Albe
Дата:
On Mon, 2021-08-23 at 09:44 +0000, Nagaraj Raj wrote:
> I know I can alter schema name after restoring but the problem is the name already exist and I don't want to touch
thatexisting schema.
 
> The dump type is "custom".
> 
> So effectively I want something like.
> pg_dump -U postgres --schema "source_schema" --format "c" --create --file "source_schema.bak" my_db
> pg_restore -U postgres --exit-on-error --dbname "my_db"  --destination-schema "destination_schema"

The only way to do that is to create a new database, import the data there,
rename the schema and dump again.

Then import that dump into the target database.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




Re: pg_restore schema dump to schema with different name

От
Jean-Christophe Boggio
Дата:
> The only way to do that is to create a new database, import the data
> there, rename the schema and dump again.
> 
> Then import that dump into the target database.

Or maybe (if you can afford to have source_schema unavailable for some
time) :

* rename source_schema to tmp_source
* import (that will re-create  source_schema)
* rename source_schema to destination_schema
* rename back tmp_source to source_schema



Re: pg_restore schema dump to schema with different name

От
Nagaraj Raj
Дата:

Wouldn’t be easy if we have option to_schema ? 

Absolutely, I should not alter current schema, as it live 24/7.

Thanks,
Rj
On Monday, August 23, 2021, 06:39:03 AM PDT, Jean-Christophe Boggio <postgresql@thefreecat.org> wrote:



> The only way to do that is to create a new database, import the data
> there, rename the schema and dump again.
>
> Then import that dump into the target database.


Or maybe (if you can afford to have source_schema unavailable for some
time) :

* rename source_schema to tmp_source
* import (that will re-create  source_schema)
* rename source_schema to destination_schema
* rename back tmp_source to source_schema



Re: pg_restore schema dump to schema with different name

От
Laurenz Albe
Дата:
On Mon, 2021-08-23 at 17:54 +0000, Nagaraj Raj wrote:
> Wouldn’t be easy if we have option to_schema ?

Sure, but it wouldn't be easy to implement that.
It would have to be a part of "pg_dump".

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




Re: pg_restore schema dump to schema with different name

От
"David G. Johnston"
Дата:
On Mon, Aug 23, 2021 at 2:46 AM Nagaraj Raj <nagaraj.sf@yahoo.com> wrote:

Currently this is not something can do. this functionality is there in oracle. 

Is this future considering to add?  (it would really help for create any test schemas without disturbing current schema. )


I find this to be not all that useful.  Current practice is to avoid relying on search_path and, in general, to schema-qualify object references (yes, attaching a local SET search_path to a function works, not sure how it would play out in this context).  Performing a dependency and contextual rename of one schema name to another is challenging given all of that, and impossible if the schema name is hard-coded into a function body.

I won't say we wouldn't accept such a patch, but as this isn't exactly a new problem or realization, and the feature doesn't presently exist, that for whatever reasons individuals may have no one has chosen to volunteer or fund such development.  I don't even remember seeing a proposal in the past 5 or so years.

David J.

Re: pg_restore schema dump to schema with different name

От
Nagaraj Raj
Дата:
I agree with that.But, probably its good idea to add this feature as many people are migrating from oracle to postgres. clone/restore schemas to existing cluster for any test cases like sandbox schema, temp schema as live backup schema etc. 

Thanks,
Rj

On Tuesday, August 24, 2021, 07:56:20 AM PDT, David G. Johnston <david.g.johnston@gmail.com> wrote:


On Mon, Aug 23, 2021 at 2:46 AM Nagaraj Raj <nagaraj.sf@yahoo.com> wrote:

Currently this is not something can do. this functionality is there in oracle. 

Is this future considering to add?  (it would really help for create any test schemas without disturbing current schema. )


I find this to be not all that useful.  Current practice is to avoid relying on search_path and, in general, to schema-qualify object references (yes, attaching a local SET search_path to a function works, not sure how it would play out in this context).  Performing a dependency and contextual rename of one schema name to another is challenging given all of that, and impossible if the schema name is hard-coded into a function body.

I won't say we wouldn't accept such a patch, but as this isn't exactly a new problem or realization, and the feature doesn't presently exist, that for whatever reasons individuals may have no one has chosen to volunteer or fund such development.  I don't even remember seeing a proposal in the past 5 or so years.

David J.