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 1nvg9H-00062p-5V for pgsql-general@arkaria.postgresql.org; Mon, 30 May 2022 14:13:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nvg9F-0001sr-Nu for pgsql-general@arkaria.postgresql.org; Mon, 30 May 2022 14:13:33 +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 1nvg9F-0001si-DQ for pgsql-general@lists.postgresql.org; Mon, 30 May 2022 14:13:33 +0000 Received: from relay10.mail.gandi.net ([2001:4b98:dc4:8::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvg9C-0005By-Di for pgsql-general@lists.postgresql.org; Mon, 30 May 2022 14:13:32 +0000 Received: from localhost (pc-153-216-214-201.cm.vtr.net [201.214.216.153]) (Authenticated sender: andrew@acooke.org) by mail.gandi.net (Postfix) with ESMTPA id 4ABC724000C; Mon, 30 May 2022 14:13:25 +0000 (UTC) Received: from localhost (localhost [IPv6:::1]) by localhost (Postfix) with ESMTP id 168DBA7137; Mon, 30 May 2022 10:13:23 -0400 (-04) Date: Mon, 30 May 2022 10:13:23 -0400 From: andrew cooke To: pgsql-general@lists.postgresql.org Subject: Appending data locally to a logical replication subscriber Message-ID: <20220530141323.y2saamlcv6y6h3zf@acooke.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi All, I would appreciate some advice on adding data to logically replicated tables on the subscriber. I am worried about contention between writes from local data loading and replication. We have 14 publisher databases (all with identical schema) that are constantly receiving new data. The tables have a composite primary key where one column identifies the publisher machine. We also have a single subscriber that subscribes to all these machines. In addition to the realtime data described above, we would like to back-load some archive data. For practical (ie political) reasons it is easier to do this on the subscriber than on each publisher. The archive data will use a composite primary key that combines the publisher code (used to differentiate publishers) with an incremental ID that will start at a "sufficiently large number" to avoid conflicts. The loading process is not a simple append; some data are normalized in separate tables. So, for example, there may be a table with orders, where each line is unique, but the orders reference companies in another table, and usually these companies already exist. My primary concern is that there is going to be contention between replication and archive loading. All tables on the subscriber may be queried by users (so disabling indices is not trivial although maybe we could drop constraints and load archive data at night). Really, after all that, I guess I am asking the following: - Is this just a bad idea? Is it implicit (or maybe explicit and I've missed it) that the subscriber should be dedicated only to reading subscriptions? - Do subscriber transactions reflect publisher transactions? For example, if the publisher receives many rows in a single transaction (which can happen if we know/guess that the table is only being written to by one process) does that mean that the subscriber also writes those rows in a single transaction? Or is it "simplified" to a transaction per row? Or something else (like one transaction per "batch")? - Is there anything else I should be concerned about? Thanks, Andrew