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 1wHBK5-006vv5-0M for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Apr 2026 02:03:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wHBK3-00Bht8-0b for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Apr 2026 02:03:43 +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 1wHBK2-00Bht0-2o for pgsql-hackers@lists.postgresql.org; Mon, 27 Apr 2026 02:03:42 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wHBJz-00000003GE9-0PZV for pgsql-hackers@postgresql.org; Mon, 27 Apr 2026 02:03:42 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-362ddc1de56so2391420a91.1 for ; Sun, 26 Apr 2026 19:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777255416; x=1777860216; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=AXrFAAATff2yPqw61wZ+6bc55MQIhawfc4fFgzbvc9E=; b=ClJhSLW4Yfqel3fRpTxygYC037mFhYaDBlsF3XOJ/LZB+JP9S8zKaZF+aKAT8SNSaa lacx7uX7+8DcUyhbp2cxlBkfck1ZBxp6Gni4xrUAH/jh4imvICFTiEamFxHcrMk3zFZN E6nhV4Rzoyrvk4IazIQkR/TKYfVPIZRwctzZohsjVvfxDvK2gBryboOXM50dP0nmeJ9+ 3SylDRLbQLkEy6cJc/YozR4f1FB0WK0/f7OkM5p5IkHGb+5rtXj/8OnyXa5IxgGWEbne 60GdaDjLxqyLUvQEzevFhXwgBVm/sigOp4Y0Je3nuxhVy2EeoeTa9D4R8M67UXYb4UMh hWSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777255416; x=1777860216; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AXrFAAATff2yPqw61wZ+6bc55MQIhawfc4fFgzbvc9E=; b=N3BE7SgmvJtq4I1B22443HpNLjLuu2RFa1KAYtYmWqgZpb1YtjKUwAsI2fG5scgmev 0JcyS/AWCNPOR8VVKiUwsR3pI9o/wpgOtU3vZEZGtz5bGJMTgJzqJOkZoZhQjujWSHMz EU11rqB/JqUWJy4rVPz8oYR52Q7G+mGMlaBP2eCtN992PS0aB7eqLT4ZTBAbAJ1cSTWY CQ7EQh1O/2IqOPVCCCnaWX+go5yVwsrq/zSNa4N2azeDItY/9SduIHGEErlQUwyf0YKA kh6hM67+l1BzcsEWroUGM5Ra3yw1ymwP5qjqzL1XanPzSkbcoW56KrR4aOdzprBKeTBF 9plg== X-Forwarded-Encrypted: i=1; AFNElJ+l7nKGBPtNCVBsOrMqJiqda5SkURhM02G1d1YvnJ2PJlnXMEgpwz3MtvdnPsSX0WMPOih8D90FJQHJXY6Q@postgresql.org X-Gm-Message-State: AOJu0YxsB4shV1j7VW1C7UQLeMQ+9EKctuGXaR4GjLXKbyFEiH0z+HAe R+u46w4hPLah9EugFb0cDIEo4/744hMMTcuH+ZxiZ5oqTCBQbXD8BqDp X-Gm-Gg: AeBDiesvA+5Cbcxo8PWUtw5uiOqMSmPV3MH7Hs3P8eq/gK9w14IFrNfvOJP1butyYcI QSu8+UbGbnVc5uJ58TbS91jBHJgMUv91NMy5go5a1rvB68JAjXnGhDUA7pK9g/4p07QhE2AgaPN lDcOHdets8NgnP0JrurkPE31CIVF4L4/E17GF9YIRhFJUuJWsaq5MbJxyeDFNPk2vz+cMf9abIZ 30D9DmpkhWoEXE8Jt0QRB4S7tbQRyJxhGpLEZBUmvWGvs7gK03hggXIn0I4LLM721JOOCc071PZ vSTN3i0PKK48mbo69/Te5Ggf5xAiH0E0rQ0kdoOdTvox9G/r5bN5+KX6AtuRfF9/LB5zsL5LiMt cAZk6eCHb9kjsR1B7uIfk7bcUSt5vOkcU5beFczNeIangjQzMth/w+Jj751LdvUUdL+mr/fDPDo nZr0DUm3NCNcogWSDRIOvG4AB3b95mLV7cxtoTS4nbLkk= X-Received: by 2002:a17:90b:35c6:b0:35e:5aa5:ae38 with SMTP id 98e67ed59e1d1-361403ebe7cmr37299869a91.9.1777255416337; Sun, 26 Apr 2026 19:03:36 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab20695sm285702655ad.56.2026.04.26.19.03.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Apr 2026 19:03:35 -0700 (PDT) From: Chao Li Message-Id: <0777DBAC-9348-423A-AB51-5AAFDA445B95@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_952909EB-5CB5-47A2-8461-6799AE293AD8" 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 Date: Mon, 27 Apr 2026 10:02:59 +0800 In-Reply-To: <13310e0b-e2b0-45a2-873d-e2b51a8ea3b4@dunslane.net> Cc: SATYANARAYANA NARLAPURAM , Tom Lane , PostgreSQL-development , Japin Li To: Andrew Dunstan 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> X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_952909EB-5CB5-47A2-8461-6799AE293AD8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > 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=20= >> 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 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. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_952909EB-5CB5-47A2-8461-6799AE293AD8 Content-Disposition: attachment; filename=v2-0001-ddlutils-error-out-when-pg_get_database_ddl-sees-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v2-0001-ddlutils-error-out-when-pg_get_database_ddl-sees-.patch" Content-Transfer-Encoding: quoted-printable =46rom=209e14a21e5cd5dcd7680a2cbdcc761126c8a23f79=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Wed,=2015=20Apr=202026=2013:32:12=20+0800=0ASubject:=20[PATCH=20= v2]=20ddlutils:=20error=20out=20when=20pg_get_database_ddl()=20sees=20a=0A= =20missing=20tablespace=0A=0Apg_get_database_ddl_internal()=20calls=20= get_tablespace_name()=20for=20a=0Adatabase's=20dattablespace,=20and=20= then=20passes=20the=20result=20to=0Apg_strcasecmp()=20without=20checking=20= for=20NULL=20first.=0A=0AFix=20that=20by=20detecting=20the=20missing=20= tablespace=20explicitly=20and=20raising=20an=0AERROR=20with=20= ERRCODE_UNDEFINED_OBJECT.=0A=0AAuthor:=20Chao=20Li=20=0A= Reviewed-by:=0ADiscussion:=20= https://postgr.es/m/573E45C1-31A4-4885-A00C-1A2171159A2A@gmail.com=0A---=0A= =20src/backend/utils/adt/ddlutils.c=20|=206=20++++++=0A=201=20file=20= changed,=206=20insertions(+)=0A=0Adiff=20--git=20= a/src/backend/utils/adt/ddlutils.c=20b/src/backend/utils/adt/ddlutils.c=0A= index=20d83cda3342e..b3f819271ad=20100644=0A---=20= a/src/backend/utils/adt/ddlutils.c=0A+++=20= b/src/backend/utils/adt/ddlutils.c=0A@@=20-986,6=20+986,12=20@@=20= pg_get_database_ddl_internal(Oid=20dbid,=20bool=20pretty,=0A=20=09{=0A=20= =09=09char=09=20=20=20*spcname=20=3D=20= get_tablespace_name(dbform->dattablespace);=0A=20=0A+=09=09if=20(spcname=20= =3D=3D=20NULL)=0A+=09=09=09ereport(ERROR,=0A+=09=09=09=09=09= errcode(ERRCODE_UNDEFINED_OBJECT),=0A+=09=09=09=09=09errmsg("tablespace=20= with=20OID=20%u=20does=20not=20exist",=0A+=09=09=09=09=09=09=20=20=20= dbform->dattablespace));=0A+=0A=20=09=09if=20(pg_strcasecmp(spcname,=20= "pg_default")=20!=3D=200)=0A=20=09=09=09append_ddl_option(&buf,=20= pretty,=204,=20"TABLESPACE=20=3D=20%s",=0A=20=09=09=09=09=09=09=09=20=20= quote_identifier(spcname));=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_952909EB-5CB5-47A2-8461-6799AE293AD8--