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 1oItL9-0002Xd-So for pgsql-performance@arkaria.postgresql.org; Tue, 02 Aug 2022 14:57:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oItL8-0000xC-P5 for pgsql-performance@arkaria.postgresql.org; Tue, 02 Aug 2022 14:57:46 +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 1oItL8-0000x3-5k for pgsql-performance@lists.postgresql.org; Tue, 02 Aug 2022 14:57:46 +0000 Received: from campbell-lange.net ([178.79.140.51]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oItL5-0000G7-8G for pgsql-performance@postgresql.org; Tue, 02 Aug 2022 14:57:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=campbell-lange.net; s=it; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5hvd4z2i0I9Q0Qzpxv+845JHdP410cZzNUeGHo4hgAA=; b=L1g+0rHm8CD5XxMKYFO6UOfXIp qXqoXPQp2xL9Tsn+oLDVkAW+Xk/sgFbmpkuIefJ3EmPjFjv23XLCpnbTbMRbFM0eCYtZ65RKx7TsZ z7PiafetLCRypI6fHtFkNtKN6A9MYlJoxpuqiJe7XRHmb2nS7B4nada7JMzrzXZv2IBE=; Received: from arennes-651-1-229-47.w90-32.abo.wanadoo.fr ([90.32.108.47] helo=rory-t470s) by campbell-lange.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oItL2-0077lE-T0; Tue, 02 Aug 2022 14:57:40 +0000 Received: from rory by rory-t470s with local (Exim 4.94.2) (envelope-from ) id 1oItL1-002bt4-Mn; Tue, 02 Aug 2022 15:57:39 +0100 Date: Tue, 2 Aug 2022 15:57:39 +0100 From: Rory Campbell-Lange To: Robert Blayzor Cc: pgsql-performance@postgresql.org Subject: Re: PgSQL 14 - Logical Rep - Single table multiple publications? Message-ID: References: <3d5996ac-a181-21a5-62a0-1cd34e6b3f1a@inoc.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3d5996ac-a181-21a5-62a0-1cd34e6b3f1a@inoc.net> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 02/08/22, Robert Blayzor (rblayzor.bulk@inoc.net) wrote: > Is it possible to have a single subscriber table contact multiple publishers > and just insert all of the data into a single table on the subscriber? ie: > merge type replication. There are no primary/FK constraints, etc. The > records are just time based audit log type data... Your use case meets, I think, the third "typical use case" listed at https://www.postgresql.org/docs/current/logical-replication.html, namely "Consolidating multiple databases into a single one (for example for analytical purposes)." I've just been testing aggregating all the data in one schema across 300 publisher databases into 5 subscriber schemas on two Postgresql 14 clusters on the same machine. Each of 60 publisher tables are aggregating into a single table on the subscriber. Special care must be taken with the "replica identity" of published tables, as set out at https://www.postgresql.org/docs/current/logical-replication-publication.html. For example, you may need a unique identifying column for each source table in addition to the normal row identifier to differentiate *this* table's id 1 row from the *other* table's id 1 row, otherwise the subscriber won't be able to identify the row to delete if this table's id 1 row is deleted (for example). Although this seems to work fine with native replication, the pglogical extension has more knobs. For instance, the pglogical.wait_for_subscription_sync_complete function is useful to ensure that sync finishes when part of a migration. Rory