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 1nTMVn-0007Xu-2y for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Mar 2022 11:35:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nTMVk-0005fn-8R for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Mar 2022 11:35:44 +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 1nTMVj-0005fe-TV for pgsql-hackers@lists.postgresql.org; Sun, 13 Mar 2022 11:35:43 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nTMVe-00089H-Os for pgsql-hackers@lists.postgresql.org; Sun, 13 Mar 2022 11:35:42 +0000 Received: by mail-lf1-x133.google.com with SMTP id g17so22465733lfh.2 for ; Sun, 13 Mar 2022 04:35:38 -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:content-transfer-encoding; bh=Vc4cwgqUR44KWl8OVne9YJ40c2Vi1M4ZmorW+lhW6uw=; b=QIXd482cCWFFEoBkx8JADmj4hEbIcpUdLGZIMDd6gOoYNadkk2JQyv64+OjuK8q5G+ IRYjX2Ib1rFiDPBA60dF2yC3vI/ta3ATthULwmL+hteEML/Q8jYKN1yy9td1vddEiR+u MAiNWwWx3aYznaE3xJY7ANyJhP2UKYwzpURloVIR2b17+hazgra5oSRQj8LEfT+zrSOq +u9m0vEOGitfweS1OoJhaQhRGgZh6w1HfwoZVkap2NauxmJc2jLM+WSTNJnRO240yfQg kTls3k6XxwxGV49JVm3ou148cDelEtBJmTYNRksDpC4/OMR2Ot3nH2CMZ7W+ACy70LBH bfAA== 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:content-transfer-encoding; bh=Vc4cwgqUR44KWl8OVne9YJ40c2Vi1M4ZmorW+lhW6uw=; b=jC1o8yYACQi1YY920K/ULpC8ZOuBPuCiaTcbYnKljcH7R8DYNNZ2ZrL1J/R3HG76UN BWpRsfnAdtyZ+qW6R3QJAnllqacdufNuYRtlLh/X/XIBFtBzhROtJNDB7h356T42+8D5 O6m5IpfX0aO5WN6DBMwi31kIUxK8Z3ydEJJDhwQ9KpQUeDI4/r3UXF5fI1stL+biR2+G dTPMK89X3QF3G5GmFlDZZBdoGS6FT2iSzPzot1/BWD+UcIS5hMJwVVhDvgs213tECrAK qVcha+tO7a9IeZh/Au8KlfT8D8mYvO1if9YWSeYYqerCVvX26qf1cJkuLTcqZ2WQRhpY LKNQ== X-Gm-Message-State: AOAM532lKKcv/UyPvKLmZ3ltswi3wh9xG0b9KNh8YAs7stSoLNtTKAuV 3e8R6x+YInk1mu69gySl9HTZ1mIHRD68xfcHOYs= X-Google-Smtp-Source: ABdhPJxKbKaf1wPddFGnBqypnA+M82Y2j1VKELnJvsZyXvIj8xZjMfHg+tDBehmNcIrP38T5+PHpDeX8Nmyz6TGNwH8= X-Received: by 2002:a05:6512:308e:b0:448:3826:6d68 with SMTP id z14-20020a056512308e00b0044838266d68mr10385605lfd.184.1647171336112; Sun, 13 Mar 2022 04:35:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Dilip Kumar Date: Sun, 13 Mar 2022 17:05:18 +0530 Message-ID: Subject: Re: Support logical replication of DDLs To: Zheng Li Cc: PostgreSQL Hackers 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 Mon, Feb 21, 2022 at 9:43 PM Zheng Li wrote: > > Hello, > > One of the most frequently requested improvements from our customers > is to reduce downtime associated with software updates (both major and > minor versions). To do this, we have reviewed potential contributions to > improving logical replication. > > I=E2=80=99m working on a patch to support logical replication of data > definition language statements (DDLs). This is a useful feature when a > database in logical replication has lots of tables, functions and > other objects that change over time, such as in online cross major > version upgrade. +1 > I put together a prototype that replicates DDLs using the generic > messages for logical decoding. The idea is to log the candidate DDL > string in ProcessUtilitySlow() using LogLogicalMessge() with a new > flag in WAL record type xl_logical_message indicating it=E2=80=99s a DDL > message. The xl_logical_message record is decoded and sent to the > subscriber via pgoutput. The logical replication worker process is > dispatched for this new DDL message type and executes the command > accordingly. If you don't mind, would you like to share the POC or the branch for this w= ork? > However, there are still many edge cases to sort out because not every > DDL statement can/should be replicated. Some of these include: > 3. CREATE TABLE AS and SELECT INTO, For example: > > CREATE TABLE foo AS > SELECT field_1, field_2 FROM bar; > > There are a few issues that can occur here. For one, it=E2=80=99s pos= sible > that table bar doesn't exist on the subscriber. Even if =E2=80=9Cbar=E2= =80=9D does > exist, it may not be fully up-to-date with the publisher, which would > cause a data mismatch on =E2=80=9Cfoo=E2=80=9D between the publisher and = subscriber. In such cases why don't we just log the table creation WAL for DDL instead of a complete statement which creates the table and inserts the tuple? Because we are already WAL logging individual inserts and once you make sure of replicating the table creation I think the exact data insertion on the subscriber side will be taken care of by the insert WALs no? --=20 Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com