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 1ndxsz-00028I-My for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Apr 2022 17:31:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ndxsy-0002oW-7K for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Apr 2022 17:31:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ndxsx-0002oN-Ri for pgsql-hackers@lists.postgresql.org; Mon, 11 Apr 2022 17:31:31 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ndxsv-0003mh-DL for pgsql-hackers@lists.postgresql.org; Mon, 11 Apr 2022 17:31:30 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-d6e29fb3d7so17997073fac.7 for ; Mon, 11 Apr 2022 10:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7c5TflgjLHopus1BynMpS0y/NHd7ad1cPkyKf9UZLgU=; b=a5iMrIxlwjdJNoXa4aONwuAzEZyUjUzDo3peX6rtx/ptgkz5pqk4Cppy0a/mJmvlzW tdAjrFZSShEivzqihqck6t0CKs75PKubGrSgim9Goa6SHhCbc+lreWdrwH8teGtBKoKE r//QvgaY2PQpakakthxvKJSEkoSglKDMdI8xgyLl766ogSjqvg76U1K/9+Dc7M2wgwnV F9STrB13V4PxIsEmzOYIDj+f1GceTJi6KHQSstQBX8e44jDhjbZOV5MIS3vAR3wM0Yfw nicAeGWVaWII5AhqbcVCPAtyyVzE/GlHxw+k7tHXEko68z1zslYKpx5bflH2Eq54A5Ff YdVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7c5TflgjLHopus1BynMpS0y/NHd7ad1cPkyKf9UZLgU=; b=30nG5kLv+RPbZeuWSvjaZILtpveGc1wbATLGyvvQ2jB/sV+KCqvycCROszt8p3deuC 5LDt+H0k9wcmqDuQ8ITBor2Thhmi10A1OiziXY1+IrcMMhGISeQbgC47yNyz+AnqXurj VcvnHXShsOq3KmqnTzAXut7H9Ne/AlyOnqlrvkYjsiQRcPk0/vqo0ZOlCwcRk4AS238w ND/FPdAkR2+HffMX7pS3znfgxZBn4UZqCy+qCxt9Q475nXqPw+NILYgz/5/DGoQYqG09 FSihQY9i57aIFdCVzkftSv+KgKfHX/lx5ZiFFxZKRkBGiGwYMPFSd7nJMwhrQLt/r0hh 8rJw== X-Gm-Message-State: AOAM532nArMYu02jgb7FKUAdaKtMDVhTU0PZ18xQY1MqsaT0TpN1hHpq IG2WLvtRfGrK8yJBLoepORHDLkibciSDJh2He+c= X-Google-Smtp-Source: ABdhPJxQm0jfmz+dzbKUE6+i7mbtTxfgxgg3kBUXBJRIkeLWMDiwPP9qDBBTomH6flzSztVx3lAHu3qBmrWc95wfmoE= X-Received: by 2002:a05:6870:d1cd:b0:e1:e7ee:faa0 with SMTP id b13-20020a056870d1cd00b000e1e7eefaa0mr152906oac.5.1649698288792; Mon, 11 Apr 2022 10:31:28 -0700 (PDT) MIME-Version: 1.0 References: <202203162206.7spggyktx63e@alvherre.pgsql> In-Reply-To: From: Zheng Li Date: Mon, 11 Apr 2022 13:31:17 -0400 Message-ID: Subject: Re: Support logical replication of DDLs To: Amit Kapila Cc: Japin Li , Alvaro Herrera , Dilip Kumar , rajesh.rs0541@gmail.com, PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Amit, > Some initial comments: > =================== > 1. > +/* > + * Write logical decoding DDL message into XLog. > + */ > +XLogRecPtr > +LogLogicalDDLMessage(const char *prefix, Oid roleoid, const char *message, > + size_t size, bool transactional) > > I don't see anywhere the patch using a non-transactional message. Is > it required for any future usage? The non-transactional behavior has > some known consistency issues, see email [1]. The transactional flag is not required by the current usage. I thought it might be useful if other logical decoding plugins want to log and consume DDL messages in a non-transactional way. But I don't have a specific use case yet. > 2. For DDL replication, do we need to wait for a consistent point of > snapshot? For DMLs, that point is a convenient point to initialize > replication from, which is why we export a snapshot at that point, > which is used to read normal data. Do we have any similar needs for > DDL replication? The current design requires manual schema initialization on the subscriber before the logical replication setup. As Euler Taveira pointed out, snapshot is needed in initial schema synchronization. And that is a different topic. > 3. The patch seems to be creating an entry in pg_subscription_rel for > 'create' message. Do we need some handling on Drop, if not, why? I > think adding some comments for this aspect would make it easier to > follow. It's already handled by existing logic in heap_drop_with_catalog: https://github.com/zli236/postgres/blob/ddl_replication/src/backend/catalog/heap.c#L2005 I'll add some comment. > 4. The handling related to partition tables seems missing because, on > the subscriber-side, it always creates a relation entry in > pg_subscription_rel which won't work. Check its interaction with > publish_via_partition_root. I will test it out. >Even if this works, how will we make Alter Table statement work where >it needs to rewrite the table? There also I think we can face a >similar problem if we directly send the statement, once the table will >be updated due to the DDL statement and then again due to table >rewrite as that will have a separate WAL. Yes, I think any DDL that can generate DML changes should be listed out and handled properly or documented. Here is one extreme example involving volatile functions: ALTER TABLE nd_ddl ADD COLUMN t timestamp DEFAULT now(). Again, I think we need to somehow skip the data rewrite on the subscriber when replicating such DDL and let DML replication handle the rewrite. >Another somewhat unrelated problem I see with this work is how to save >recursion of the same command between nodes (when the involved nodes >replicate DDLs). For DMLs, we can avoid that via replication origins >as is being done in the patch proposed [1] but not sure how will we >deal with that here? I'll need to investigate "recursion of the same command between nodes", could you provide an example? Regards, Zheng