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 1vkW5n-00GRR5-1Y for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jan 2026 23:34:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkW5m-00BDAf-1v for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jan 2026 23:33:58 +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 1vkW5m-00BDAX-0d for pgsql-hackers@lists.postgresql.org; Mon, 26 Jan 2026 23:33:58 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vkW5k-00000000cNi-05rF; Mon, 26 Jan 2026 23:33:58 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (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) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4f0PxV6Wcrz49Psn; Tue, 27 Jan 2026 01:33:50 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1769470431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XClmlhR1uXpfaVR/CSYfkQI/nRe0FFau1thS7LqfW2k=; b=aK3dKgtqmbcsgTP199H3IyPZSW7JYrPmP/b5Tz6XoqRHG2b/SQsuzaiO8AAGcvHKpNMc5F lYydVFWLMREQAGAerbazv7DqHYDUX591CvADUGae4X8Bp71TlNwKXOwwQ+PgC4kh251anU kaaTjyB0MYCMZGZrVBl8BviSJaa0+JUeABZL6cvDBfCwZrO9xwMQ8bC3p3dZJFV5HeIxnJ MNQf9eD+kBNrZkzVjYZR6eLTMcQdMcVO6l15sble/XQoVH7kBNUe9Lt4PJDNaUJTVWW43H SF29Yvyyr0oCtqpDsSeqA6tVdRuuj/wlEfmV73UfWavg+eI6N4ikaarjZrij2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1769470431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XClmlhR1uXpfaVR/CSYfkQI/nRe0FFau1thS7LqfW2k=; b=pRLpkNDYQt+UzWPVjcoAYkO434PkI3OvFMeW3cxrBtM9xLbR7WblyxrHV8wFPvgTeA30o1 nRSfM4vr39mbD4krOfk628CGh3CYFI2HHZsj8CDANHWNJ/dVk0slwNW0olrmBvve9CmJFh JmM1QBWCWlLsbKUkaQrYffYvoSkdayQZLriq2C5KANmgBur3D/SKM8c58CAwI63l0TGqtr 45RI8QqcNgfgP6aZSnW68PHAFqby9bq/gHFrM7INwhOrqEPQi8GXuuzwbX6U7SnJDF1E15 nBGsQPZB3UoUVxZHdKVN1A0knJS6T9dTgErwxAW0Vk7MVriPR8UAVy/GNZupHw== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1769470431; b=lme2YdN15KIQVNzWCpMW+ny7q9EG38XV0mK0bVGxlzG0+UKYj+runyZkhltkGon2iRUR1/ AVj3cbL58hq/Zf+C69DbohDXdV5llU2O87GqelsrmSMtc+reZfSzFhHR0Pkk3oZOS15s5Q w7U63kMEySG/hllz5g7C6tbiommA0jwFJ+N0Squoz6/aTctT1PdNj4uqaDKPPpXfmqWacJ +Km8gUXpHhpUaEChDLXZSbpHWY7bw5wT0Fk+uZVDx8V5fdxqS6vlzM1NGL7ZwgwJfyId11 ixPRrN/+bjYCq+Y8Z5zVkWVMBg9KTxhDsVNXpyRBqGUbhEcmg6IVynNEEiJi+Q== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi> Date: Tue, 27 Jan 2026 01:33:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Implement WAIT FOR command To: Alexander Korotkov References: Content-Language: en-US From: Heikki Linnakangas Cc: "pgsql-hackers@postgresql.org" 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 05/11/2025 11:44, Alexander Korotkov wrote: > Implement WAIT FOR command Happened to just spot this: > @@ -1831,20 +1832,30 @@ PerformWalRecovery(void) > */ > ApplyWalRecord(xlogreader, record, &replayTLI); > > /* Exit loop if we reached inclusive recovery target */ > if (recoveryStopsAfter(xlogreader)) > { > reachedRecoveryTarget = true; > break; > } > > + /* > + * If we replayed an LSN that someone was waiting for then walk > + * over the shared memory array and set latches to notify the > + * waiters. > + */ > + if (waitLSNState && > + (XLogRecoveryCtl->lastReplayedEndRecPtr >= > + pg_atomic_read_u64(&waitLSNState->minWaitedLSN[WAIT_LSN_TYPE_REPLAY]))) > + WaitLSNWakeup(WAIT_LSN_TYPE_REPLAY, XLogRecoveryCtl->lastReplayedEndRecPtr); > + > /* Else, try to fetch the next WAL record */ > record = ReadRecord(xlogprefetcher, LOG, false, replayTLI); > } while (record != NULL); > > /* > * end of main redo apply loop > */ > > if (reachedRecoveryTarget) > { I think that WaitLSNWakeup() call is a little misplaced. It's after the recoveryStopsAfter() call, so if recovery is paused right after the record, the waiters won't be woken up until recovery is continued. And I suppose if recovery is stopped and the server is promoted, the waiters will never be woken up, although I didn't verify that. To fix, that should be moved to between the ApplyWalRecord() and recoveryStopsHere() calls. - Heikki