Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEdDR-002dEx-29 for pgsql-general@arkaria.postgresql.org; Tue, 04 Jun 2024 23:05:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sEdDR-0039na-4N for pgsql-general@arkaria.postgresql.org; Tue, 04 Jun 2024 23:05:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEdDQ-0039nS-8l for pgsql-general@lists.postgresql.org; Tue, 04 Jun 2024 23:05:16 +0000 Received: from wfout3-smtp.messagingengine.com ([64.147.123.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEdDN-003UN6-3I for pgsql-general@lists.postgresql.org; Tue, 04 Jun 2024 23:05:15 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id DB5061C0015F; Tue, 4 Jun 2024 19:05:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 04 Jun 2024 19:05:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1717542309; x=1717628709; bh=ixMcdYd9B5q842STFCw+sSJPmgYcfMihWJF6fCQNzT8=; b= pR6DdDvveip9gbdji2lLf9gZaYEZztvmK/G8zo15rUSAMCzjyvuNzeCTlv3WNoik X2fYRbjsMzictPiUNJ8Tv5B9ZaNE3vQfqYxNWu73ye7IafLq8NIYifcXsL1NJjaZ T1V7yOSyMLdiRr7G77QFxWJuCImELXDvLdeHDSsR+niVFOT4eK1U5uXJ+8qd173m kEzfCX19mX/88M+Jhk3r15mCScu3rBAVOc3DzNrUR57G1Z6J5WKrjQgWT/H/pdPl KonOPf+DeNN3h5P03zNgpyjxh24q5qQekl+qm4WlCjpTFhuDpqQ/jXgZZN/VUvRQ UfWfYe+kBukUEQ6Rqkr6aA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717542309; x= 1717628709; bh=ixMcdYd9B5q842STFCw+sSJPmgYcfMihWJF6fCQNzT8=; b=E l7CVHU92VaIGf5IcJTfAbXx0uwb0KPA3pTMtqzVPo3Bsf8v2fKPozg2cHQ7A0VDh aeCpwafAzwJ0fPrDLfllYvIK81t/UtcbpLRvELVQjDY7fldTP9ulOYPrwjcHVnSn BM8zvcrAIO2ptViw1wo9lnS/By9pU4QBT8xFKkW0I3swrXUpxwi2Pk3ZMnbXBGdW DL/1oU7wcpwfw3BWC/aayP4BRyclMv4bob9FwctOiVBzn5zG1cZHKoJEp2eb4rbD A+R2Uj2cj5ltknYbKjlWf6B4aB8vuBZ0ip7KIaXFevPAf4/1XYArOZ24oQ09ltoe UGdqbq8tnGqwscb2FcMnA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelhedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthejredttddvjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeekfeehuddvjeeigfeifeejtdduudffledvfeelheef tdeiffeugfdvkeelgedtvdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 4 Jun 2024 19:05:08 -0400 (EDT) Message-ID: <1628637f-419f-4f6a-9cb6-07af90cd0bc4@aklaver.com> Date: Tue, 4 Jun 2024 16:05:08 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Questions on logical replication To: Koen De Groote , PostgreSQL General References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/4/24 15:55, Koen De Groote wrote: > I recently read the entire documentation on logical replication, but am > left with a question on the buildup of WAL > > On this page: > https://www.postgresql.org/docs/current/logical-replication-subscription.html#LOGICAL-REPLICATION-SUBSCRIPTION-SLOT > > It is written: " When dropping a subscription, the remote host is not > reachable. In that case, disassociate the slot from the subscription > using |ALTER SUBSCRIPTION| before attempting to drop the subscription. > If the remote database instance no longer exists, no further action is > then necessary. If, however, the remote database instance is just > unreachable, the replication slot (and any still remaining table > synchronization slots) should then be dropped manually; otherwise > it/they would continue to reserve WAL and might eventually cause the > disk to fill up. Such cases should be carefully investigated." > > > Assuming a situation where I add tables 1 at a time to the publisher, > and refresh the subscription every time. > > What happens if I shut down the subscriber database for a while? The > subscription isn't dropped, so am I reading it right that the disk on > the publisher will slowly be filling up with WAL? Isn't that always the > case if wall is enabled? https://www.postgresql.org/docs/current/wal-configuration.html "Checkpoints are points in the sequence of transactions at which it is guaranteed that the heap and index data files have been updated with all information written before that checkpoint. At checkpoint time, all dirty data pages are flushed to disk and a special checkpoint record is written to the WAL file. (The change records were previously flushed to the WAL files.) In the event of a crash, the crash recovery procedure looks at the latest checkpoint record to determine the point in the WAL (known as the redo record) from which it should start the REDO operation. Any changes made to data files before that point are guaranteed to be already on disk. Hence, after a checkpoint, WAL segments preceding the one containing the redo record are no longer needed and can be recycled or removed. (When WAL archiving is being done, the WAL segments must be archived before being recycled or removed.)" > > This "cause disk to fill up" warning is quite concerning, and I'd like > to understand what could cause it and how likely it is? I thought > logical replication uses WAL by default, so doesn't that mean there has > to be a log of changes kept anyhow? Even if the WAL isn't written to > disk by an "archive_command"? https://www.postgresql.org/docs/current/warm-standby.html#STREAMING-REPLICATION-SLOTS "Replication slots provide an automated way to ensure that the primary does not remove WAL segments until they have been received by all standbys, and that the primary does not remove rows which could cause a recovery conflict even when the standby is disconnected." When you set up logical replication you are 'asking' via the replication slot that WAL records be kept on the publisher until the subscriber retrieves them. > > Regards, > Koen De Groote -- Adrian Klaver adrian.klaver@aklaver.com