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 1wHE1k-006yMH-2j for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Apr 2026 04:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wHE1j-00C9Au-0I for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Apr 2026 04:56:59 +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 1wHE1i-00C9Am-2R for pgsql-hackers@lists.postgresql.org; Mon, 27 Apr 2026 04:56:58 +0000 Received: from mail-vs1-xe34.google.com ([2607:f8b0:4864:20::e34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wHE1g-00000003HKu-0b8B for pgsql-hackers@postgresql.org; Mon, 27 Apr 2026 04:56:58 +0000 Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-610e2e8f57dso3499631137.0 for ; Sun, 26 Apr 2026 21:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777265814; cv=none; d=google.com; s=arc-20240605; b=arJ9tXboPXXnYd9JBs8zrHCSAzS/Qct1n4gpwfUFfnBFTi5xE3hWFKHRv7eu3YziOl fJSp0w8nwh+V72yoJXlzdctwmV6fwcAvVvU3YbEzU+iIucTlpVsgZhyYLzJ4b2qO7SxM 77MH7KIrfNG6JIOk4KqanVbypdMHt10MCwYSTm10XfGuZXbHxNZ4V5weEP4IK26KjyuP YlHoAb7hwntrJxCnWvdtfgDxrwJQBIlWrLh7LwLBfxbaMa5qWYyi+hjGn5gK+qQnyygm AHt4jDBGSrFvqljfS+R9tR8BPBQoqhdV8eRg3wgJnW0hbaL7/9bEOyCxxNlqN3JuQmEp AP/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=IQIu60beyVE3Paxvt3T8TwDN6pXSgyyzX8gWnq6HV6M=; fh=PcocpQXnErpyUs8rFm1WdE+u8F8uZTC/NrhI+taTgOU=; b=UY/rDrT/I2QudTJf7NUNQCib8OY/u7wPzyMfFEjxS/OTuOerG4tXODujpbDqyAZhKG +bSJbRKvYfRKdAouAvmovac3IlR4OBvBDhCe0I3KjYAg2nko9J5kOcu70hHN1lQLbLwq fOsspJk74z+RQqJW447/maTzMaBkFdcSAPYspPFt6VP78Eh9HAVihS4WqL7817FR65nI ohc85B5eZpOZl54vIdCD2LTvhOwSmU/g1asycz58WDmG532FjxETnLYZk8ggWoCDNipx cvkoQga7oN3vC95lmFWxYctK9SOUd/Q7bAeZSUr4C3jRVcNRs0xlR+1nM72RSWaZ8J8Z taOA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777265814; x=1777870614; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IQIu60beyVE3Paxvt3T8TwDN6pXSgyyzX8gWnq6HV6M=; b=pdSKn1DailGM2niDpeZWVGa4FMGza4OkU5F+IBLMzI9hpMsN+fFr+xKOh81EKZ9hgD XF5+0gqGgnnXLoG54ZGbw7kB2gT8Ln2NB3yt3WaMsE0FFrLr22nGHw0+g/CpPt+mDndj YJErZR7bAVhTd+AT8DLm33ZUna6T1+Rtipq6P7CzZNO330EGDQNxIkZ9jiLy6mboEAfV oKucfxQof9K0ib/b3sq7wg5BORCf4bXa2lvtqa2tn7E1qLhNTgV/XUjNR9K+J06rJJfT drLvzZXWqxKmXcpkWRwAuzN8gG1szMNCb/WT6qnhHP1eyO5++k9wYkYOpIDNP+JDwVA4 TLXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777265814; x=1777870614; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IQIu60beyVE3Paxvt3T8TwDN6pXSgyyzX8gWnq6HV6M=; b=CtsDoBpoG5sX/Z1pnMY38XwMqgjybr2UYhKsuLYKorkPmnkY4qm+tDM9sRFsavtnN7 4k5vYnqAACWxjzZw0WqqjC1P30UrktN0tTjbQ71Gadysr9uCmHGT03yJCE2UlfW+12Mc dNUd1sANHcPYLWTnwW8sSP8TFfu4gRNu/9Q3IWbe/LMqwjvcVC+3v7gV4nUBgfUIJF4q zrly9kH7Y/hblh+O+S0QYqY40wjBwAug8uC4/W1u0eDNaQmWdigD8Xjde6JyJMalUFh3 bL6sHZSQ1FsHLsz+Ji6uiCkgQQ9jSaqBFQzJQceCXfSL8LqPQcIgxKXEk6xgZB4i058x j23w== X-Forwarded-Encrypted: i=1; AFNElJ/jUXeDVTRTkc7czaSekwWNLyHh5M+4tW+Md15OqRcmh7ieOaQA9Myi2D0Ta95ZZlFiclSsgMyOcj6EW4F3@postgresql.org X-Gm-Message-State: AOJu0YyT2ULCe5EIyamaVAtFaKCf/cqtcZwSFxheTrwh1L0SrgZKF3GP 8xYtWG/U43G/dtQT3fCotBzNL6pE/SW50D22SPydLG4xSxiAhZ7Ruvi0noRYin6V54JhT4fEKIx zos+St0d7DUO2BRilomxk4ZCXp78HxX7YNunS X-Gm-Gg: AeBDieuV3m4p+iKYK33EGUmwo8icBs/3+oEZBi7JRrzoFcriWem/aIhJA58HMqrfor0 Z1dk47iUu1umfoB9z4kUXp70bp0G15of7/JDnl1/PiYe/Hy3qzvMpudBT1GMEM6thxT7EUFLH6a 0Q3AZogGggcu7JvbfbU37fl7P5m2x37tHHRgEpSyX2ZBD32JMKgQbjpCZiFI1B7uyQlE28JeRTq 3dHlvClGE78lSgNpzq3q+LhTjBYQ0lI3BXojCNSPZWQSNRyb09QnRY1ymWsw5bX0LT5ybkC2PZU FWkr55faynyWh7W5yg== X-Received: by 2002:a05:6102:2927:b0:607:cc9e:57a9 with SMTP id ada2fe7eead31-616f53a929fmr17797205137.1.1777265813678; Sun, 26 Apr 2026 21:56:53 -0700 (PDT) MIME-Version: 1.0 References: <573E45C1-31A4-4885-A00C-1A2171159A2A@gmail.com> <28b82ab2-5721-4e7c-bf71-979c3f198a2e@app.fastmail.com> <634F4A5D-9D38-4F9D-BC1C-70815CBB5089@gmail.com> <13310e0b-e2b0-45a2-873d-e2b51a8ea3b4@dunslane.net> <0777DBAC-9348-423A-AB51-5AAFDA445B95@gmail.com> In-Reply-To: <0777DBAC-9348-423A-AB51-5AAFDA445B95@gmail.com> From: SATYANARAYANA NARLAPURAM Date: Sun, 26 Apr 2026 21:56:42 -0700 X-Gm-Features: AVHnY4J2GyLhpYh4xa-Y71xDEIHgldAO_qR4zHgC7iuOxAWf9o-cMu1NkYK4sVU Message-ID: Subject: Re: Fix a server crash problem from pg_get_database_ddl To: Chao Li Cc: Andrew Dunstan , Tom Lane , PostgreSQL-development , Japin Li Content-Type: multipart/alternative; boundary="0000000000007eec4b065069f1bc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007eec4b065069f1bc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Chao, On Sun, Apr 26, 2026 at 7:03=E2=80=AFPM Chao Li wr= ote: > > > > On Apr 26, 2026, at 22:50, Andrew Dunstan wrote: > > > > > > 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 erro= r > seems more like the right thing to do. > > > > cheers > > > > andrew > > -- > > Andrew Dunstan > > EDB: https://www.enterprisedb.com > > > > The v1 patch raises an error when the tablespace name is NULL. > > PFA v2: removed hint from the error message, because I now consider the > hint might not be necessary. > + if (spcname =3D=3D NULL) + ereport(ERROR, + errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("tablespace with OID %u does not exist", + dbform->dattablespace)); + A message with error detail that says a concurrent DDL could have dropped a tablespace could be better? System catalog is optional. Something like: errdetail("The tablespace may have been dropped concurrently, or the system catalog is inconsistent."))); Thanks, Satya --0000000000007eec4b065069f1bc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Chao,

On Sun, Apr= 26, 2026 at 7:03=E2=80=AFPM Chao Li <li.evan.chao@gmail.com> wrote:


> On Apr 26, 2026, at 22:50, Andrew Dunstan <andrew@dunslane.net> wrote:
>
>
> 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 n= ot in
>> a database you care about).
>> ```
>>
>> So, let me take back this patch.
>>
>> [2] https://www.postg= resql.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 functi= on (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 t= his.
>>
>> 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
>

The v1 patch raises an error when the tablespace name is NULL.

PFA v2: removed hint from the error message, because I now consider the hin= t might not be necessary.

+ if (spcname =3D= =3D NULL)
+ ereport(ERROR,
+ errcode(ERRCODE_UNDEFINED_OBJECT),=
+ errmsg("tablespace with OID %u does not exist",
+ = =C2=A0 dbform->dattablespace));
+

A= message with error detail that says a concurrent DDL could have dropped a = tablespace could be better?
System catalog is optional.
Something like:

er= rdetail("The tablespace may have = been dropped concurrently, or the system catalog is inconsistent.")));

Thanks,
Satya
--0000000000007eec4b065069f1bc--