Обсуждение: Cloning schemas

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

Cloning schemas

От
Łukasz Jarych
Дата:
Hi,

i am trying to use postgresql clone schema function:


I created function clone_schema in public schema:

image.png


I am trying to use :

"select * from clone_schema('public','Version8',true) but i am getting error:

"Column "max_value" does not exist. 
LINE 1: SELECT last_value, max_value, start_value, increment_by, min...
HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
QUERY: SELECT last_value, max_value, start_value, increment_by, min_value, cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;

CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in EXECUTE
SQL state: 42703
Can anyone help?

Best,
Jacek


Вложения

Re: Cloning schemas

От
Łukasz Jarych
Дата:
Hi ,

thank you !

You have right:

image.png

Hmm i thought that i am creating this table " audit_sq " within  clone schema and this function is complete.

How can i fix this?

Best,
Jacek



pon., 2 lip 2018 o 13:51 Victor Noagbodji <vnoagbodji@amplify-nation.com> napisał(a):
Hello,

Can you check if the table "audit_sq" has the column "max_value"?

On Jul 2, 2018, at 7:30 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:

Hi,

i am trying to use postgresql clone schema function:


I created function clone_schema in public schema:

<image.png>


I am trying to use :

"select * from clone_schema('public','Version8',true) but i am getting error:

"Column "max_value" does not exist. 
LINE 1: SELECT last_value, max_value, start_value, increment_by, min...
HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
QUERY: SELECT last_value, max_value, start_value, increment_by, min_value, cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;

CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in EXECUTE
SQL state: 42703
Can anyone help?

Best,
Jacek



Вложения

Re: Cloning schemas

От
Tom Lane
Дата:
=?UTF-8?Q?=C5=81ukasz_Jarych?= <jaryszek@gmail.com> writes:
> I am trying to use :

> "select * from clone_schema('public','Version8',true) but i am getting
> error:

> "Column "max_value" does not exist.
> LINE 1: SELECT last_value, max_value, start_value, increment_by, min...
> HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
> QUERY: SELECT last_value, max_value, start_value, increment_by, min_value,
> cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;
> CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in
> EXECUTE

I guess audit_sq is a sequence?  It looks to me like this function has
not been taught about the changes in sequence metadata in PG v10.
You need to update it, or talk to its author about an update.

            regards, tom lane


Re: Cloning schemas

От
Łukasz Jarych
Дата:
Hi,

"
Strange. "audit_sq" looks like an invalid sequence table. I went here, https://www.postgresql.org/docs/9.6/static/sql-createsequence.html, and checked all the way back to version 7.1 and "maxvalue" has been a column since back then.

Maybe skip that table for now? It even says the last value is 1. You should also check the other sequence tables. You can get them by doing:

select * from information_schema.sequences;"

Result of select:

image.png

Are you sure that I can skip " audit_sq" seq? 

I wrote here because i am newbie and i can not update this. Hope for your help Guys.

Best,
Jacek







pon., 2 lip 2018 o 15:30 Tom Lane <tgl@sss.pgh.pa.us> napisał(a):
Łukasz Jarych <jaryszek@gmail.com> writes:
> I am trying to use :

> "select * from clone_schema('public','Version8',true) but i am getting
> error:

> "Column "max_value" does not exist.
> LINE 1: SELECT last_value, max_value, start_value, increment_by, min...
> HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
> QUERY: SELECT last_value, max_value, start_value, increment_by, min_value,
> cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;
> CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in
> EXECUTE

I guess audit_sq is a sequence?  It looks to me like this function has
not been taught about the changes in sequence metadata in PG v10.
You need to update it, or talk to its author about an update.

                        regards, tom lane
Вложения

Re: Cloning schemas

От
Adrian Klaver
Дата:
On 07/02/2018 06:57 AM, Łukasz Jarych wrote:
> Hi,
> 
> "
> Strange. "audit_sq" looks like an invalid sequence table. I went 
> here,https://www.postgresql.org/docs/9.6/static/sql-createsequence.html, 
> and checked all the way back to version 7.1 and "maxvalue" has been a 
> column since back then.

What version of Postgres are you actually doing the cloning in?

Per Tom's post:

https://www.postgresql.org/docs/10/static/release-10.html

"
Move sequences' metadata fields into a new pg_sequence system catalog 
(Peter Eisentraut)

...

A sequence relation now stores only the fields that can be modified by 
nextval(), that is last_value, log_cnt, and is_called.

...

The main incompatibility introduced by this change is that selecting 
from a sequence relation now returns only the three fields named above. 
To obtain the sequence's other properties, applications must look into 
pg_sequence. The new system view pg_sequences can also be used for this 
purpose; it provides column names that are more compatible with existing 
code.
"

> 
> Maybe skip that table for now? It even says the last value is 1. You 
> should also check the other sequence tables. You can get them by doing:
> 
> select * from information_schema.sequences;"
> 
> Result of select:
> 
> image.png
> 
> Are you sure that I can skip " audit_sq" seq?
> 
> I wrote here because i am newbie and i can not update this. Hope for 
> your help Guys.
> 
> Best,
> Jacek
> 
> 
> 
> 
> 
> 
> 
> pon., 2 lip 2018 o 15:30 Tom Lane <tgl@sss.pgh.pa.us 
> <mailto:tgl@sss.pgh.pa.us>> napisał(a):
> 
>     =?UTF-8?Q?=C5=81ukasz_Jarych?= <jaryszek@gmail.com
>     <mailto:jaryszek@gmail.com>> writes:
>      > I am trying to use :
> 
>      > "select * from clone_schema('public','Version8',true) but i am
>     getting
>      > error:
> 
>      > "Column "max_value" does not exist.
>      > LINE 1: SELECT last_value, max_value, start_value, increment_by,
>     min...
>      > HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
>      > QUERY: SELECT last_value, max_value, start_value, increment_by,
>     min_value,
>      > cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;
>      > CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in
>      > EXECUTE
> 
>     I guess audit_sq is a sequence?  It looks to me like this function has
>     not been taught about the changes in sequence metadata in PG v10.
>     You need to update it, or talk to its author about an update.
> 
>                              regards, tom lane
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: Cloning schemas

От
Łukasz Jarych
Дата:

Hi,

i see. thank you 

I am using: 

image.png

Best,
Jacek

pon., 2 lip 2018 o 16:03 Adrian Klaver <adrian.klaver@aklaver.com> napisał(a):
On 07/02/2018 06:57 AM, Łukasz Jarych wrote:
> Hi,
>
> "
> Strange. "audit_sq" looks like an invalid sequence table. I went
> here,https://www.postgresql.org/docs/9.6/static/sql-createsequence.html,
> and checked all the way back to version 7.1 and "maxvalue" has been a
> column since back then.

What version of Postgres are you actually doing the cloning in?

Per Tom's post:

https://www.postgresql.org/docs/10/static/release-10.html

"
Move sequences' metadata fields into a new pg_sequence system catalog
(Peter Eisentraut)

...

A sequence relation now stores only the fields that can be modified by
nextval(), that is last_value, log_cnt, and is_called.

...

The main incompatibility introduced by this change is that selecting
from a sequence relation now returns only the three fields named above.
To obtain the sequence's other properties, applications must look into
pg_sequence. The new system view pg_sequences can also be used for this
purpose; it provides column names that are more compatible with existing
code.
"

>
> Maybe skip that table for now? It even says the last value is 1. You
> should also check the other sequence tables. You can get them by doing:
>
> select * from information_schema.sequences;"
>
> Result of select:
>
> image.png
>
> Are you sure that I can skip " audit_sq" seq?
>
> I wrote here because i am newbie and i can not update this. Hope for
> your help Guys.
>
> Best,
> Jacek
>
>
>
>
>
>
>
> pon., 2 lip 2018 o 15:30 Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> napisał(a):
>
>     Łukasz Jarych <jaryszek@gmail.com
>     <mailto:jaryszek@gmail.com>> writes:
>      > I am trying to use :
>
>      > "select * from clone_schema('public','Version8',true) but i am
>     getting
>      > error:
>
>      > "Column "max_value" does not exist.
>      > LINE 1: SELECT last_value, max_value, start_value, increment_by,
>     min...
>      > HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
>      > QUERY: SELECT last_value, max_value, start_value, increment_by,
>     min_value,
>      > cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;
>      > CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in
>      > EXECUTE
>
>     I guess audit_sq is a sequence?  It looks to me like this function has
>     not been taught about the changes in sequence metadata in PG v10.
>     You need to update it, or talk to its author about an update.
>
>                              regards, tom lane
>


--
Adrian Klaver
adrian.klaver@aklaver.com
Вложения

Re: Cloning schemas

От
Melvin Davidson
Дата:


On Mon, Jul 2, 2018 at 10:14 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:

Hi,

i see. thank you 

I am using: 

image.png

Best,
Jacek

pon., 2 lip 2018 o 16:03 Adrian Klaver <adrian.klaver@aklaver.com> napisał(a):
On 07/02/2018 06:57 AM, Łukasz Jarych wrote:
> Hi,
>
> "
> Strange. "audit_sq" looks like an invalid sequence table. I went
> here,https://www.postgresql.org/docs/9.6/static/sql-createsequence.html,
> and checked all the way back to version 7.1 and "maxvalue" has been a
> column since back then.

What version of Postgres are you actually doing the cloning in?

Per Tom's post:

https://www.postgresql.org/docs/10/static/release-10.html

"
Move sequences' metadata fields into a new pg_sequence system catalog
(Peter Eisentraut)

...

A sequence relation now stores only the fields that can be modified by
nextval(), that is last_value, log_cnt, and is_called.

...

The main incompatibility introduced by this change is that selecting
from a sequence relation now returns only the three fields named above.
To obtain the sequence's other properties, applications must look into
pg_sequence. The new system view pg_sequences can also be used for this
purpose; it provides column names that are more compatible with existing
code.
"

>
> Maybe skip that table for now? It even says the last value is 1. You
> should also check the other sequence tables. You can get them by doing:
>
> select * from information_schema.sequences;"
>
> Result of select:
>
> image.png
>
> Are you sure that I can skip " audit_sq" seq?
>
> I wrote here because i am newbie and i can not update this. Hope for
> your help Guys.
>
> Best,
> Jacek
>
>
>
>
>
>
>
> pon., 2 lip 2018 o 15:30 Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> napisał(a):
>
>     =?UTF-8?Q?=C5=81ukasz_Jarych?= <jaryszek@gmail.com
>     <mailto:jaryszek@gmail.com>> writes:
>      > I am trying to use :
>
>      > "select * from clone_schema('public','Version8',true) but i am
>     getting
>      > error:
>
>      > "Column "max_value" does not exist.
>      > LINE 1: SELECT last_value, max_value, start_value, increment_by,
>     min...
>      > HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
>      > QUERY: SELECT last_value, max_value, start_value, increment_by,
>     min_value,
>      > cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;
>      > CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in
>      > EXECUTE
>
>     I guess audit_sq is a sequence?  It looks to me like this function has
>     not been taught about the changes in sequence metadata in PG v10.
>     You need to update it, or talk to its author about an update.
>
>                              regards, tom lane
>


--
Adrian Klaver
adrian.klaver@aklaver.com

Lukas,

Once again, in Version 10, the developers have changed the system catalogs. Please use the attached clone_schema_10.sql which
has been adjusted for PostgreSQL 10.



--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!
Вложения

Re: Cloning schemas

От
Łukasz Jarych
Дата:
Hi Melvin, 

I understand this but i can not update function by myself. Thnak you very much ! 

Still errors here. 

Something like:

ERROR: BŁĄD: you cannot add to column "TopoToVersion_ID" DETAIL: Column "TopoToVersion_ID" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override. CONTEXT: wyrażenie SQL "INSERT INTO version4.t_topotoversions SELECT * FROM public.t_topotoversions;" funkcja PL/pgSQL clone_schema(text,text,boolean), wiersz 212 w EXECUTE SQL state: 428C9

pon., 2 lip 2018 o 16:22 Melvin Davidson <melvin6925@gmail.com> napisał(a):


On Mon, Jul 2, 2018 at 10:14 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:

Hi,

i see. thank you 

I am using: 

image.png

Best,
Jacek

pon., 2 lip 2018 o 16:03 Adrian Klaver <adrian.klaver@aklaver.com> napisał(a):
On 07/02/2018 06:57 AM, Łukasz Jarych wrote:
> Hi,
>
> "
> Strange. "audit_sq" looks like an invalid sequence table. I went
> here,https://www.postgresql.org/docs/9.6/static/sql-createsequence.html,
> and checked all the way back to version 7.1 and "maxvalue" has been a
> column since back then.

What version of Postgres are you actually doing the cloning in?

Per Tom's post:

https://www.postgresql.org/docs/10/static/release-10.html

"
Move sequences' metadata fields into a new pg_sequence system catalog
(Peter Eisentraut)

...

A sequence relation now stores only the fields that can be modified by
nextval(), that is last_value, log_cnt, and is_called.

...

The main incompatibility introduced by this change is that selecting
from a sequence relation now returns only the three fields named above.
To obtain the sequence's other properties, applications must look into
pg_sequence. The new system view pg_sequences can also be used for this
purpose; it provides column names that are more compatible with existing
code.
"

>
> Maybe skip that table for now? It even says the last value is 1. You
> should also check the other sequence tables. You can get them by doing:
>
> select * from information_schema.sequences;"
>
> Result of select:
>
> image.png
>
> Are you sure that I can skip " audit_sq" seq?
>
> I wrote here because i am newbie and i can not update this. Hope for
> your help Guys.
>
> Best,
> Jacek
>
>
>
>
>
>
>
> pon., 2 lip 2018 o 15:30 Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> napisał(a):
>
>     Łukasz Jarych <jaryszek@gmail.com
>     <mailto:jaryszek@gmail.com>> writes:
>      > I am trying to use :
>
>      > "select * from clone_schema('public','Version8',true) but i am
>     getting
>      > error:
>
>      > "Column "max_value" does not exist.
>      > LINE 1: SELECT last_value, max_value, start_value, increment_by,
>     min...
>      > HINT: Maybe you wanted to point to column " "audit_sq.last_value"?
>      > QUERY: SELECT last_value, max_value, start_value, increment_by,
>     min_value,
>      > cache_value, log_cnt, is_cycled, is_called FROM public.audit_sq;
>      > CONTEXT: function PL/pgSQL clone_schema(text,text,boolean), row 66 in
>      > EXECUTE
>
>     I guess audit_sq is a sequence?  It looks to me like this function has
>     not been taught about the changes in sequence metadata in PG v10.
>     You need to update it, or talk to its author about an update.
>
>                              regards, tom lane
>


--
Adrian Klaver
adrian.klaver@aklaver.com

Lukas,

Once again, in Version 10, the developers have changed the system catalogs. Please use the attached clone_schema_10.sql which
has been adjusted for PostgreSQL 10.



--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!
Вложения

Re: Cloning schemas

От
Melvin Davidson
Дата:



ERROR: BŁĄD: you cannot add to column "TopoToVersion_ID" DETAIL: Column "TopoToVersion_ID" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override. CONTEXT: wyrażenie SQL "INSERT INTO version4.t_topotoversions SELECT * FROM public.t_topotoversions;" funkcja PL/pgSQL clone_schema(text,text,boolean), wiersz 212 w EXECUTE

Lukasz,
That ERROR is occuring because you choose to copy the data (include_recs = TRUE).
I have added OVERRIDING SYSTEM VALUE to the insert statement and attached revised version.
CAUTION: The value of TopoToVersion_ID and any other IDENTITY columns may be changed.

The revised version is attached.

Вложения

Re: Cloning schemas

От
Łukasz Jarych
Дата:
Hi Melvin,

thank you very much. Awesome!!!

Best,
Jacek


wt., 3 lip 2018 o 15:34 Melvin Davidson <melvin6925@gmail.com> napisał(a):



ERROR: BŁĄD: you cannot add to column "TopoToVersion_ID" DETAIL: Column "TopoToVersion_ID" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override. CONTEXT: wyrażenie SQL "INSERT INTO version4.t_topotoversions SELECT * FROM public.t_topotoversions;" funkcja PL/pgSQL clone_schema(text,text,boolean), wiersz 212 w EXECUTE

Lukasz,
That ERROR is occuring because you choose to copy the data (include_recs = TRUE).
I have added OVERRIDING SYSTEM VALUE to the insert statement and attached revised version.
CAUTION: The value of TopoToVersion_ID and any other IDENTITY columns may be changed.

The revised version is attached.

Re: Cloning schemas

От
Melvin Davidson
Дата:

On Wed, Jul 4, 2018 at 2:27 PM, Łukasz Jarych <jaryszek@gmail.com> wrote:
Hi Melvin,



Best,
Jacek


wt., 3 lip 2018 o 15:34 Melvin Davidson <melvin6925@gmail.com> napisał(a):



ERROR: BŁĄD: you cannot add to column "TopoToVersion_ID" DETAIL: Column "TopoToVersion_ID" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override. CONTEXT: wyrażenie SQL "INSERT INTO version4.t_topotoversions SELECT * FROM public.t_topotoversions;" funkcja PL/pgSQL clone_schema(text,text,boolean), wiersz 212 w EXECUTE

Lukasz,
That ERROR is occuring because you choose to copy the data (include_recs = TRUE).
I have added OVERRIDING SYSTEM VALUE to the insert statement and attached revised version.
CAUTION: The value of TopoToVersion_ID and any other IDENTITY columns may be changed.

The revised version is attached.


> thank you very much. Awesome!!!

Jacek,
You are quite welcome.



--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
DiasCosta
Дата:
Hi Melvin,

I'm new to clone_schema.
Can I use it on PostgreSQL 9.6?

TIA
DCosta



On 03-07-2018 14:34, Melvin Davidson wrote:



ERROR: BŁĄD: you cannot add to column "TopoToVersion_ID" DETAIL: Column "TopoToVersion_ID" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override. CONTEXT: wyrażenie SQL "INSERT INTO version4.t_topotoversions SELECT * FROM public.t_topotoversions;" funkcja PL/pgSQL clone_schema(text,text,boolean), wiersz 212 w EXECUTE

Lukasz,
That ERROR is occuring because you choose to copy the data (include_recs = TRUE).
I have added OVERRIDING SYSTEM VALUE to the insert statement and attached revised version.
CAUTION: The value of TopoToVersion_ID and any other IDENTITY columns may be changed.

The revised version is attached.


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.

Re: Cloning schemas

От
Melvin Davidson
Дата:


On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org> wrote:
Hi Melvin,

I'm new to clone_schema.
Can I use it on PostgreSQL 9.6?

TIA
DCostaployment by invitation only!

> Can I use it on PostgreSQL 9.6?

Yes, but because the developer(s) once again monkeyed with the system catalogs, there are now
two versions. One for 10 and one for 9.6 and below. I've attached the 9.6 version for you.

 
Вложения

Re: Cloning schemas

От
Adrian Klaver
Дата:
On 07/04/2018 03:38 PM, Melvin Davidson wrote:
> 
> 
> On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org 
> <mailto:diascosta@diascosta.org>> wrote:
> 
>     Hi Melvin,
> 
>     I'm new to clone_schema.
>     Can I use it on PostgreSQL 9.6?
> 
>     TIA
>     DCostaployment by invitation only!
> 
> 
>  > Can I use it on PostgreSQL 9.6?
> 
> Yes, but because the developer(s) once again monkeyed with the system 
> catalogs, there are now

Well that is one of the things that distinguish a major release so it 
should be no surprise.

> two versions. One for 10 and one for 9.6 and below. I've attached the 
> 9.6 version for you.
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: Cloning schemas

От
Melvin Davidson
Дата:


On Wed, Jul 4, 2018 at 6:48 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 07/04/2018 03:38 PM, Melvin Davidson wrote:


On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org <mailto:diascosta@diascosta.org>> wrote:

    Hi Melvin,

    I'm new to clone_schema.
    Can I use it on PostgreSQL 9.6?

    TIA
    DCostaployment by invitation only!


 > Can I use it on PostgreSQL 9.6?

Yes, but because the developer(s) once again monkeyed with the system catalogs, there are now

Well that is one of the things that distinguish a major release so it should be no surprise.



The problem is, AFAICS, none of the changes induced were really necessary or increased performance.


Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
Adrian Klaver
Дата:
On 07/04/2018 03:53 PM, Melvin Davidson wrote:
> 
> 

> 
> 
> The problem is, AFAICS, none of the changes induced were really 
> necessary or increased performance.

The folks that wanted transactional ALTER SEQUENCE might disagree:):

https://www.postgresql.org/docs/10/static/release-10.html
"Move sequences' metadata fields into a new pg_sequence system catalog 
(Peter Eisentraut)

A sequence relation now stores only the fields that can be modified by 
nextval(), that is last_value, log_cnt, and is_called. Other sequence 
properties, such as the starting value and increment, are kept in a 
corresponding row of the pg_sequence catalog. ALTER SEQUENCE updates are 
now fully transactional, implying that the sequence is locked until 
commit. The nextval() and setval() functions remain nontransactional.

...
"

> 
> 
> *Melvin Davidson**
> Maj. Database & Exploration Specialist**
> Universe Exploration Command – UXC***
> Employment by invitation only!


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: Cloning schemas

От
Melvin Davidson
Дата:

>The folks that wanted transactional ALTER SEQUENCE might disagree:):
Ah, so you mean the previous version was not working or sufficient?

--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
Łukasz Jarych
Дата:
Hi Melvin.

folks wrote only that it is old version and didnt care :) 

Tahnk you very much, 
Best,
Jacek 

czw., 5 lip 2018 o 01:09 Melvin Davidson <melvin6925@gmail.com> napisał(a):

>The folks that wanted transactional ALTER SEQUENCE might disagree:):
Ah, so you mean the previous version was not working or sufficient?

--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
Łukasz Jarych
Дата:
From link function is not working. 

czw., 5 lip 2018 o 07:49 Łukasz Jarych <jaryszek@gmail.com> napisał(a):
Hi Melvin.

folks wrote only that it is old version and didnt care :) 

Tahnk you very much, 
Best,
Jacek 

czw., 5 lip 2018 o 01:09 Melvin Davidson <melvin6925@gmail.com> napisał(a):

>The folks that wanted transactional ALTER SEQUENCE might disagree:):
Ah, so you mean the previous version was not working or sufficient?

--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
Melvin Davidson
Дата:


On Thu, Jul 5, 2018 at 1:49 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
From link function is not working. 

There is no " From link" in PostgreSQL,
Would you please be more specific. Please provide a working example.

Re: Cloning schemas

От
Łukasz Jarych
Дата:
You gave me working example. 

the function from here is not working:


Best,
Jacek 

czw., 5 lip 2018 o 16:02 Melvin Davidson <melvin6925@gmail.com> napisał(a):


On Thu, Jul 5, 2018 at 1:49 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
From link function is not working. 

There is no " From link" in PostgreSQL,
Would you please be more specific. Please provide a working example.

Re: Cloning schemas

От
Melvin Davidson
Дата:



On Thu, Jul 5, 2018 at 10:38 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
You gave me working example. 

the function from here is not working:


Best,
Jacek 

czw., 5 lip 2018 o 16:02 Melvin Davidson <melvin6925@gmail.com> napisał(a):


On Thu, Jul 5, 2018 at 1:49 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
From link function is not working. 

There is no " From link" in PostgreSQL,
Would you please be more specific. Please provide a working example.



Jacek,

That is NOT the version for PostgreSQL 10. It is for 9.6 and below only!
I attached the working function for 10 and it is attached again to this response.


--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!
Вложения

Re: Cloning schemas

От
Łukasz Jarych
Дата:
Melvin,

thank you once again ! Yes and this is working like a charm, 
I love your function and file ! 

Best,
Jacek 

czw., 5 lip 2018 o 16:53 Melvin Davidson <melvin6925@gmail.com> napisał(a):



On Thu, Jul 5, 2018 at 10:38 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
You gave me working example. 

the function from here is not working:


Best,
Jacek 

czw., 5 lip 2018 o 16:02 Melvin Davidson <melvin6925@gmail.com> napisał(a):


On Thu, Jul 5, 2018 at 1:49 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
From link function is not working. 

There is no " From link" in PostgreSQL,
Would you please be more specific. Please provide a working example.



Jacek,

That is NOT the version for PostgreSQL 10. It is for 9.6 and below only!
I attached the working function for 10 and it is attached again to this response.


--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
DiasCosta
Дата:
Hi Melvin,

Thank you.

Dias Costa

On 04-07-2018 23:38, Melvin Davidson wrote:


On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org> wrote:
Hi Melvin,

I'm new to clone_schema.
Can I use it on PostgreSQL 9.6?

TIA
DCostaployment by invitation only!

> Can I use it on PostgreSQL 9.6?

Yes, but because the developer(s) once again monkeyed with the system catalogs, there are now
two versions. One for 10 and one for 9.6 and below. I've attached the 9.6 version for you.

 


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.

Re: Cloning schemas

От
Melvin Davidson
Дата:


2018-07-07 4:32 GMT-04:00 DiasCosta <diascosta@diascosta.org>:
Hi Melvin,

Thank you.

Dias Costa

On 04-07-2018 23:38, Melvin Davidson wrote:


On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org> wrote:
Hi Melvin,

I'm new to clone_schema.
Can I use it on PostgreSQL 9.6?

TIA
DCostaployment by invitation only!

> Can I use it on PostgreSQL 9.6?

Yes, but because the developer(s) once again monkeyed with the system catalogs, there are now
two versions. One for 10 and one for 9.6 and below. I've attached the 9.6 version for you.

 


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.

You are welcome Dias!
Good to have positive feedback.


--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
Łukasz Jarych
Дата:
Hi Melvin,

i am trying to run postgresql 10 cloning schema function but still i am getting error...

image.png

Error: Error in syntax near "SYSTEM"
Context: Function PL/pgSQL, row 212 in EXECUTE

What is happening?

Best,
Jacek 


sob., 7 lip 2018 o 22:20 Melvin Davidson <melvin6925@gmail.com> napisał(a):


2018-07-07 4:32 GMT-04:00 DiasCosta <diascosta@diascosta.org>:
Hi Melvin,

Thank you.

Dias Costa

On 04-07-2018 23:38, Melvin Davidson wrote:


On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org> wrote:
Hi Melvin,

I'm new to clone_schema.
Can I use it on PostgreSQL 9.6?

TIA
DCostaployment by invitation only!

> Can I use it on PostgreSQL 9.6?

Yes, but because the developer(s) once again monkeyed with the system catalogs, there are now
two versions. One for 10 and one for 9.6 and below. I've attached the 9.6 version for you.

 


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.

You are welcome Dias!
Good to have positive feedback.


--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!
Вложения

Re: Cloning schemas

От
Melvin Davidson
Дата:


On Mon, Jul 9, 2018 at 5:14 AM, Łukasz Jarych <jaryszek@gmail.com> wrote:
Hi Melvin,

i am trying to run postgresql 10 cloning schema function but still i am getting error...

image.png

Error: Error in syntax near "SYSTEM"
Context: Function PL/pgSQL, row 212 in EXECUTE

What is happening?

Best,
Jacek 

> Error: Error in syntax near "SYSTEM"

Jacek,
I have changed the code from OVERRIDING SYSTEM VALUE to OVERRIDING USER VALUE
and attached the revised version below.

If that does not fix the problem, then I will need you to do a
pgdump -F p -t public.t_cpuinfo

and send the output to me.

--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!
Вложения

Re: Cloning schemas

От
DiasCosta
Дата:
Hi Melvin,

Trying run 9.6 clone_schema on a different schema and I get the following error:

NOTICE:  search path = {public,pg_catalog}
CONTEXT:  PL/pgSQL function clone_schema(text,text,boolean) line 79 at RAISE
ERROR:  relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist
CONTEXT:  SQL statement "COMMENT ON INDEX bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante unicidade do Cod_Operador_AML';"
PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE
********** Error **********

ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist
SQL state: 42P01
Context: SQL statement "COMMENT ON INDEX bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante unicidade do Cod_Operador_AML';"
PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE


Can you help me, please?
Thanks in advance
Dias Costa




On 07-07-2018 09:32, DiasCosta wrote:
Hi Melvin,

Thank you.

Dias Costa

On 04-07-2018 23:38, Melvin Davidson wrote:


On Wed, Jul 4, 2018 at 2:48 PM, DiasCosta <diascosta@diascosta.org> wrote:
Hi Melvin,

I'm new to clone_schema.
Can I use it on PostgreSQL 9.6?

TIA
DCostaployment by invitation only!

> Can I use it on PostgreSQL 9.6?

Yes, but because the developer(s) once again monkeyed with the system catalogs, there are now
two versions. One for 10 and one for 9.6 and below. I've attached the 9.6 version for you.

 


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.

Re: Cloning schemas

От
Melvin Davidson
Дата:


On Mon, Jul 9, 2018 at 12:32 PM, DiasCosta <diascosta@diascosta.org> wrote:
Hi Melvin,

Trying run 9.6 clone_schema on a different schema and I get the following error:

NOTICE:  search path = {public,pg_catalog}
CONTEXT:  PL/pgSQL function clone_schema(text,text,boolean) line 79 at RAISE
ERROR:  relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist
CONTEXT:  SQL statement "COMMENT ON INDEX bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante unicidade do Cod_Operador_AML';"
PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE
********** Error **********

ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist
SQL state: 42P01
Context: SQL statement "COMMENT ON INDEX bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante unicidade do Cod_Operador_AML';"
PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE


Can you help me, please?
Thanks in advance
Dias Costa


Dias
> NOTICE:  search path = {public,pg_catalog}
>ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist

This is not related to the clone_schema function. It looks like you may have corruption in your syste catalogs,
Try reindexing your system_catalogs.

REINDEX VERBOSE SYSTEM  <your_database_name>;


--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
Adrian Klaver
Дата:
On 07/09/2018 09:49 AM, Melvin Davidson wrote:
> 
> 
> On Mon, Jul 9, 2018 at 12:32 PM, DiasCosta <diascosta@diascosta.org 
> <mailto:diascosta@diascosta.org>> wrote:
> 
>     Hi Melvin,
> 
>     Trying run 9.6 clone_schema on a different schema and I get the
>     following error:
> 
>     NOTICE:  search path = {public,pg_catalog}
>     CONTEXT:  PL/pgSQL function clone_schema(text,text,boolean) line 79
>     at RAISE
>     ERROR:  relation "bilhetica_logic_schema.idx_unq_cod_operador_aml"
>     does not exist
>     CONTEXT:  SQL statement "COMMENT ON INDEX
>     bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante
>     unicidade do Cod_Operador_AML';"
>     PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE
>     ********** Error **********
> 
>     ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml"
>     does not exist
>     SQL state: 42P01
>     Context: SQL statement "COMMENT ON INDEX
>     bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante
>     unicidade do Cod_Operador_AML';"
>     PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE
> 
> 
>     Can you help me, please?
>     Thanks in advance
>     Dias Costa
> 
> 
> Dias
>  > NOTICE:  search path = {public,pg_catalog}
>  >ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does 
> not exist
> 
> This is not related to the clone_schema function. It looks like you may 
> have corruption in your syste catalogs,
> Try reindexing your system_catalogs.

Or from clone_schema.sql:

EXECUTE 'CREATE TABLE ' || buffer || ' (LIKE ' || 
quote_ident(source_schema) || '.' || quote_ident(object)
         || ' INCLUDING ALL)';

https://www.postgresql.org/docs/10/static/sql-createtable.html

"LIKE source_table [ like_option ... ]

...

Indexes, PRIMARY KEY, UNIQUE, and EXCLUDE constraints on the original 
table will be created on the new table only if INCLUDING INDEXES is 
specified. <*/Names for the new indexes and constraints are chosen 
according to the default rules, regardless of how the originals were 
named. (This behavior avoids possible duplicate-name failures for the 
new indexes.)/*>

...
INCLUDING ALL is an abbreviated form of INCLUDING COMMENTS INCLUDING 
CONSTRAINTS INCLUDING DEFAULTS INCLUDING IDENTITY INCLUDING INDEXES 
INCLUDING STATISTICS INCLUDING STORAGE.

..."

See tagged part(<*/ /*>) part above. I could see where the indexes in 
the new schema have new names while the index comments in the old schema 
refer to the old name. Then you would get the error the OP showed.

> 
> REINDEX VERBOSE SYSTEM  <your_database_name>;
> 
> 
> 
> -- 
> *Melvin Davidson**
> Maj. Database & Exploration Specialist**
> Universe Exploration Command – UXC***
> Employment by invitation only!


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: Cloning schemas

От
Melvin Davidson
Дата:

Adrian,
The code that CREATES the TABLE is

EXECUTE 'CREATE TABLE ' || buffer || ' (LIKE ' || quote_ident(source_schema) || '.' || quote_ident(object)
        || ' INCLUDING ALL)';

The schema names are supposed to be changed!

This function HAS been tested and does WORK. Please do not muddle the problem without testing yourself.


On Mon, Jul 9, 2018 at 2:56 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 07/09/2018 09:49 AM, Melvin Davidson wrote:



On Mon, Jul 9, 2018 at 12:32 PM, DiasCosta <diascosta@diascosta.org <mailto:diascosta@diascosta.org>> wrote:

    Hi Melvin,

    Trying run 9.6 clone_schema on a different schema and I get the
    following error:

    NOTICE:  search path = {public,pg_catalog}
    CONTEXT:  PL/pgSQL function clone_schema(text,text,boolean) line 79
    at RAISE
    ERROR:  relation "bilhetica_logic_schema.idx_unq_cod_operador_aml"
    does not exist
    CONTEXT:  SQL statement "COMMENT ON INDEX
    bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante
    unicidade do Cod_Operador_AML';"
    PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE
    ********** Error **********

    ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml"
    does not exist
    SQL state: 42P01
    Context: SQL statement "COMMENT ON INDEX
    bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante
    unicidade do Cod_Operador_AML';"
    PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE


    Can you help me, please?
    Thanks in advance
    Dias Costa


Dias
 > NOTICE:  search path = {public,pg_catalog}
 >ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist

This is not related to the clone_schema function. It looks like you may have corruption in your syste catalogs,
Try reindexing your system_catalogs.

Or from clone_schema.sql:

EXECUTE 'CREATE TABLE ' || buffer || ' (LIKE ' || quote_ident(source_schema) || '.' || quote_ident(object)
        || ' INCLUDING ALL)';

https://www.postgresql.org/docs/10/static/sql-createtable.html

"LIKE source_table [ like_option ... ]

...

Indexes, PRIMARY KEY, UNIQUE, and EXCLUDE constraints on the original table will be created on the new table only if INCLUDING INDEXES is specified. <*/Names for the new indexes and constraints are chosen according to the default rules, regardless of how the originals were named. (This behavior avoids possible duplicate-name failures for the new indexes.)/*>

...
INCLUDING ALL is an abbreviated form of INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING IDENTITY INCLUDING INDEXES INCLUDING STATISTICS INCLUDING STORAGE.

..."

See tagged part(<*/ /*>) part above. I could see where the indexes in the new schema have new names while the index comments in the old schema refer to the old name. Then you would get the error the OP showed.


REINDEX VERBOSE SYSTEM  <your_database_name>;



--
*Melvin Davidson**
Maj. Database & Exploration Specialist**
Universe Exploration Command – UXC***
Employment by invitation only!


--
Adrian Klaver
adrian.klaver@aklaver.com



--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!

Re: Cloning schemas

От
DiasCosta
Дата:
Hi Melvin,

I followed your recommendation and it did not work.

Since I was in a rush I did try to understand where the function crashed and commenting in the function the creation of
comments for indexes, as follows, was sufficient for the function work.

    IF FOUND
      THEN     
--        EXECUTE 'COMMENT ON INDEX ' || quote_ident(dest_schema) || '.' || quote_ident(object)
--                 || ' IS ''' || v_def || ''';';

Problem is I don't usually comment indexes.

Thanks and
Keep good working
Dias Costa









On 09-07-2018 22:50, Melvin Davidson wrote:

Adrian,
The code that CREATES the TABLE is

EXECUTE 'CREATE TABLE ' || buffer || ' (LIKE ' || quote_ident(source_schema) || '.' || quote_ident(object)
        || ' INCLUDING ALL)';

The schema names are supposed to be changed!

This function HAS been tested and does WORK. Please do not muddle the problem without testing yourself.


On Mon, Jul 9, 2018 at 2:56 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 07/09/2018 09:49 AM, Melvin Davidson wrote:



On Mon, Jul 9, 2018 at 12:32 PM, DiasCosta <diascosta@diascosta.org <mailto:diascosta@diascosta.org>> wrote:

    Hi Melvin,

    Trying run 9.6 clone_schema on a different schema and I get the
    following error:

    NOTICE:  search path = {public,pg_catalog}
    CONTEXT:  PL/pgSQL function clone_schema(text,text,boolean) line 79
    at RAISE
    ERROR:  relation "bilhetica_logic_schema.idx_unq_cod_operador_aml"
    does not exist
    CONTEXT:  SQL statement "COMMENT ON INDEX
    bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante
    unicidade do Cod_Operador_AML';"
    PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE
    ********** Error **********

    ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml"
    does not exist
    SQL state: 42P01
    Context: SQL statement "COMMENT ON INDEX
    bilhetica_logic_schema.idx_unq_cod_operador_aml IS 'garante
    unicidade do Cod_Operador_AML';"
    PL/pgSQL function clone_schema(text,text,boolean) line 401 at EXECUTE


    Can you help me, please?
    Thanks in advance
    Dias Costa


Dias
 > NOTICE:  search path = {public,pg_catalog}
 >ERROR: relation "bilhetica_logic_schema.idx_unq_cod_operador_aml" does not exist

This is not related to the clone_schema function. It looks like you may have corruption in your syste catalogs,
Try reindexing your system_catalogs.

Or from clone_schema.sql:

EXECUTE 'CREATE TABLE ' || buffer || ' (LIKE ' || quote_ident(source_schema) || '.' || quote_ident(object)
        || ' INCLUDING ALL)';

https://www.postgresql.org/docs/10/static/sql-createtable.html

"LIKE source_table [ like_option ... ]

...

Indexes, PRIMARY KEY, UNIQUE, and EXCLUDE constraints on the original table will be created on the new table only if INCLUDING INDEXES is specified. <*/Names for the new indexes and constraints are chosen according to the default rules, regardless of how the originals were named. (This behavior avoids possible duplicate-name failures for the new indexes.)/*>

...
INCLUDING ALL is an abbreviated form of INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING IDENTITY INCLUDING INDEXES INCLUDING STATISTICS INCLUDING STORAGE.

..."

See tagged part(<*/ /*>) part above. I could see where the indexes in the new schema have new names while the index comments in the old schema refer to the old name. Then you would get the error the OP showed.


REINDEX VERBOSE SYSTEM  <your_database_name>;



--
*Melvin Davidson**
Maj. Database & Exploration Specialist**
Universe Exploration Command – UXC***
Employment by invitation only!


--
Adrian Klaver
adrian.klaver@aklaver.com



--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!


-- 
J. M. Dias Costa
Telef. 214026948     Telem. 939307421

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.

Re: Cloning schemas

От
Adrian Klaver
Дата:
On 07/09/2018 02:50 PM, Melvin Davidson wrote:
> 
> Adrian,
> The code that CREATES the TABLE is
> 
> EXECUTE 'CREATE TABLE ' || buffer || ' (LIKE ' || 
> quote_ident(source_schema) || '.' || quote_ident(object)
>          || ' INCLUDING ALL)';
> 
> The schema names are supposed to be changed!
> 
> This function HAS been tested and does WORK. Please do not muddle the 
> problem without testing yourself.
> 

create table public.idx_test (id int, fld_1 varchar);
create index test_idx on idx_test (id);

test_(postgres)# \d idx_test
                    Table "public.idx_test"
  Column |       Type        | Collation | Nullable | Default
--------+-------------------+-----------+----------+---------
  id     | integer           |           |          |
  fld_1  | character varying |           |          |
Indexes:
     "test_idx" btree (id)

create table sch_test.idx_test (like public.idx_test including all);

test_(postgres)# \d sch_test.idx_test
                   Table "sch_test.idx_test"
  Column |       Type        | Collation | Nullable | Default
--------+-------------------+-----------+----------+---------
  id     | integer           |           |          |
  fld_1  | character varying |           |          |
Indexes:
     "idx_test_id_idx" btree (id)

When you look up the comments you do:

  SELECT oid
       FROM pg_class
      WHERE relkind = 'i'
        AND relnamespace = src_oid

Where src_oid is the source namespace/schema. So in this case:

test_(postgres)# SELECT oid, relname
       FROM pg_class
      WHERE relkind = 'i'
        AND relnamespace = 'public'::regnamespace AND oid=2089851;
    oid   | relname
---------+----------
  2089851 | test_idx

You then do:

  SELECT relname INTO object ..

EXECUTE 'COMMENT ON INDEX ' || quote_ident(dest_schema) || '.' || 
quote_ident(object)
                  || ' IS ''' || v_def || ''';';

The problem is that the relname/object has changed in the new schema. In 
this case from text_idx --> idx_test_id_idx. So this happens:

test_(postgres)# comment on index sch_test.test_idx is 'test';
ERROR:  relation "sch_test.test_idx" does not exist


Just some muddling do with it what you will:)


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: Cloning schemas

От
Melvin Davidson
Дата:

Dias,

As an experiment, I commented out the code that creates the comment on indexes and it still works flawlessly, so that part is redundant.
I have attached the modified function below,
Please retry and see if the problem still exists.
If it does, then please do a schema only pg_dump of the source schema abd send me the call to clone schema that you are using.

--
Melvin Davidson
Maj. Database & Exploration Specialist

Universe Exploration Command – UXC

Employment by invitation only!
Вложения

Re: Cloning schemas

От
Adrian Klaver
Дата:
On 07/09/2018 03:23 PM, Adrian Klaver wrote:
> On 07/09/2018 02:50 PM, Melvin Davidson wrote:
>>
>> Adrian,

> 
> The problem is that the relname/object has changed in the new schema. In 
> this case from text_idx --> idx_test_id_idx. So this happens:
> 
> test_(postgres)# comment on index sch_test.test_idx is 'test';
> ERROR:  relation "sch_test.test_idx" does not exist
> 
> 
> Just some muddling do with it what you will:)
> 

Should have added to the above that INCLUDING ALL encompasses INCLUDING 
COMMENTS:

https://www.postgresql.org/docs/10/static/sql-createtable.html

"Comments for the copied columns, constraints, and indexes will be 
copied only if INCLUDING COMMENTS is specified. The default behavior is 
to exclude comments, resulting in the copied columns and constraints in 
the new table having no comments."

So the COMMENT ON INDEX code is redundant anyway.

-- 
Adrian Klaver
adrian.klaver@aklaver.com