Thread: Table's REPLICATE IDENTITY : where is it kept?

Table's REPLICATE IDENTITY : where is it kept?

From
Achilleas Mantzios
Date:
Hello,
I noticed that after changing a table's REPLICA IDENTITY via the ALTER TABLE command, this is not reflected in
pg_dump.
\d shows the REPLICA IDENTITY , also this is track-able via pg_index.indisreplident but I can't seem to find where this
isreflected in terms of the pg_dump command.
 

-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt



Re: Table's REPLICATE IDENTITY : where is it kept?

From
Tom Lane
Date:
Achilleas Mantzios <achill@matrix.gatewaynet.com> writes:
> I noticed that after changing a table's REPLICA IDENTITY via the ALTER TABLE command, this is not reflected in
pg_dump.

Really?  There's certainly code in there that purports to do it:

    /*
     * dump properties we only have ALTER TABLE syntax for
     */
    if ((tbinfo->relkind == RELKIND_RELATION ||
         tbinfo->relkind == RELKIND_PARTITIONED_TABLE ||
         tbinfo->relkind == RELKIND_MATVIEW) &&
        tbinfo->relreplident != REPLICA_IDENTITY_DEFAULT)
    {
        if (tbinfo->relreplident == REPLICA_IDENTITY_INDEX)
        {
            /* nothing to do, will be set when the index is dumped */
        }
        else if (tbinfo->relreplident == REPLICA_IDENTITY_NOTHING)
        {
            appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY NOTHING;\n",
                              qualrelname);
        }
        else if (tbinfo->relreplident == REPLICA_IDENTITY_FULL)
        {
            appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY FULL;\n",
                              qualrelname);
        }
    }

            regards, tom lane


Re: Table's REPLICATE IDENTITY : where is it kept?

From
Achilleas Mantzios
Date:
On 30/07/2018 16:37, Tom Lane wrote:
> Achilleas Mantzios <achill@matrix.gatewaynet.com> writes:
>> I noticed that after changing a table's REPLICA IDENTITY via the ALTER TABLE command, this is not reflected in
pg_dump.
> Really?  There's certainly code in there that purports to do it:
When its a plain INDEX it is pg_dump'ed correctly.
But when this is a CONSTRAINT index it is not.
e.g.
\d status
...
Indexes:
     "status_id_key" UNIQUE CONSTRAINT, btree (id)
     "status_uk" UNIQUE, btree (id)

alter table status REPLICA IDENTITY USING INDEX status_id_key;
This does not get dumped:
postgres@TEST-smadb:~$ pg_dump --schema-only | grep "REPLICA IDENTITY"
postgres@TEST-smadb:~$

But if I do :

alter table status REPLICA IDENTITY USING INDEX status_uk;
then I get correct result :

postgres@TEST-smadb:~$ pg_dump --schema-only | grep "REPLICA IDENTITY"
ALTER TABLE ONLY public.status REPLICA IDENTITY USING INDEX status_uk;
postgres@TEST-smadb:~$

>      /*
>       * dump properties we only have ALTER TABLE syntax for
>       */
>      if ((tbinfo->relkind == RELKIND_RELATION ||
>           tbinfo->relkind == RELKIND_PARTITIONED_TABLE ||
>           tbinfo->relkind == RELKIND_MATVIEW) &&
>          tbinfo->relreplident != REPLICA_IDENTITY_DEFAULT)
>      {
>          if (tbinfo->relreplident == REPLICA_IDENTITY_INDEX)
>          {
>              /* nothing to do, will be set when the index is dumped */
>          }
>          else if (tbinfo->relreplident == REPLICA_IDENTITY_NOTHING)
>          {
>              appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY NOTHING;\n",
>                                qualrelname);
>          }
>          else if (tbinfo->relreplident == REPLICA_IDENTITY_FULL)
>          {
>              appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY FULL;\n",
>                                qualrelname);
>          }
>      }
>
>             regards, tom lane


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt



Re: Table's REPLICATE IDENTITY : where is it kept?

From
Tom Lane
Date:
Achilleas Mantzios <achill@matrix.gatewaynet.com> writes:
> On 30/07/2018 16:37, Tom Lane wrote:
>> Really?  There's certainly code in there that purports to do it:

> When its a plain INDEX it is pg_dump'ed correctly.
> But when this is a CONSTRAINT index it is not.

Oooh, you're right, dumpIndex() has code for that but dumpConstraint()
lacks it.

            regards, tom lane