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 1sp4yB-00GHV1-4L for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Sep 2024 12:00:12 +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 1sp4y9-0020A4-FW for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Sep 2024 12:00:09 +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 1sp4y8-00209h-U6 for pgsql-hackers@lists.postgresql.org; Fri, 13 Sep 2024 12:00:09 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sp4y5-000xX2-Qb for pgsql-hackers@lists.postgresql.org; Fri, 13 Sep 2024 12:00:07 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2f75de9a503so23264611fa.0 for ; Fri, 13 Sep 2024 05:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726228804; x=1726833604; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8+YnZpqkkOStJyV3iYp5oWMQNO+eiSvpJvmYUm87/zU=; b=QpSvddY876gLy1uFdJbwCVFfHhu2+hAEbDTPl4KZZbv6cvlHhbggFa1x9hC85sl1Fj kZCZZDOCG6cXF8kZ7z+PCUmo32jNK/8bSi29sb5kmzDwySu226QSS9KKUrzE5WhJtxYr zrOmZOY8IQHL+wOUt28DENPQyA5A9mosPqFzm83B+IzXurD1psDPOffi+zPoaoMfCcMM IE67pWSm1jVITaG39fnDP8whp5FnWp3NCzXWlDo6e0CnvTt7eu/DdjvjMkQkR33E7V25 OYmYRedXQib6HmsE7+9qf7ExtN7dtglb+QtQOV1oDlko1XdVRSVnn36Ey8P56rKOBcci oKGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726228804; x=1726833604; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8+YnZpqkkOStJyV3iYp5oWMQNO+eiSvpJvmYUm87/zU=; b=cdK1fqCONk17CSmSsgKjMAomNZo9YxBfNsn4hR3cvjgefu/A+SAxJGTHPMSsnhf7uQ p7L++ax80yRZgV+mNsdDZv1d9wfk10H5TkKLWDmbuyZXuVAfiJQcAS3JWkYznlRcQfmy Vo5B9R9MuVu59VQEGLsjdkMdI7VRlGccwmay4YH2e8wd8522Wwk+AWAjesAfzNvpjams yIAeQ6OR2hn5/4+6BE2pIrGL5eXMDPFukGF906yy6S00wlwPTQvlNemgZH1U13u9zpqa kULBqHup4Fig9v6uZpnV59Bf4ZHb5TlOgOZGUct+3Fv5hX6Ad4joP4IO/AQtObC6npyL pShA== X-Forwarded-Encrypted: i=1; AJvYcCW15kOrZCqsoJIazt5FwUYO+jyV5LiO2L7na8hxpE7h1w9bqeEoQ+U7kY+NRi79qJoOBuoqinm2qUw4bGvR@lists.postgresql.org X-Gm-Message-State: AOJu0Ywsw4D+HDlKM17RgrQCVk9zqZgR9hWARZJa7E9if6fYYXCR5hDn VSuZulEaVG4A1Yy9kuncKcyIc6yFajgObSSYzlzhPa4inlH5Lv6g X-Google-Smtp-Source: AGHT+IFKh18kyEB1u2XWj8MmFLCFKcS0um6gPqzXLWSPjtUb1jQlx82Yy3Tc8NiweqR8u13t2D2jRw== X-Received: by 2002:a05:651c:220c:b0:2f7:5519:710d with SMTP id 38308e7fff4ca-2f787f447dfmr39097781fa.33.1726228803356; Fri, 13 Sep 2024 05:00:03 -0700 (PDT) Received: from [1.0.0.7] ([178.155.16.7]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f75c0b29casm22066551fa.138.2024.09.13.05.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Sep 2024 05:00:02 -0700 (PDT) Message-ID: <1d7b08f2-64a2-77fb-c666-c9a74c68eeda@gmail.com> Date: Fri, 13 Sep 2024 15:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [HACKERS] make async slave to wait for lsn to be replayed To: Alexander Korotkov , Kevin Hale Boyes Cc: Kartyshov Ivan , Kyotaro Horiguchi , hlinnaka@iki.fi, alvherre@alvh.no-ip.org, pashkin.elfe@gmail.com, bharath.rupireddyforpostgres@gmail.com, euler@eulerto.com, thomas.munro@gmail.com, peter@eisentraut.org, amit.kapila16@gmail.com, dilipbalaut@gmail.com, smithpb2250@gmail.com, pgsql-hackers@lists.postgresql.org References: <20240620.173045.1163445432733259320.horikyota.ntt@gmail.com> <8d0286f9f0c2f9fc29794dda6b5f4600@postgrespro.ru> From: Alexander Lakhin Content-Language: en-US In-Reply-To: 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 Hi Alexander, 10.08.2024 20:18, Alexander Korotkov wrote: > On Sat, Aug 10, 2024 at 7:33 PM Alexander Korotkov wrote: >> On Tue, Aug 6, 2024 at 5:17 AM Alexander Korotkov wrote: >> ... >> Here is a revised version of the patchset. I've fixed some typos, >> identation, etc. I'm going to push this once it passes cfbot. > The next revison of the patchset fixes uninitialized variable usage > spotted by cfbot. When running check-world on a rather slow armv7 device, I came across the 043_wal_replay_wait.pl test failure: t/043_wal_replay_wait.pl .............. 7/? # Tests were run but no plan was declared and done_testing() was not seen. # Looks like your test exited with 29 just after 8. regress_log_043_wal_replay_wait contains: ... 01234[21:58:56.370](1.594s) ok 7 - multiple LSN waiters reported consistent data ### Promoting node "standby" # Running: pg_ctl -D .../src/test/recovery/tmp_check/t_043_wal_replay_wait_standby_data/pgdata -l .../src/test/recovery/tmp_check/log/043_wal_replay_wait_standby.log promote waiting for server to promote.... done server promoted [21:58:56.637](0.268s) ok 8 - got error after standby promote error running SQL: 'psql::1: ERROR:  recovery is not in progress HINT:  Waiting for LSN can only be executed during recovery.' while running 'psql -XAtq -d port=10228 host=/tmp/Ftj8qpTQht dbname='postgres' -f - -v ON_ERROR_STOP=1' with sql 'CALL pg_wal_replay_wait('0/300D0E8');' at .../src/test/recovery/../../../src/test/perl/PostgreSQL/Test/Cluster.pm line 2140. 043_wal_replay_wait_standby.log contains: 2024-09-12 21:58:56.518 UTC [15220:1] [unknown] LOG:  connection received: host=[local] 2024-09-12 21:58:56.520 UTC [15220:2] [unknown] LOG:  connection authenticated: user="android" method=trust (.../src/test/recovery/tmp_check/t_043_wal_replay_wait_standby_data/pgdata/pg_hba.conf:117) 2024-09-12 21:58:56.520 UTC [15220:3] [unknown] LOG:  connection authorized: user=android database=postgres application_name=043_wal_replay_wait.pl 2024-09-12 21:58:56.527 UTC [15220:4] 043_wal_replay_wait.pl LOG: statement: CALL pg_wal_replay_wait('2/570CB4E8'); 2024-09-12 21:58:56.535 UTC [15123:7] LOG:  received promote request 2024-09-12 21:58:56.535 UTC [15124:2] FATAL:  terminating walreceiver process due to administrator command 2024-09-12 21:58:56.537 UTC [15123:8] LOG:  invalid record length at 0/300D0B0: expected at least 24, got 0 2024-09-12 21:58:56.537 UTC [15123:9] LOG:  redo done at 0/300D088 system usage: CPU: user: 0.01 s, system: 0.00 s, elapsed: 14.23 s 2024-09-12 21:58:56.537 UTC [15123:10] LOG:  last completed transaction was at log time 2024-09-12 21:58:55.322831+00 2024-09-12 21:58:56.540 UTC [15123:11] LOG:  selected new timeline ID: 2 2024-09-12 21:58:56.589 UTC [15123:12] LOG:  archive recovery complete 2024-09-12 21:58:56.590 UTC [15220:5] 043_wal_replay_wait.pl ERROR: recovery is not in progress 2024-09-12 21:58:56.590 UTC [15220:6] 043_wal_replay_wait.pl DETAIL:  Recovery ended before replaying target LSN 2/570CB4E8; last replay LSN 0/300D0B0. 2024-09-12 21:58:56.591 UTC [15121:1] LOG:  checkpoint starting: force 2024-09-12 21:58:56.592 UTC [15220:7] 043_wal_replay_wait.pl LOG: disconnection: session time: 0:00:00.075 user=android database=postgres host=[local] 2024-09-12 21:58:56.595 UTC [15120:4] LOG:  database system is ready to accept connections 2024-09-12 21:58:56.665 UTC [15227:1] [unknown] LOG:  connection received: host=[local] 2024-09-12 21:58:56.668 UTC [15227:2] [unknown] LOG:  connection authenticated: user="android" method=trust (.../src/test/recovery/tmp_check/t_043_wal_replay_wait_standby_data/pgdata/pg_hba.conf:117) 2024-09-12 21:58:56.668 UTC [15227:3] [unknown] LOG:  connection authorized: user=android database=postgres application_name=043_wal_replay_wait.pl 2024-09-12 21:58:56.675 UTC [15227:4] 043_wal_replay_wait.pl LOG: statement: CALL pg_wal_replay_wait('0/300D0E8'); 2024-09-12 21:58:56.677 UTC [15227:5] 043_wal_replay_wait.pl ERROR: recovery is not in progress 2024-09-12 21:58:56.677 UTC [15227:6] 043_wal_replay_wait.pl HINT: Waiting for LSN can only be executed during recovery. 2024-09-12 21:58:56.679 UTC [15227:7] 043_wal_replay_wait.pl LOG: disconnection: session time: 0:00:00.015 user=android database=postgres host=[local] Note that last replay LSN is 300D0B0, but the latter pg_wal_replay_wait call wants to wait for 300D0E8. pg_waldump -p src/test/recovery/tmp_check/t_043_wal_replay_wait_primary_data/pgdata/pg_wal/ 000000010000000000000003 shows: rmgr: Heap        len (rec/tot):     59/    59, tx:        748, lsn: 0/0300D048, prev 0/0300D020, desc: INSERT off: 35, flags: 0x00, blkref #0: rel 1663/5/16384 blk 0 rmgr: Transaction len (rec/tot):     34/    34, tx:        748, lsn: 0/0300D088, prev 0/0300D048, desc: COMMIT 2024-09-12 21:58:55.322831 UTC rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0300D0B0, prev 0/0300D088, desc: RUNNING_XACTS nextXid 749 latestCompletedXid 748 oldestRunningXid 749 I could reproduce this failure on my workstation with bgworker modified as below: --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -69 +69 @@ int            BgWriterDelay = 200; -#define LOG_SNAPSHOT_INTERVAL_MS 15000 +#define LOG_SNAPSHOT_INTERVAL_MS 15 @@ -307 +307 @@ BackgroundWriterMain(char *startup_data, size_t startup_data_len) -                       BgWriterDelay /* ms */ , WAIT_EVENT_BGWRITER_MAIN); +                       1 /* ms */ , WAIT_EVENT_BGWRITER_MAIN); When looking at the test, I noticed probably a typo in the test message: wait for already replayed LSN exists immediately ... shouldn't it be "exits" there (though maybe the whole phrase could be improved)? I also suspect that "achieve" is not suitable word in the context of LSNs and timeouts. Maybe you would find it appropriate to replace it with "reach"? Best regards, Alexander