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 1wH0oO-006mtt-1a for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Apr 2026 14:50:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wH0oL-00APZ0-1a for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Apr 2026 14:50:17 +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.96) (envelope-from ) id 1wH0oL-00APYs-0E for pgsql-hackers@lists.postgresql.org; Sun, 26 Apr 2026 14:50:17 +0000 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wH0oI-00000002sqp-0jjG for pgsql-hackers@postgresql.org; Sun, 26 Apr 2026 14:50:15 +0000 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-8f231f3b130so216506985a.3 for ; Sun, 26 Apr 2026 07:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20251104.gappssmtp.com; s=20251104; t=1777215013; x=1777819813; darn=postgresql.org; h=in-reply-to:autocrypt:content-language:from:references:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=qlSUb9neXnmRFqRLGiURHB2g0tcsVoeQcW0rRI2P/3c=; b=vXTAGUDxLtECyeYuiKar3wr5OQFLOmX4W8t7219HLOC6uclsfw1fpJ1YLb7zyUamle sCj45UJKRIiWkaJw/3Ec2hW2xA1DYUI60z7g++u7NCwFjTGYtJUxrtWumbts704U3ZPu ZdqPWPqGMMbkcJDpFA3qvema5GpRbdytgB1q1M3WLiqTDdEmKAiYSP0xnj2AHbf9EEX7 Wjm+n8O7XIWcHTT+g4e5HiNWI3q3Jwq7PXvAy9uf8v0kPVyPIULV3HJaCO5gbOFwqEZ3 TNw/3FKr/tadbNjTYXokXF+ocS9brSUdUD1BiGxUwfBvC9uTk5w05v9arh3dnLZ0GDq0 faIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777215013; x=1777819813; h=in-reply-to:autocrypt:content-language:from:references:to:subject :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qlSUb9neXnmRFqRLGiURHB2g0tcsVoeQcW0rRI2P/3c=; b=kBkmQKB2g9eoet4ogH371KUCsuNgh0hWcLMtemuWMvckOn3b7VBQfcwALgRk0jfC5Y 9qpq+xaqhx8opy38veMPQKtDIpGYxKtDqrGdcnOXvqnUjVeZ2qJ7FfP2uRp0nVzCUflG DIcdK7H/wzxadjJZh0sxQGNcDXz4ovXfDHyvct70fpzQJtFjXbho5Nm7fC3frAt6WMdK 2RhElGfTb1mLKBDDOhKZvvHUVP3rv5prAp/lZeqEEyXyRyMjn31E9xgGHsdDM5FNA97f L0NTeGHP9XVyZtNUrbVqgr4sdydItlANsFgQfmo52YDBiUcgZ+M44hL5wePG6pLunvWG 9q5Q== X-Forwarded-Encrypted: i=1; AFNElJ/0Ztit9LwKPrsJtxf0rtwdZ7k+9ddHU9t7biiYdpvcjIfGpck2CJ0D+fAzbRXXCXyRjLXIHRHAT3nILXGX@postgresql.org X-Gm-Message-State: AOJu0YwWkQAsZAhJqtXmgOkzsh29oS5oqV9zBI7oRFUMnBse00Ghiks/ 1k5h8vHV7q+/CK9ufHKCpYo81JiNdbBUEScx1Ki7XucIzAIcKUg/RLajYC54tXd/g7o= X-Gm-Gg: AeBDiesI4DoDA40kwZProklIa2vBbiRWgbZTzt4U23eeIMS+WYEMag75H1ZPZNqyJXG BNEjivshbHLW0v/6oV6MvridyqIahDX4dixvjryrH9TZ1fre7JzdZcAWCGA1r72PQ/Fi13GExcG LvoWRecf2Yfox636Ipkz1JAax7wP+EBa+06vbAs8aUrmGQgc2xBAjxsyY3M0bZ8qFOc4UhkL7Yk CD4euoHkggdJ3CAgbSxn138eSTUsRzvYU6ZuS34PeFAd7cfFzuPCHmgZndjvfHJ95ddv7tyACe2 jeignhQmVfeCWB7tyCYh2NbQQwaZi2dKMEF//2K35nnY/mXJvpTRz2lL6NCughKJUkk4QTRMYI3 d2xrZhfptsCz1SAgFJkq2d7m/QWw78eGiKnIxOxu0SrCOukGT21eRsC8s5vpw4w145JSqCDIUa5 sVblB+fl/OH6T9Uf0J4IXdw4ky+bSmChuy7E1sP1fn X-Received: by 2002:a05:620a:198a:b0:8cd:b61f:2f48 with SMTP id af79cd13be357-8e79208406fmr5347253085a.42.1777215012759; Sun, 26 Apr 2026 07:50:12 -0700 (PDT) Received: from ?IPV6:2605:a601:a6b0:500::1cb? ([2605:a601:a6b0:500::1cb]) by smtp.googlemail.com with ESMTPSA id af79cd13be357-8e7d94d3f99sm2423574685a.40.2026.04.26.07.50.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Apr 2026 07:50:12 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------RT0YfPq3y6eDsZliE5m0pqsH" Message-ID: <13310e0b-e2b0-45a2-873d-e2b51a8ea3b4@dunslane.net> Date: Sun, 26 Apr 2026 10:50:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Fix a server crash problem from pg_get_database_ddl To: SATYANARAYANA NARLAPURAM , Tom Lane , Chao Li , PostgreSQL-development , Japin Li References: <573E45C1-31A4-4885-A00C-1A2171159A2A@gmail.com> <28b82ab2-5721-4e7c-bf71-979c3f198a2e@app.fastmail.com> <634F4A5D-9D38-4F9D-BC1C-70815CBB5089@gmail.com> From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNJEFuZHJldyBEdW5zdGFuIDxhbmRyZXdAZHVuc2xhbmUubmV0PsLAlwQTAQgAQQIbAwIX gAIZAQULCQgHAwUVCgkICwUWAgMBAAIeBRYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNGd BQkdEO8nAAoJEJn6f8tZ/DuBq74H/jkTR4Zi3stbw+xC7v2u3QozssK7MYPL2AsVfh7OealS h182fiWXpfvmmAB7WUHbhk9GC2RAOnHI/2d2jgKaMLAHsGYOT0YopTVIwRY43fCw/mK67yxc wmDcX+zyKfLaivNbf5A7QPLNwda98bEAMSJ8Sn652Uc6cA8t3uKGsVzbRBQOoYzjgvBCfSrE 9ql3PDNg0l4BfAqabd2f70ZUm9VAMEPrgv/v2xI7M2XiL4g5BVmqLCOwxLM8RMCotCuoweUr VO43DeBCIDwLxotMJKvGWDjBzQYlU1NPUAtNcz/gN9ITUe1VUGjyvGj4u1lxBOcQQUw7l1+T 5moZ4iZxXzvOwE0ETspYWQEIANGc4zQULOxhbqO2dyD51YhqCNRmm9oKWaqf+wmW4tpDe/VV cxAnNizd4LWCHfzpb5cHAtGkOPePMfzWVf6nvdF7d3eglbtf59+zG7O7llV0xSSoFiieQBsr GvqDInXYX/4mRRXMtyhM353/tixC9RWLs1oofyYmCPPXXY7h9R7en3B8BoVrRFcdzlIY/NFN hFGW/9dkEiGjgna2Rk6e15kln4ZvFBWUg23p93w/pqXcxY6+k/8TEk+C4R+M6w7o2PLGOjdZ +kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaYL++LAEOqrlvm2Tvq QqZRtnEAEQEAAcLAfAQYAQgAJgIbDBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNI2BQkd EODdAAoJEJn6f8tZ/DuBfw0IAKTsfD40teP/pp+bsLLMSxPXUYrrprTj7WFB5v61p6dkpSr/ qXmMlyahdxQFaPmfVgVirB1Vk/kHiWNnnGjfUV9nB2Zg9LI0Xb9/ts3LsUiRWXzG3tkMY6XL vsVOxW4XFRND9l2q+WW93aZ1DZl+fqWfYgMvsusFRhmGFOKTRfKPta2Pkv+AhA24N4+PrR5p bU4k2MO8PAGiK8eaYKGFG1bHKuAvoDoF7WXJ3FHxuWqLnKEt4dfOLm5pAe3zq1Lt6q8azT9i QWGpSAK5vQUWQHBHpiDjdPeqKZ6HiAXIIKfSmb+jrvXBqoP+D6/K7rUjG2aXiRtTIAXms9sm VRu7cmw= In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------RT0YfPq3y6eDsZliE5m0pqsH Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026-04-23 Th 2:47 AM, SATYANARAYANA NARLAPURAM wrote: > > > > Thanks for printing out that. Yes, they are similar. > > I agree with what Tom said in [2]: > ``` > This is not a bug. This is a superuser intentionally breaking > the system by corrupting the catalogs. There are any number > of ways to cause trouble with ill-advised manual updates to a > catalog table. Try, eg, "DELETE FROM pg_proc" (... but not in > a database you care about). > ``` > > So, let me take back this patch. > > [2] > https://www.postgresql.org/message-id/1538113.1768921841@sss.pgh.pa.us > > > In this case, it is a very corner case but not something superuser > intentionally breaks. > For example, a concurrent tablespace dropĀ + database ddl to assign a > different tablespace or default. > We aren't acquiring Access Share lock on the DB in this function > (intentional) so it is a good practice > to do the null checks. Of course, it makes more sense to add this > comment while doing a code review. > I will let Tom and others chime in with their thoughts on fixing this. > > Attached an injection point test to show the race. Not intended to commit. > > I agree if there's a race condition we should protect against it. I don't much like the idea of silently ignoring it, though. Raising an error seems more like the right thing to do. cheers andrew -- Andrew Dunstan EDB:https://www.enterprisedb.com --------------RT0YfPq3y6eDsZliE5m0pqsH Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2026-04-23 Th 2:47 AM, SATYANARAYANA NARLAPURAM wrote:


Thanks for printing out that. Yes, they are similar.

I agree with what Tom said in [2]:
```
This is not a bug. This is a superuser intentionally breaking
the system by corrupting the catalogs. There are any number
of ways to cause trouble with ill-advised manual updates to a
catalog table. Try, eg, "DELETE FROM pg_proc" (... but not in
a database you care about).
```

So, let me take back this patch.

[2] https://www.postgresql.org/message-id/1538113.1768921841@sss.pgh.pa.us

In this case, it is a very corner case but not something superuser intentionally breaks.
For example, a concurrent tablespace dropĀ + database ddl to assign a different tablespace or default.
We aren't acquiring Access Share lock on the DB in this function (intentional) so it is a good practice
to do the null checks. Of course, it makes more sense to add this comment while doing a code review.
I will let Tom and others chime in with their thoughts on fixing this.

Attached an injection point test to show the race. Not intended to commit.



I agree if there's a race condition we should protect against it. I don't much like the idea of silently ignoring it, though. Raising an error seems more like the right thing to do.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com
--------------RT0YfPq3y6eDsZliE5m0pqsH--