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 1sbi8T-000sFD-BZ for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Aug 2024 14:59:34 +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 1sbi8R-007yP3-Cl for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Aug 2024 14:59:31 +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 1sbi8R-007yOv-0K for pgsql-hackers@lists.postgresql.org; Wed, 07 Aug 2024 14:59:31 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sbi8N-003YlB-Iz for pgsql-hackers@postgresql.org; Wed, 07 Aug 2024 14:59:29 +0000 Received: from [192.168.1.110] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4WfCxl63n1zyNj; Wed, 7 Aug 2024 17:59:23 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1723042764; 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=BaAmd0JzR/aedxtEVxPXB1nb7mLBTpd/MY5dddDy1j0=; b=A7NqGkoyvJU3e9dbNa4hGtu1c+MddwLsRB7c7VJZMZTyeotZ5j8SVoNU7tutgu1VmBb8gC 5AgkYDFFlCn/ShmRYnXJ+5cd7pFhY30XgGdG+/nbFdMnKOYtJRuWkpE9gPw2p//ycnV6zq LNBGOY6YY4YlBXneqEN91KLZ/YxjE1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1723042764; 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=BaAmd0JzR/aedxtEVxPXB1nb7mLBTpd/MY5dddDy1j0=; b=UfPCUgOPCRJTEDQVHg2ZtVa27gkFchLvIKL0FDBQ3HajbxtIHN5vHeuRXvPqx7M7YGMxKP DOaas3xMDtT3JEvPjL0xPDh8w7CBHgDkw/XspS3/IoLTPnje6ULpXbdyQYiA9EaoxVnx+S 8pQYEBqANwyKDUUcMaAFyI6sQP1QSgE= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1723042764; a=rsa-sha256; cv=none; b=pzCPEgREA5g6leJY7L5uV3H0S0A7/1fOp8Dd+PY4zTvzQrLCpeZRl59JDmA4i/ey6rDEVY 86qn99vXOx8x6arPhZ7yzhifXWPsdToXB8zmQ4Hgo2UlOaY1KLtKqhGcR7RTfHv/E/fB62 M3XDltxtba9ekTFImUNBkOTAznfSUhg= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <46f047a1-bfd5-406a-a0f3-97205d9529ad@iki.fi> Date: Wed, 7 Aug 2024 17:59:23 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Heikki Linnakangas Subject: Re: Interrupts vs signals To: Thomas Munro Cc: pgsql-hackers , Andres Freund , Robert Haas References: <20211020192748.dguzfnnd4hzh7e5v@alap3.anarazel.de> <20211111195000.v5fmy5yvtqcbvo55@alap3.anarazel.de> <3b996d73-2a10-4072-a58d-0386af0cbb78@iki.fi> Content-Language: en-US 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 10/07/2024 09:48, Thomas Munro wrote: > The next problems to remove are, I think, the various SIGUSR2, SIGINT, > SIGTERM signals sent by the postmaster. These should clearly become > SendInterrupt() or ProcSetLatch(). The problem here is that the > postmaster doesn't have the proc numbers yet. One idea is to teach > the postmaster to assign them! Not explored yet. With my latest patches on the "Refactoring postmaster's code to cleanup after child exit" thread [1], every postmaster child process is assigned a slot in the pmsignal.c array, including all the aux processes. If we moved 'pending_interrupts' and the process Latch to the pmsignal.c array, then you could send an interrupt also to a process that doesn't have a PGPROC entry. That includes dead-end backends, backends that are still in authentication, and the syslogger. That would also make it so that the postmaster would never need to poke into the procarray. pmsignal.c is already designated as the limited piece of shared memory that is accessed by the postmaster (BackgroundWorkerSlots is the other exception), so it would be kind of nice if all the information that the postmaster needs to send an interrupt was there. That would mean that where you currently use a ProcNumber to identify a process, you'd use an index into the PMSignalState array instead. I don't insist on changing that right now, I think this patch is OK as it is, but that might be a good next step later. [1] https://www.postgresql.org/message-id/8f2118b9-79e3-4af7-b2c9-bd5818193ca4%40iki.fi I'm also wondering about the relationship between interrupts and latches. Currently, SendInterrupt sets a latch to wake up the target process. I wonder if it should be the other way 'round? Move all the wakeup code, with the signalfd, the self-pipe etc to interrupt.c, and in SetLatch, call SendInterrupt to wake up the target process? Somehow that feels more natural to me, I think. > This version is passing on Windows. I'll create a CF entry. Still > work in progress! Some comments on the patch details: > ereport(WARNING, > (errmsg("NOTIFY queue is %.0f%% full", fillDegree * 100), > - (minPid != InvalidPid ? > - errdetail("The server process with PID %d is among those with the oldest transactions.", minPid) > + (minPgprocno != INVALID_PROC_NUMBER ? > + errdetail("The server process with pgprocno %d is among those with the oldest transactions.", minPgprocno) > : 0), > - (minPid != InvalidPid ? > + (minPgprocno != INVALID_PROC_NUMBER ? > errhint("The NOTIFY queue cannot be emptied until that process ends its current transaction.") > : 0))); This makes the message less useful to the user, as the ProcNumber isn't exposed to users. With the PID, you can do "pg_terminate_backend(pid)" > diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c > index c42742d2c7b..bfb89049020 100644 > --- a/src/backend/optimizer/util/pathnode.c > +++ b/src/backend/optimizer/util/pathnode.c > @@ -18,6 +18,7 @@ > > #include "foreign/fdwapi.h" > #include "miscadmin.h" > +#include "postmaster/interrupt.h" > #include "nodes/extensible.h" > #include "optimizer/appendinfo.h" > #include "optimizer/clauses.h" misordered > + * duplicated interrupts later if we switch backx. typo: backx -> back > - if (IdleInTransactionSessionTimeoutPending) > + if (ConsumeInterrupt(INTERRUPT_IDLE_TRANSACTION_TIMEOUT)) > { > /* > * If the GUC has been reset to zero, ignore the signal. This is > @@ -3412,7 +3361,6 @@ ProcessInterrupts(void) > * interrupt. We need to unset the flag before the injection point, > * otherwise we could loop in interrupts checking. > */ > - IdleInTransactionSessionTimeoutPending = false; > if (IdleInTransactionSessionTimeout > 0) > { > INJECTION_POINT("idle-in-transaction-session-timeout"); The "We need to unset the flag.." comment is a bit out of place now, since the flag was already cleared by ConsumeInterrupt(). Same in the INTERRUPT_TRANSACTION_TIMEOUT and INTERRUPT_IDLE_SESSION_TIMEOUT handling after this. -- Heikki Linnakangas Neon (https://neon.tech)