Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pfL7u-0005sJ-0R for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Mar 2023 13:37:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pfL7s-0000Ap-T2 for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Mar 2023 13:37:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pfL7s-0000Ag-GK for pgsql-hackers@lists.postgresql.org; Thu, 23 Mar 2023 13:37:08 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pfL7o-0003OS-Od for pgsql-hackers@lists.postgresql.org; Thu, 23 Mar 2023 13:37:08 +0000 Received: by mail-oi1-x22d.google.com with SMTP id v17so6367165oic.5 for ; Thu, 23 Mar 2023 06:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679578622; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vkvnUtfjKpbIoYqJAur+hZO1ncKdHeY/DJosPVJQEfE=; b=LquWJLbGxDHJyyS3qYjKXLfjCc/zN9bVSLjxfQkTi4iKCjz88M2sTzJr/KKi+Dde1W WQaVSrACOpV+7MmqAA+OuGRspwfCW0jJ9L9knXKrnsCwXr0FiTFOjkO4zTcRdmCwab2l 9/7g95M15Oi3DgHnnBoaY1wZMplXxaphLinR9BElujptG6U57YRcM2/2fYtfydZ6kkEi gPY0lwUJrmOk4gt+HffTBFSKx5WJutWcAbFhr6MXAHddy+qYzEvubUz13Lxap5CMmHmR lC4SIlssvXwV0JibUBSzas6jMBDeHm41ypKEwOZaIqjMkK+ZuzIScN7edpQ3nhikHBT0 3unw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679578622; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vkvnUtfjKpbIoYqJAur+hZO1ncKdHeY/DJosPVJQEfE=; b=KZZrYYe8IyU5Z8ddn3tBYqNY3R2RymIHQo57AdxACRi73qedYDmBqYBRfS8iDK9aGX yTnu4xT7sk4dkoADZypDcBazVXh8qcJU6l0EXGgyUDKID23uavrActvkMb0CiiRvhUVR fpFwC1OWLoYpdPjRO5/pAYV8Dhy1/yr7GBh3agLORKP1NXVa4xllysfA7xqCYq2wRxbA 0gkthfcEYD7rsEidFjUUxm0yzkOUmbG5C5cNpvLvRrDn7ZfHrQrnMRMwamNqvZDQLyJ2 8w8sFUaEZgufGwskUCaVygbnTwRCi/Bt2JCixXrkSgH2FqcMg/lpJ1JPZTrR2ha0HmRj 7CLA== X-Gm-Message-State: AO0yUKUytp8x2fynknw2k7Vcjvkj7M3UK2o8ZaPT/jSPa1Vb5PUegjKf pLQ53ciJtWSgNolGRZ2VD3D/ah0z3DIox2BWseE= X-Google-Smtp-Source: AK7set/FL4bQefBd2qxbk/eHPjRiwqRXw62HHJuUYgBkZevKTnA0/N/BjxYkW6uxvX1R2mVF/Zx2BCTHIhf+xTfFxms= X-Received: by 2002:a54:440f:0:b0:386:c175:c807 with SMTP id k15-20020a54440f000000b00386c175c807mr1936340oiw.7.1679578621864; Thu, 23 Mar 2023 06:37:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: vignesh C Date: Thu, 23 Mar 2023 19:06:32 +0530 Message-ID: Subject: Re: Support logical replication of DDLs To: Ajin Cherian Cc: "houzj.fnst@fujitsu.com" , "wangw.fnst@fujitsu.com" , Runqi Tian , Peter Smith , li jie , Dilip Kumar , Alvaro Herrera , Amit Kapila , Masahiko Sawada , Japin Li , rajesh singarapu , PostgreSQL Hackers , Zheng Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 23 Mar 2023 at 09:22, Ajin Cherian wrote: > > On Mon, Mar 20, 2023 at 8:17=E2=80=AFPM houzj.fnst@fujitsu.com > wrote: > > > > Attach the new patch set which addressed above comments. > > 0002,0003,0004 patch has been updated in this version. > > > > Best Regards, > > Hou zj > > Attached a patch-set which adds support for ONLY token in ALTER TABLE.. > Changes are in patches 0003 and 0004. Few comments: 1) The file name should be changed to 033_ddl_replication.pl as 032 is used already: diff --git a/src/test/subscription/t/032_ddl_replication.pl b/src/test/subscription/t/032_ddl_replication.pl new file mode 100644 index 0000000000..4bc4ff2212 --- /dev/null +++ b/src/test/subscription/t/032_ddl_replication.pl @@ -0,0 +1,465 @@ +# Copyright (c) 2022, PostgreSQL Global Development Group +# Regression tests for logical replication of DDLs +# +use strict; +use warnings; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + 2) Typos 2.a) subcriber should be subscriber: (Note #2) For ATTACH/DETACH PARTITION, we haven't added extra logic on the subscriber to handle the case where the table on the publisher is a PARTITIONED TABLE while the target table on the subcriber side is a NORMAL table. We wi= ll research this more and improve it later. 2.b) subscrier should be subscriber: + For example, when enabled a CREATE TABLE command executed on the publisher gets + WAL-logged, and forwarded to the subscriber to replay; a subsequent "A= LTER + SUBSCRIPTION ... REFRESH PUBLICATION" is run on the subscrier database so any + following DML changes on the new table can be replicated without a hit= ch. 3) Error reporting could use new style: + break; + default: + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid conversion specifier \"%c\"", *cp))); + } 4) We could also mention "or the initial tree content is known." as we have mentioned for the first point: * c) new_objtree_VA where the complete tree can be derived using some fixe= d * content and/or some variable arguments. 5) we could simplify the code by changing: /* * Scan pg_constraint to fetch all constraints linked to the given * relation. */ conRel =3D table_open(ConstraintRelationId, AccessShareLock); if (OidIsValid(relationId)) { ScanKeyInit(&key, Anum_pg_constraint_conrelid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId)); scan =3D systable_beginscan(conRel, ConstraintRelidTypidNameIndexId, true, NULL, 1, &key); } else { ScanKeyInit(&key, Anum_pg_constraint_contypid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(domainId)); scan =3D systable_beginscan(conRel, ConstraintTypidIndexId, true, NULL, 1, &key); } to: relid =3D (OidIsValid(relationId)) ? ConstraintRelidTypidNameIndexId :ConstraintTypidIndexId; ScanKeyInit(&key, Anum_pg_constraint_conrelid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(relationId)); scan =3D systable_beginscan(conRel, relid, true, NULL, 1, &key); 6) The tmpstr can be removed by changing: +static inline ObjElem * +deparse_Seq_Cache(Form_pg_sequence seqdata, bool alter_table) +{ + ObjTree *ret; + char *tmpstr; + char *fmt; + + fmt =3D alter_table ? "SET CACHE %{value}s" : "CACHE %{value}s"; + + tmpstr =3D psprintf(INT64_FORMAT, seqdata->seqcache); + ret =3D new_objtree_VA(fmt, 2, + "clause", ObjTypeString, "cache", + "value", ObjTypeString, tmpstr); + + return new_object_object(ret); +} to: ret =3D new_objtree_VA(fmt, 2, "clause", ObjTypeString, "cache", "value", ObjTypeString, psprintf(INT64_FORMAT, seqdata->seqcache)); 7) Same change can be done here too: static inline ObjElem * deparse_Seq_IncrementBy(Form_pg_sequence seqdata, bool alter_table) { ObjTree *ret; char *tmpstr; char *fmt; fmt =3D alter_table ? "SET INCREMENT BY %{value}s" : "INCREMENT BY %{value}= s"; tmpstr =3D psprintf(INT64_FORMAT, seqdata->seqincrement); ret =3D new_objtree_VA(fmt, 2, "clause", ObjTypeString, "seqincrement", "value", ObjTypeString, tmpstr); return new_object_object(ret); } 8) same change can be done here too: static inline ObjElem * deparse_Seq_Maxvalue(Form_pg_sequence seqdata, bool alter_table) { ObjTree *ret; char *tmpstr; char *fmt; fmt =3D alter_table ? "SET MAXVALUE %{value}s" : "MAXVALUE %{value}s"; tmpstr =3D psprintf(INT64_FORMAT, seqdata->seqmax); ret =3D new_objtree_VA(fmt, 2, "clause", ObjTypeString, "maxvalue", "value", ObjTypeString, tmpstr); return new_object_object(ret); } 9) same change can be done here too: static inline ObjElem * deparse_Seq_Minvalue(Form_pg_sequence seqdata, bool alter_table) { ObjTree *ret; char *tmpstr; char *fmt; fmt =3D alter_table ? "SET MINVALUE %{value}s" : "MINVALUE %{value}s"; tmpstr =3D psprintf(INT64_FORMAT, seqdata->seqmin); ret =3D new_objtree_VA(fmt, 2, "clause", ObjTypeString, "minvalue", "value", ObjTypeString, tmpstr); return new_object_object(ret); } 10) same change can be done here too: static inline ObjElem * deparse_Seq_Restart(int64 last_value) { ObjTree *ret; char *tmpstr; tmpstr =3D psprintf(INT64_FORMAT, last_value); ret =3D new_objtree_VA("RESTART %{value}s", 2, "clause", ObjTypeString, "restart", "value", ObjTypeString, tmpstr); return new_object_object(ret); } 11) same change can be done here too: static inline ObjElem * deparse_Seq_Startwith(Form_pg_sequence seqdata, bool alter_table) { ObjTree *ret; char *tmpstr; char *fmt; fmt =3D alter_table ? "SET START WITH %{value}s" : "START WITH %{value}s"; tmpstr =3D psprintf(INT64_FORMAT, seqdata->seqstart); ret =3D new_objtree_VA(fmt, 2, "clause", ObjTypeString, "start", "value", ObjTypeString, tmpstr); return new_object_object(ret); } 12) Verbose syntax should be updated to include definition too: * Verbose syntax * CREATE %{persistence}s SEQUENCE %{identity}D */ static ObjTree * deparse_CreateSeqStmt(Oid objectId, Node *parsetree) 13) Verbose syntax should include AUTHORIZATION too: * Verbose syntax * CREATE SCHEMA %{if_not_exists}s %{name}I %{authorization}s */ static ObjTree * deparse_CreateSchemaStmt(Oid objectId, Node *parsetree) 14) DROP %s should be DROP %{objtype}s in verbose syntax: * Verbose syntax * DROP %s IF EXISTS %%{objidentity}s %{cascade}s */ char * deparse_drop_command(const char *objidentity, const char *objecttype, DropBehavior behavior) 15) ALTER %s should be ALTER %{objtype}s in verbose syntax: * * Verbose syntax * ALTER %s %{identity}s SET SCHEMA %{newschema}I */ static ObjTree * deparse_AlterObjectSchemaStmt(ObjectAddress address, Node *parsetree, ObjectAddress old_schema) { 16) ALTER %s should be ALTER %{identity}s in verbose syntax: * Verbose syntax * ALTER %s %{identity}s OWNER TO %{newowner}I */ static ObjTree * deparse_AlterOwnerStmt(ObjectAddress address, Node *parsetree) 17) ALTER TYPE %{identity}D (%{definition: }s) should include SET in verbose syntax: * Verbose syntax * ALTER TYPE %{identity}D (%{definition: }s) */ static ObjTree * deparse_AlterTypeSetStmt(Oid objectId, Node *cmd) 18) extobjtype should be included in the verbose syntax: * Verbose syntax * ALTER EXTENSION %{extidentity}I ADD/DROP %{objidentity}s */ static ObjTree * deparse_AlterExtensionContentsStmt(Oid objectId, Node *parsetree, ObjectAddress objectAddress) Regards, Vignesh