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 1tNY8K-000WsB-6Z for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Dec 2024 14:01:08 +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 1tNY7L-0020wx-GH for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Dec 2024 14:00:07 +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 1tNY7L-0020wp-27 for pgsql-hackers@lists.postgresql.org; Tue, 17 Dec 2024 14:00:06 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tNY7I-0002A7-0q for pgsql-hackers@postgresql.org; Tue, 17 Dec 2024 14:00:05 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4361a50e337so37438345e9.0 for ; Tue, 17 Dec 2024 06:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734444002; x=1735048802; darn=postgresql.org; h=content-transfer-encoding:to:subject:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=sEuhPuX25H3VSdKb2RXuDCsQ/9yxZMzmvy94VdAh1ks=; b=WNa6UwoZn2sd4NappuwMui8PrYpwapbnG3I3Q6AiuWo6UdvJMwfM/pCfs4WJemvfQW fzY+/HA3oJY27QJcOL5gM+pEwboREIQoWUZ/E4a3Irb2vo0KUIDMkRvAgzwp0sC4I4J9 yyIcG8QPJq4d1zvUWS5YQl/aBzHTld7bIVj2ZCraRAiQAevJorDr14Vzw69jDTeTpMpg R/TXCjcJ2a/e+PKkX6b22kIzwGSqjAqTTD8EqizxAA2yjKcIxvFCDxiZtL+R556ER+Cq zsMJs9YX9u0/4vVKyTWH21CMQjd/6UB5Pa/SYQp6FcnCfSr5MFleY2hgreBS+v/zKlFc 6jZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734444002; x=1735048802; h=content-transfer-encoding:to:subject:from:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sEuhPuX25H3VSdKb2RXuDCsQ/9yxZMzmvy94VdAh1ks=; b=CsRLIWtZFGWZTDaB+SL/68lm8jIjcLTypv00go6inefaIb1e0XIFOM5oyCbZdtQ5i2 LdxW1hDV92PB4/mav8IQ/3fW+qSL6lIHwuvPoack1ejPOuad2RN7PFkxMsPCT0Q/xg+9 UM6hx+S5wsQmu7eFFwlMun7jJhpcjNcM0h2PBKmYWODt8+FAajsHFU2mlTAuTsqH2k3p OKL3ILMSa9s/uOjvNCNfZODS976XdZKmM8ky7ypqXiFDmLPV8wAx1xTPJXZDagW7zikC MYaRStwRpg38semQ8CGv4lsYWDYyXFeVW60EbG8uEH3DRbb7BvFfVB4KpSwLPDms2pO3 xCZQ== X-Gm-Message-State: AOJu0YzGmJNeJ/6KN/K++5QZ9Q3UUYKTJnA1N6Qlqo6Qg53zM3QR89Hi 3n+PJfK4ZJndpwd/ChHA2qzuNJFIOSBm3dCuobO7ufnCoBBqGrXFG2oX78Yj X-Gm-Gg: ASbGncsJqcvedeCPhOpG94r7/d38CjXu1PzMn3PpokdGEcHBbj44Ur0TsGOrPpnvrXx E1Lj6sjN/f8B/TpCWrLWKSNAuqS9PN96SaqL5++vzKJ8FG1/GWFLsJnAB2yV3M2CXJYYvTrzvL/ M7L6tD9Pm5iD0exDlZE9AvveTS1bj0g65TeyXIcoK6V/KYaIaddGOlJ73GGE/e3uuC7WRElDO6X CpPNo9jKV6IQp0A0PgtU3bevWhhvLKjKXr2YfFibPoVL7BtNDUNoYAXEzoGrg== X-Google-Smtp-Source: AGHT+IEYYg/O1IEC5HCY9XGfT3aMupNwgezhP9AiR1XnE0vJI1/w1Vp9CzqdmsGcE65NNS5c6Fo7gw== X-Received: by 2002:a05:600c:83c9:b0:434:f219:6b28 with SMTP id 5b1f17b1804b1-4362aaa9625mr132207465e9.24.1734444002173; Tue, 17 Dec 2024 06:00:02 -0800 (PST) Received: from [192.168.100.26] ([178.168.43.57]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801223dsm11407428f8f.3.2024.12.17.06.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Dec 2024 06:00:01 -0800 (PST) Message-ID: <0b07ead5-a5da-445e-9698-a7d340708bdf@gmail.com> Date: Tue, 17 Dec 2024 16:00:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Alexander Lakhin Subject: 019_replslot_limit.pl might fail due to checkpoint skipped To: pgsql-hackers Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello hackers, Investigating a recent buildfarm failure [1] with the following diagnostics: [12:27:41.437](0.024s) ok 18 - have walreceiver pid 637143 [12:30:42.564](181.127s) not ok 19 - walsender termination logged [12:30:42.564](0.000s) [12:30:42.564](0.000s) #   Failed test 'walsender termination logged' #   at t/019_replslot_limit.pl line 382. 019_replslot_limit_primary3.log: 2024-12-13 12:27:40.912 ACDT [637093:7] LOG:  checkpoint starting: wal ... 2024-12-13 12:27:41.461 ACDT [637182:4] 019_replslot_limit.pl LOG: statement: SELECT pg_logical_emit_message(false, '', 'foo'); 2024-12-13 12:27:41.462 ACDT [637182:5] 019_replslot_limit.pl LOG: statement: SELECT pg_switch_wal(); 2024-12-13 12:27:41.463 ACDT [637182:6] 019_replslot_limit.pl LOG: disconnection: session time: 0:00:00.003 user=postgres database=postgres host=[local] 2024-12-13 12:27:41.668 ACDT [637093:8] LOG:  checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 1 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.756 s; sync files=0, longest=0.000 s, average=0.000 s; distance=1024 kB, estimate=1024 kB; lsn=0/900060, redo lsn=0/700028 2024-12-13 12:27:41.668 ACDT [637093:9] LOG:  checkpoints are occurring too frequently (1 second apart) 2024-12-13 12:27:41.668 ACDT [637093:10] HINT:  Consider increasing the configuration parameter "max_wal_size". 2024-12-13 12:30:42.565 ACDT [637144:10] standby_3 LOG:  terminating walsender process due to replication timeout ### waiting for walsender termination logged timed out after 3 minuts 2024-12-13 12:30:42.565 ACDT [637144:11] standby_3 STATEMENT: START_REPLICATION SLOT "rep3" 0/700000 TIMELINE 1 (note that checkpoint was started at 40.912 and completed at 41.668, i.e., it took 0.7 seconds) I've found that such a failure can occur when the checkpoint, which should invalidate replication slot (through the call chain: CreateCheckPoint() -> InvalidateObsoleteReplicationSlots() -> InvalidatePossiblyObsoleteSlot()), is skipped. I've managed to reproduce this with the following sleep() added inside src/backend/access/transam/xlog.c: @@ -7126,6 +7126,11 @@ CreateCheckPoint(int flags)          * panic. Accordingly, exit critical section while doing it.          */         END_CRIT_SECTION(); +if (rand() % 2 == 0) +{ +elog(LOG, "!!!CreateCheckPoint| sleeping..."); +pg_usleep(1000000); +} When running just make -s check -C src/test/recovery/ PROVE_TESTS="t/019*" in a loop. I got failures on iterations 3, 4, 13, so with debug logging enabled, I can see the following: [12:57:41.899](0,009s) ok 18 - have walreceiver pid 509480 [13:00:44.862](182,963s) not ok 19 - walsender termination logged [13:00:44.862](0,000s) [13:00:44.862](0,000s) #   Failed test 'walsender termination logged' #   at t/019_replslot_limit.pl line 382. 019_replslot_limit_primary3.log: 2024-12-17 12:57:41.695 UTC [][509460:11][checkpointer] LOG: checkpoints are occurring too frequently (0 seconds apart) 2024-12-17 12:57:41.695 UTC [][509460:12][checkpointer] HINT: Consider increasing the configuration parameter "max_wal_size". 2024-12-17 12:57:41.695 UTC [][509460:13][checkpointer] LOG: checkpoint starting: wal 2024-12-17 12:57:41.695 UTC [][509460:14][checkpointer] LOG: !!!CreateCheckPoint| sleeping... ... 2024-12-17 12:57:41.903 UTC [][509460:15][checkpointer] DEBUG: performing replication slot checkpoint ... 2024-12-17 12:57:41.907 UTC [postgres][509495:5][client backend] [019_replslot_limit.pl] LOG:  statement: SELECT pg_logical_emit_message(false, '', 'foo'); 2024-12-17 12:57:41.908 UTC [postgres][509495:6][client backend] [019_replslot_limit.pl] LOG:  statement: SELECT pg_switch_wal(); ... 2024-12-17 12:57:41.947 UTC [][509460:16][checkpointer] DEBUG: snapshot of 0+0 running transaction ids (lsn 0/C00060 oldest xid 742 latest complete 741 next xid 742) 2024-12-17 12:57:41.947 UTC [][509460:17][checkpointer] DEBUG: attempting to remove WAL segments older than log file 000000000000000000000009 2024-12-17 12:57:41.947 UTC [][509460:18][checkpointer] DEBUG: removing write-ahead log file "000000010000000000000009" 2024-12-17 12:57:41.948 UTC [][509460:19][checkpointer] DEBUG: SlruScanDirectory invoking callback on pg_subtrans/0000 2024-12-17 12:57:41.948 UTC [][509460:20][checkpointer] LOG: checkpoint complete: wrote 0 buffers (0.0%), wrote 0 SLRU buffers; 0 WAL file(s) added, 1 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.253 s; sync files=0, longest=0.000 s, average=0.000 s; distance=1024 kB, estimate=1024 kB; lsn=0/C00060, redo lsn=0/A00028     ### the checkpoint, that started before pg_switch_wal(), is completed 2024-12-17 12:57:41.948 UTC [][509460:21][checkpointer] LOG: checkpoints are occurring too frequently (0 seconds apart) 2024-12-17 12:57:41.948 UTC [][509460:22][checkpointer] HINT: Consider increasing the configuration parameter "max_wal_size". 2024-12-17 12:57:41.948 UTC [][509460:23][checkpointer] DEBUG: checkpoint skipped because system is idle     ### the checkpoint, which expected to invalidate the replication slot after pg_switch_wal, is skipped Reproduced starting from commit 24043c27b (dated 2021-07-23), which added this test case. [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=alligator&dt=2024-12-13%2001%3A24%3A58 Best regards, Alexander