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 1wIL59-007zpA-0K for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Apr 2026 06:41:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wIL57-006JjB-1S for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Apr 2026 06:41:05 +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 1wIL57-006Jj3-0P for pgsql-hackers@lists.postgresql.org; Thu, 30 Apr 2026 06:41:05 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wIL54-00000003SnQ-3jOy for pgsql-hackers@postgresql.org; Thu, 30 Apr 2026 06:41:04 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-35dac556bb2so369887a91.1 for ; Wed, 29 Apr 2026 23:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777531262; x=1778136062; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=O3BmkUynpJyx4Lvdxx7FRmQVmGqV3IEoVOuz2pYvX2I=; b=mxnYjioDNORcpL+hozCdk50tkrcITMVjAVKVecxUWgpj0Vqm8x3dyI6isai3rOMdlD ODl9FVg3EIGZ9HNtPzX7jjyoMk7KuXR0MTiT3eBemJ6mNZE7p7EQZdeJBuCannJUj6+e H69ht5B/PNJqnYE/I2diUSEdNO+ni+9sWWM6hYzCRyHl74cY+eUa1vPW+rfNgie8M4GG tMk/KOWFBbcvK+5q15PkXMUBIMeMxn2yth2gNRnta7KZPCuX2EOYWiOSw7Us22apxPVg WUirRIxBDbwXlLurEvFjypSOE1DaND0/5vL1HZOXkodoB1OpxpFgsYkL5TtZiBx5iT4w +4CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777531262; x=1778136062; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=O3BmkUynpJyx4Lvdxx7FRmQVmGqV3IEoVOuz2pYvX2I=; b=cFHnjNoIy1n66JpToIpD+zZ5C3FJNozT65yejPT+KeJXrgA57Hi8XnVGa/0UcmWuIc lUAoVlH6CtvTXpPrWp5otywI/v2+z0+CdX2rdYD+Y2FU/r81lYVQ3uGSau4t8Xk2nya4 mzh4Kv82T0smGqCktDlEPqs1no9Q+PJFMEfvjgq9UnxT6TEj4B6QZY0rr7zfqv/cF9do qKgTS+AYx/V0AiJxiRxtJuiZGp9u+o8o49M3etxHv63vlG3XR9QhefDdfkVyCheDzAQ0 Vk59Jmd1Q4TpaVU4EOlZk6jrleZU/OQ00NDeILdZAAOWZK2d+0Lir+xumVbL0ZZn8zAP Iqtw== X-Forwarded-Encrypted: i=1; AFNElJ8J9Hru+fZ5aarJM3ElLuMQ5s5N5VKEQzkgtFh3kHpssFGkgX/zEOs/X/2K5PY/4aDWzG2lmIWQ5D1kZ7o3@postgresql.org X-Gm-Message-State: AOJu0YwkzRNZ7QeHTGT7UyWdhLtXeOY5BCwdEv6D8BOfwafrZ0gpndR2 1Ph9hNfZAdhm/edBYc31EbalyD02+oXDpLASbNxF/3TBrikCsIYIwP7ONWKbDxPEJK0= X-Gm-Gg: AeBDiesZQmxUdjcZ26dHaqb8zeSaYykuzbSWujy1Dpd9Fv3q2We1PqnYiNv1h7fuzMO bmc/AAB4GQw45qtYeKm717OvQtHOonMhWNmt97RaAXH0zJjDZqK+GP/MEZzBQqin9HnuwOM50iU 9eLbGiLaVSkHhtCbvTWtaoxu3/rIMDwInpjahRxTYc8M7wU0HXyrVhTQt4dp1gtK1hH2bEx9EiG YhUEvQcVceCX1mDHA31MbkMtZYdiOZ6juZy1oKj6QuoYOYpJtydvg7hPfVyQNHVCt+Y6wbPqvJh bhtgthRkbOauVejBZiz0Nt3AB00jCaAUtoaHjStqmqr0uLEUWmDimjrQdgdq2cx6ltaKetnXkCB 6UzbKvk4xQpDKaZ84lD0hDJKjb8EdwUCrDPrtn4N3NLHx9rIAjyGlvhROU8J6dab1doMPOGfGl3 p5h0RP5U8CZASACz1D5UU+5b9PT2eRONAEDRc76Diulg== X-Received: by 2002:a17:90b:2f04:b0:35d:9c43:57fe with SMTP id 98e67ed59e1d1-364c30cb5admr1530326a91.13.1777531261764; Wed, 29 Apr 2026 23:41:01 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-364a2732502sm2422086a91.3.2026.04.29.23.40.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2026 23:41:01 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Fix a server crash problem from pg_get_database_ddl From: Chao Li In-Reply-To: Date: Thu, 30 Apr 2026 14:40:21 +0800 Cc: Andrew Dunstan , Tom Lane , PostgreSQL-development , Japin Li Content-Transfer-Encoding: quoted-printable Message-Id: 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> To: SATYANARAYANA NARLAPURAM X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 27, 2026, at 12:56, SATYANARAYANA NARLAPURAM = wrote: >=20 > Hi Chao, >=20 > On Sun, Apr 26, 2026 at 7:03=E2=80=AFPM Chao Li = wrote: >=20 >=20 > > On Apr 26, 2026, at 22:50, Andrew Dunstan = wrote: > >=20 > >=20 > > On 2026-04-23 Th 2:47 AM, SATYANARAYANA NARLAPURAM wrote: > >>=20 > >>=20 > >> Thanks for printing out that. Yes, they are similar. > >>=20 > >> 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). > >> ``` > >>=20 > >> So, let me take back this patch. > >>=20 > >> [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. > >>=20 > >> Attached an injection point test to show the race. Not intended to = commit. > >>=20 > >>=20 > >=20 > > 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. > >=20 > > cheers > >=20 > > andrew > > -- > > Andrew Dunstan > > EDB: https://www.enterprisedb.com > >=20 >=20 > The v1 patch raises an error when the tablespace name is NULL. >=20 > PFA v2: removed hint from the error message, because I now consider = the hint might not be necessary. >=20 > + if (spcname =3D=3D NULL) > + ereport(ERROR, > + errcode(ERRCODE_UNDEFINED_OBJECT), > + errmsg("tablespace with OID %u does not exist", > + dbform->dattablespace)); > + >=20 > A message with error detail that says a concurrent DDL could have = dropped a tablespace could be better? > System catalog is optional. > Something like: >=20 > errdetail("The tablespace may have been dropped concurrently, or the = system catalog is inconsistent."))); >=20 > Thanks, > Satya Hi Satya, Thanks for your review. I hesitate to add a detail message here because = we do not actually know the root cause. A concurrent DROP TABLESPACE = could be one cause, but some unusual user operation could also lead to = the same result, so I am not sure the detail message would help much. The main purpose of this patch is to avoid passing NULL to = pg_strcasecmp() and to report the missing object clearly. So I think the = errmsg itself is enough. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/