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 1rywVD-001BYn-J8 for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Apr 2024 16:26:47 +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 1rywVC-008L75-83 for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Apr 2024 16:26:46 +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 1rywVB-008KsA-KD for pgsql-hackers@lists.postgresql.org; Mon, 22 Apr 2024 16:26:45 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rywV8-0046Z9-V2 for pgsql-hackers@lists.postgresql.org; Mon, 22 Apr 2024 16:26:44 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-2343ae31a9bso1744601fac.1 for ; Mon, 22 Apr 2024 09:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1713803202; x=1714408002; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=upB2l/aMTC76GGXRBef5i+UqNi7Wtqsf9NpuEt8c3iA=; b=ao/CJyhYNqGV29knVYC6wBohcs595oApoAsPAB4ozTEoUs+lbkRV3+Q4CTJBkpW2G8 5yPPHWrfvEEHfHkVO9ydpvtVwHgVNMji9rePxPjyfLi2LZ0AqU/WXxY/+Qfrf2uHsZKT gBdyNoG8KpoRuOFtYpGB1tE8AijX8JSwqN3+4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713803202; x=1714408002; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=upB2l/aMTC76GGXRBef5i+UqNi7Wtqsf9NpuEt8c3iA=; b=dEFQ4w1X/LSULEeEOnM96Ijy8RGdwvszT2bu3K5rhquX3GmP5JmCQ5Tv5LopE1TqKJ B1aQkYIlIlj+kZP1vyEpNrw7cfmg3czLDOU7U6NNrJF3cvvJNLZ+iebmag5szw2zgmef E8hsPZ5LvB+ymTWn7U2LP5UcOcPWKPztV5NDoQP01JskJkFQt6S2RGqdzUn6Bq9AcAv0 gq2uh4Trj+rtwSmHGx0PlVO3iK1NxnyIgXoilt9/mBien2a5t+8T11XvQn1l0TU7JHpZ kGV8y+5gYiyN+kS6RniVwN7yGuIkgNK70vorXjw2mjWGxLk+zFxwBheJXF6BgyaiyIb5 sPdQ== X-Forwarded-Encrypted: i=1; AJvYcCWw6qX6vf7Yn2HCuPoKf6YkPeEULnHBJEPQbZpMro5uo6cwL3z/sT0qaVKsGjpk7wr5xQkRiTlc2mzk1tT1ggPrWeJ3OYikB9L3vBGJt3b/WfwR X-Gm-Message-State: AOJu0YwioadfgYz0C+CHyDOPcQsyphIXrWa0ww796d+IxFMhsw3PBSiu XLbYf5IHtD0b/w+4RlaaNwFkfOUC1OOz2/5Scgx+0jHSBov9nAMzvhFhK+8N7Q== X-Google-Smtp-Source: AGHT+IGxo4Yo4+8DldNLS7JcHwrO1H77lIBKeatc8XpUriR0Rge4EDS3y9FG6KntLqIxCSfZGOOHbQ== X-Received: by 2002:a05:6871:b19c:b0:229:a2a4:58b7 with SMTP id an28-20020a056871b19c00b00229a2a458b7mr8414205oac.40.1713803202223; Mon, 22 Apr 2024 09:26:42 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id v6-20020a056830140600b006ed048519bbsm585352otp.66.2024.04.22.09.26.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2024 09:26:41 -0700 (PDT) Date: Mon, 22 Apr 2024 09:26:39 -0700 From: Noah Misch To: Amit Kapila Cc: Kirill Reshke , PostgreSQL Hackers Subject: Re: TerminateOtherDBBackends code comments inconsistency. Message-ID: <20240422162639.68@rfd.leadboat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Apr 15, 2024 at 11:17:54AM +0530, Amit Kapila wrote: > On Thu, Apr 11, 2024 at 6:58 PM Kirill Reshke wrote: > > > > While working on [0] i have noticed this comment in > > TerminateOtherDBBackends function: > > > > /* > > * Check whether we have the necessary rights to terminate other > > * sessions. We don't terminate any session until we ensure that we > > * have rights on all the sessions to be terminated. These checks are > > * the same as we do in pg_terminate_backend. > > * > > * In this case we don't raise some warnings - like "PID %d is not a > > * PostgreSQL server process", because for us already finished session > > * is not a problem. > > */ > > > > This statement is not true after 3a9b18b. > > "These checks are the same as we do in pg_terminate_backend." The comment mismatch is a problem. Thanks for reporting it. The DROP DATABASE doc mimics the comment, using, "permissions are the same as with pg_terminate_backend". > > But the code is still correct, I assume... or not? In fact, we are > > killing autovacuum workers which are working with a given database > > (proc->roleId == 0), which is OK in that case. Are there any other > > cases when proc->roleId == 0 but we should not be able to kill such a > > process? > > > > Good question. I am not aware of such cases but I wonder if we should > add a check similar to 3a9b18b [1] for the reason given in the commit > message. I have added Noah to see if he has any suggestions on this > matter. > > [1] - > commit 3a9b18b3095366cd0c4305441d426d04572d88c1 > Author: Noah Misch > Date: Mon Nov 6 06:14:13 2023 -0800 > > Ban role pg_signal_backend from more superuser backend types. That commit distinguished several scenarios. Here's how they apply in TerminateOtherDBBackends(): - logical replication launcher, autovacuum launcher: the proc->databaseId test already skips them, since they don't connect to a database. Vignesh said this. - autovacuum worker: should terminate, since CountOtherDBBackends() would terminate them in DROP DATABASE without FORCE. - background workers that connect to a database: the right thing is less clear on these, but I lean toward allowing termination and changing the DROP DATABASE doc. As a bgworker author, I would value being able to recommend DROP DATABASE FORCE if a worker is sticking around unexpectedly. There's relatively little chance of a bgworker actually wanting to block DROP DATABASE FORCE or having an exploitable termination-time bug. Thoughts?