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.96) (envelope-from ) id 1vvzNy-00E94A-0C for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 15:04:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvzNw-004Fwd-3B for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 15:04:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vvzNw-004FwV-29 for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 15:04:08 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvzNt-00000001aRG-3IcM for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 15:04:08 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-679f6f0855bso1046998eaf.0 for ; Fri, 27 Feb 2026 07:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772204644; cv=none; d=google.com; s=arc-20240605; b=SI+UsOBP4lXZvBTnLZxN6ogMhFkDupixIt1UpeguirDVBlCdWo6e4Qmynl8dZ5mhVO 1qeHyNhIF9eZzoJZTjHQu7GmoldErWliFSzihE/Ai7RwKqhTRYLJlgG0hz2VRyrIBRGd X8zVj6SbFRFNgn//Q2bd+8GLQVEaRdDUw2l7KjMHRdtlIphYCjPbiDe5PhhxkREfEdus pmxtmZ+Rm2CHqKiL7/JxSUhokhcAZUkxFnu69V5dtwpEOzRdiHPjlBFUQpsmhdSoFXhE c7yA/XTvsHgUWKXronZ2Urj/z0sB3vQECMKvl528hrAKI5uf4FL09hiYq7BS/BdDSV4z DLGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=gTmx5QLJnJ92r4yC1meJ7FuHmVOnlUcwNcC5HotYJx8=; fh=dxJXJbLzq9Nah1LUdsj4QTuQ3JoDScd0wp1YHY64NXM=; b=dfPIihyPtCyrIyYi4wQDP+ZYx943HUfYg9UqrrL2UVTTB0lmGLK9rxC72D/f3GQzh4 s79EwJpzWpz02odqbUKMzQJSmlttjE6aro5s68jylEs181H21AzWdo38c+g7rRRK7rM0 d4UQmJ7bQGyzF+mXwkUQVWFx+nd5qL8WyO5zkdCO35FyJAMazxDczDJ0ziSXflkETYpw LqIAq9PzEtHEIFg6MP8PknC6RmM7B8jGDegmM/f0uNonTLY+2+EtnC92N2O/IwEBWZSR UdzX1IYhncqswKaxTtIv3IXKVpIgKN0ZQP4poAdMcdkj6IGc056gpOzX/2OAiime9J4h A21A==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772204644; x=1772809444; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=gTmx5QLJnJ92r4yC1meJ7FuHmVOnlUcwNcC5HotYJx8=; b=I53rG/Pqs0mD9oLgp/R3x0vHZAkLQUvza7J+KWE/hSyhErOheahwM+bzpiM/+a141i 7gKvkOKttlpzqJM4be+9unwnTXSOjNyLe2icFTdDponXuYyyLinimB8cFeBhPyH53vSR Ya9xO1VxKoidgN7xAwAmlaujxWRmNbRo5GYS3mWz5pLjk5cxh/Dw5A/ZoQ7vhcjBWIbw BUP1BFs/NlBdNzyMCVAFDySK4+ncElsHZTUMWc8l5wjNwhmmLUFk/aYjVrhbsTwrWoEA u/xMXNksoXL/Ko/ANOiWJsrV27kCeg4q8DjkTEPNs7s8j9RzFl/WTtOZboig6e6UW2P7 B3zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772204644; x=1772809444; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gTmx5QLJnJ92r4yC1meJ7FuHmVOnlUcwNcC5HotYJx8=; b=C132PPEz+f01ifVnaFZM0PQe9IljOfssnSF0hHwQScVA3FvDIeWxSLIyEZcGNF5Et6 gO4WFmUiRWOKp6B94T8pDK/5VuCFoDIzctu9M+9O8iMiEChZr6BUYQIH7gy6fjKqskAJ 2XuE8ihdtcbGC+0mxtd2aoHoPvrrdn1dzkkWGMbPZfYU04dSzzJj7yOC3eXPLOe0/Clq ASwEjddnFfJlxSJTAeUfoHWZAU+Vkq/BrL7kA4wNmiFfrgNEs6VcW1I7XWm7j95sW6ul 0Q8udvCG+u6o6bh7lmfIPhnaw1XWgPzTUDHvUFgheUlvcskHloBeyRw++oTiVExkh7qi Rakw== X-Gm-Message-State: AOJu0YwAtO3vT00tCkiwbYb9xR5HjswVrRz26nxV6Sfoq6YJ89/8kUNt inyV/9sau8T1dp/k6rQJOEX0bjwv5NRAvUlQPGCBUMBWkJygfUW8llnH3uduhWwfeWsAfvE05/r Sdsg+tXzUDCGh5eKxsWEUmrvNVJS9uGhs2fFPZuk= X-Gm-Gg: ATEYQzwqBm5RxdWHEaba0WX+ObF7fUL6YXeQaf+EoPd/VsrlkwtWGjZJsLZxNJq1ljc /BOPaiV/Olquw/e1k2DFhqp5aDcXHkSO8ay0lw/Qon5CWF+vavXi+PCksyBXeFzv5ijXl2RIiXP c/MKP4DAW+IwdR7y6fMXQzMcPyavXnpnFHPx69jandOMI/gjPGnFbx5n5BGrARTC1ZAx2w7WXL+ 0HAjbNsK1FJHoBQopo6niYGGXyzUBFsDfMEviXBwzYAr+15wrNIdUEHmaUF/RmnQySUK1GFuOtX yqngdKufxZ2k6ZFFNY+Ys8cZcaRWeLeOw+lIvCcW7w5G5B2+buBy X-Received: by 2002:a05:6820:1b10:b0:677:98b4:79ab with SMTP id 006d021491bc7-679fae7c465mr1842661eaf.33.1772204643901; Fri, 27 Feb 2026 07:04:03 -0800 (PST) MIME-Version: 1.0 From: Fujii Masao Date: Sat, 28 Feb 2026 00:03:45 +0900 X-Gm-Features: AaiRm52YBVPJCBW4mmv9Cm5TjgJq9NM6rsmhNs1HvFLn4sBiDA52axPXWiGk2zY Message-ID: Subject: Fix slotsync worker busy loop causing repeated log messages To: PostgreSQL Hackers Content-Type: multipart/mixed; boundary="0000000000004541b2064bcf8c4e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000004541b2064bcf8c4e Content-Type: text/plain; charset="UTF-8" Hi, While testing the replication slot sync feature, I observed that the slotsync worker can suddenly start emitting four log messages every 200 ms, even when both primary and standby are idle. For example: -------------------------- 2026-02-27 23:06:46.123 JST [80789] LOG: starting logical decoding for slot "logical_slot" 2026-02-27 23:06:46.123 JST [80789] DETAIL: Streaming transactions committing after 0/03000140, reading WAL from 0/03000098. 2026-02-27 23:06:46.123 JST [80789] LOG: logical decoding found consistent point at 0/03000098 2026-02-27 23:06:46.123 JST [80789] DETAIL: There are no running transactions. 2026-02-27 23:06:46.330 JST [80789] LOG: starting logical decoding for slot "logical_slot" 2026-02-27 23:06:46.330 JST [80789] DETAIL: Streaming transactions committing after 0/03000140, reading WAL from 0/03000098. 2026-02-27 23:06:46.330 JST [80789] LOG: logical decoding found consistent point at 0/03000098 2026-02-27 23:06:46.330 JST [80789] DETAIL: There are no running transactions. 2026-02-27 23:06:46.536 JST [80789] LOG: starting logical decoding for slot "logical_slot" 2026-02-27 23:06:46.536 JST [80789] DETAIL: Streaming transactions committing after 0/03000140, reading WAL from 0/03000098. 2026-02-27 23:06:46.536 JST [80789] LOG: logical decoding found consistent point at 0/03000098 2026-02-27 23:06:46.536 JST [80789] DETAIL: There are no running transactions. -------------------------- These messages repeat roughly every 200 ms. I created the replication slot sync environment as follows: -------------------------- initdb -D data --encoding=UTF8 --locale=C cat <> data/postgresql.conf wal_level = logical synchronized_standby_slots = 'physical_slot' EOF pg_ctl -D data start pg_receivewal --create-slot -S physical_slot pg_recvlogical --create-slot -S logical_slot -P pgoutput --enable-failover -d postgres psql -c "CREATE PUBLICATION mypub" pg_basebackup -D sby1 -c fast -R -S physical_slot -d "dbname=postgres" cat <> sby1/postgresql.conf port = 5433 sync_replication_slots = on hot_standby_feedback = on EOF pg_ctl -D sby1 start -------------------------- After that, I executed the following, and then the issue occurred: -------------------------- SELECT pg_logical_emit_message(true, 'abc', 'xyz'); SELECT pg_replication_slot_advance('logical_slot', max(lsn)) FROM pg_logical_slot_peek_binary_changes('logical_slot', NULL, NULL, 'proto_version', '3', 'publication_names', 'mypub', 'messages', 'true', 'binary', 'false', 'streaming', 'false'); -- Wait for the log message "newly created replication slot "logical_slot" is sync-ready now" to output SELECT pg_replication_slot_advance('logical_slot', max(lsn)) FROM pg_logical_slot_peek_binary_changes('logical_slot', NULL, NULL, 'proto_version', '3', 'publication_names', 'mypub', 'messages', 'true', 'binary', 'false', 'streaming', 'false'); -------------------------- While the issue is happening, the failover logical slot shows: [PRIMARY] =# SELECT slot_name, restart_lsn, confirmed_flush_lsn from pg_replication_slots where slot_name = 'logical_slot'; slot_name | restart_lsn | confirmed_flush_lsn --------------+-------------+--------------------- logical_slot | 0/03000140 | 0/03000140 [STANDBY] =# SELECT slot_name, restart_lsn, confirmed_flush_lsn from pg_replication_slots where slot_name = 'logical_slot'; slot_name | restart_lsn | confirmed_flush_lsn --------------+-------------+--------------------- logical_slot | 0/03000098 | 0/03000140 confirmed_flush_lsn matches on both servers, but restart_lsn differs. Normally, the slotsync worker updates the standby slot using the primary's slot state. However, when confirmed_flush_lsn matches but restart_lsn does not, the worker does not actually update the standby slot. Despite that, the current code of update_local_synced_slot() appears to treat this situation as if an update occurred. As a result, the worker sleeps only for the minimum interval (200 ms) before retrying. In the next cycle, it again assumes an update happened, and continues looping with the short sleep interval, causing the repeated logical decoding log messages. Based on a quick analysis, this seems to be the root cause. I think update_local_synced_slot() should return false (i.e., no update happened) when confirmed_flush_lsn is equal but restart_lsn differs between primary and standby. That would allow the worker to use the normal sleep interval instead of the minimum one. I've attached a PoC patch implementing this change. Thoughts? Regards, -- Fujii Masao --0000000000004541b2064bcf8c4e Content-Type: application/octet-stream; name="v1-0001-Fix-slotsync-worker-busy-loop-causing-repeated-lo.patch" Content-Disposition: attachment; filename="v1-0001-Fix-slotsync-worker-busy-loop-causing-repeated-lo.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mm50tk080 RnJvbSA4Y2Q3MzE4NTc1YTY1MTcyZDQwZjFjZDY2YTZjNWZjODA3ZDMzNjZhIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBGdWppaSBNYXNhbyA8ZnVqaWlAcG9zdGdyZXNxbC5vcmc+CkRh dGU6IEZyaSwgMjcgRmViIDIwMjYgMjM6MDI6MjMgKzA5MDAKU3ViamVjdDogW1BBVENIIHYxXSBG aXggc2xvdHN5bmMgd29ya2VyIGJ1c3kgbG9vcCBjYXVzaW5nIHJlcGVhdGVkIGxvZ2ljYWwKIGRl Y29kaW5nIGxvZ3MuCgpQcmV2aW91c2x5LCB0aGUgc2xvdHN5bmMgd29ya2VyIGNvdWxkIGVudGVy IGEgYnVzeSBsb29wIGFuZCBlbWl0IGZvdXIgbG9naWNhbApsb2cgbWVzc2FnZXMgZXZlcnkgMjAw IG1zLCBldmVuIHdoZW4gYm90aCB0aGUgcHJpbWFyeSBhbmQgc3RhbmRieSB3ZXJlIGlkbGUuCgpU aGlzIGhhcHBlbmVkIGJlY2F1c2UgdGhlIHdvcmtlciBpbmNvcnJlY3RseSB0cmVhdGVkIGNlcnRh aW4gY2FzZXMgYXMKc3VjY2Vzc2Z1bCBzbG90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