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 1u2m5c-005lnb-2C for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Apr 2025 07:12:44 +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 1u2m5Z-009TzS-Sy for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Apr 2025 07:12:42 +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 1u2m5Z-009Tyu-EX for pgsql-hackers@lists.postgresql.org; Thu, 10 Apr 2025 07:12:41 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u2m5W-004152-2M for pgsql-hackers@postgresql.org; Thu, 10 Apr 2025 07:12:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1744269155; bh=DCFCiKcgYcW7x7ekAReAlRfc6zFgtRHe0ipr1kt8bUc=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=NFvww7WH8AiA5UR9/N5Zek5/nWPtufxerH8m82MgIVi8/tnZONgh/HZM21ivybhMq eUcn/goNHzZlSrDkCDrCJUOMUj68YZGBYyEPVbZUgLuEXHN4yPX1ZcQ8q06FlBn0b6 HISYgljn9R4hOWcnYMIXuOs9zepN4dbifKdXlFmAHOxoL7oHRDODH4Rsjw3E8KSMd5 rihQZ6L9tbWxf2AodrGy8JO/qGh125jr3LfNCTGxi82fvkGX5FTo9rce2iQlwvZTKo NfL+4knA/uz13s5b3zkFdFq9YUOLpzaBXM7DZIjZW8diVdpukfbL3bLFRB7EUQH3sG Or7pIxrWPBPPw== Received: from [172.30.48.142] (unknown [93.174.131.138]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: m.melnikov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 040EE6038B; Thu, 10 Apr 2025 10:12:34 +0300 (MSK) Message-ID: <825c1d30-e4cb-4f2c-b27b-0230d4079dcd@postgrespro.ru> Date: Thu, 10 Apr 2025 10:12:34 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: sync_standbys_defined read/write race on startup To: Michael Paquier Cc: Kirill Reshke , PostgreSQL Hackers References: <163fcbec-900b-4b07-beaa-d2ead8634bec@postgrespro.ru> <69541672-0fa2-41ea-af52-6e6110bf7235@postgrespro.ru> Content-Language: en-US From: "Maksim.Melnikov" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/04/10 06:23:00 #27870742 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10.04.2025 05:25, Michael Paquier wrote: > Confirmed. One thing where it would be possible to make things work > is to introduce some persistency of the injection points, say these > are flushed at shutdown. We could do that without touching at the > backend code and only in the module injection_points, but perhaps this > thread is not enough to justify this extra complexity. Agree, it should be discussed in another thread. On 10.04.2025 05:25, Michael Paquier wrote: > What do you think? Yes, patch for me looks ok, only one suggestion, I am not sure but I am afraid we are loosing this.         if (WalSndCtl->sync_standbys_status & SYNC_STANDBY_INIT)         {                 if ((WalSndCtl->sync_standbys_status & SYNC_STANDBY_DEFINED) == 0 ||                         lsn <= WalSndCtl->lsn[mode])                 {                         LWLockRelease(SyncRepLock);                         return;                 }         }         else if (!SyncStandbysDefined())         {                 /*                  * If we are here, the sync standby data has not been initialized yet,                  * so fall back to the best thing we can do: a check on                  * SyncStandbysDefined() to see if the GUC is set or not.                  *                  * If the GUC has a value, we wait until the checkpointer updates the                  * status data because we cannot be sure yet if we should wait or not.                  * If the GUC has *no* value, we are sure that there is no point to                  * wait; this matters for example when initializing a cluster, where                  * we should never wait, and no sync standbys is the default behavior.                  */                 LWLockRelease(SyncRepLock);                 return;         } +       else if (lsn <= WalSndCtl->lsn[mode]) +       { +               LWLockRelease(SyncRepLock); +               return; +       } What do you think? Best regards, Maksim Melnikov