Re: Support logical replication of DDLs - Mailing list pgsql-hackers

From Zheng Li
Subject Re: Support logical replication of DDLs
Date
Msg-id CAAD30U+A=2rjZ+xejNz+e1A=udWPQMxHD8W48nbhxwJRfw_qrA@mail.gmail.com
Whole thread Raw
In response to Re: Support logical replication of DDLs  (li jie <ggysxcq@gmail.com>)
List pgsql-hackers
Hi,

Attached please find the DDL deparser testing module in the v45-0007
patch, this testing module is written by Runqi Tian in [1] with minor
modification from myself. I think we can
start adding more tests to the module now that we're getting close to
finish implementing the DDL deparser.

This testing module ddl_deparse_regress aims to achieve the following
four testing goals for the DDL deparser:
    1. Test that the generated JSON blob is expected using SQL tests.
    2. Test that the re-formed DDL command is expected using SQL tests.
    3. Test that the re-formed DDL command has the same effect as the
original command
       by comparing the results of pg_dump, using the SQL tests in 1 and 2.
    4. Test that any new DDL syntax is handled by the DDL deparser by
capturing and deparsing
       DDL commands ran by pg_regress.

1 and 2 is tested with SQL tests, by comparing the deparsed JSON blob
and the re-formed command.
3 is tested with TAP framework in t/001_compare_dumped_results.pl
4 is tested with TAP framework and pg_regress in 002_regress_tests.pl,
the execution is currently commented out because it will fail due
unimplemented commands in the DDL deparser.

[1]
https://www.postgresql.org/message-id/flat/CAH8n8_jMTunxxtP4L-3tc%3DGNamg%3Dmg1X%3DtgHr9CqqjjzFLwQng%40mail.gmail.com

On Thu, Dec 8, 2022 at 10:32 PM li jie <ggysxcq@gmail.com> wrote:
>
> >
> > Attached please find a new solution that skips the deparsing of ALTER TABLE
> > subcommands generated for TableLikeClause. The patch v42-0005 added a new
> > boolean field table_like to AlterTableStmt in order to identify an ALTER TABLE
> > subcommand generated internally for the TableLikeClause.
> >
> > Regards,
> > Zheng
>
> I took a look at this patch and it appears to be incomplete.
>
> > @@ -1974,6 +1974,7 @@ typedef struct AlterTableStmt
> > List *cmds; /* list of subcommands */
> > ObjectType objtype; /* type of object */
> > bool missing_ok; /* skip error if table missing */
> > + bool table_like; /* internally generated for TableLikeClause */
> > } AlterTableStmt;
>
> The table_like field should include implementations of the `copynode`
> and `equalnode `methods.

Looks like this we don't need to manually update
copynode/equalnode/readnode/outnode
now that they are generated by ./src/backend/nodes/gen_node_support.pl.

> I think temporary objects should not be part of replication because
> they are visible within the session.
>  replicate them over would not make them visible to the user and would
> not be meaningful.

We currently don't replicate temporary tables:
event_trigger.c
/*
* Do not generate wal log for commands whose target table is a
* temporary table.
*
* We will generate wal logs for unlogged tables so that unlogged
* tables can also be created and altered on the subscriber side. This
* makes it possible to directly replay the SET LOGGED command and the
* incoming rewrite message without creating a new table.
*/
if (relpersist == RELPERSISTENCE_TEMP)
continue;

Regards,
Zheng

Attachment

pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: [PoC] Reducing planning time when tables have many partitions
Next
From: Zheng Li
Date:
Subject: Re: Testing DDL Deparser