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 1slORy-007L7N-Dq for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Sep 2024 07:59:43 +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 1slORw-008fVR-Dp for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Sep 2024 07:59:40 +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 1slORu-008fVJ-OE for pgsql-hackers@lists.postgresql.org; Tue, 03 Sep 2024 07:59:40 +0000 Received: from fout2-smtp.messagingengine.com ([103.168.172.145] helo=pfout2-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1slORr-000PoF-JR for pgsql-hackers@lists.postgresql.org; Tue, 03 Sep 2024 07:59:37 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 6201B1380382; Tue, 3 Sep 2024 03:59:34 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Tue, 03 Sep 2024 03:59:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725350374; x=1725436774; bh=AlHu/o+Vwl YfqBj/TaxcBEBlxisQiunNmFFwy9zxVZ4=; b=EHgyS/nUCYwy6lMnnEBJO22RfN QDv8l/nQu/1yZ9XmWm8n4WxrV/ViDvITMQ6/7wkIb16wb2Hfei6wvAx16lEDj4Mb 7bTSi5VzJKz9YprUYjcOL1qC88OOEYPuXS9wf6ViZf109N59VUoSWAfqVUOzrBC9 ziE8RyGPJp7/iDsbtErILslWEZiVdc4rzFx6j2J5qDtU84eEnK76ZrpecAqpdtWi 3M7Sax6+ckik1e5AorapEDtBJDcMYQDMgbpKZffZUjpyYfxCEYoq/tEPFQjR4J52 Gov+kYrThPT2LQXnQ/j0n2np8kc8sigph2AWMW8eNOSoeA91G51kCsRqlN0w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1725350374; x=1725436774; bh=AlHu/o+VwlYfqBj/TaxcBEBlxisQ iunNmFFwy9zxVZ4=; b=orUcumgJY4A8aeyd+2ms7dvmhe+0om1RacHxNS4RcxR/ wAP/6vmXc/4Eyz3xktDojAjSl1Ytr9UvomuJYqp8nKDUXuWuiebxLMx4tQTI9d4m RGW5yioUc387YQmnKUkk4ndT9LKK5tBtVuVWTzuiN2DVzCv7ToI1RFFgvHVsMOKp crBXKeg3AkeBjpryxFOqQ/Wh0SuP+HsZZyPe0W8UIjsGi+rOC0o4JrareVERii76 p2GKN31zy3v++NbE5pbmJvF0p3Rnul5Op4mG3wU0hHFpYSHPOrH7QgEr6AO/kFeE zAmPWq9bitYNhN6pKCeZZbaMklcQWlaDc21GcTu68Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehgedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeet leeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehnrghthhgrnhgusghoshhsrghrthesghhmrghilhdrtghomhdp rhgtphhtthhopegurghvihgurdhgrdhjohhhnhhsthhonhesghhmrghilhdrtghomhdprh gtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhq lhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Sep 2024 03:59:32 -0400 (EDT) Date: Tue, 3 Sep 2024 16:59:18 +0900 From: Michael Paquier To: Nathan Bossart Cc: "David G. Johnston" , Postgres hackers Subject: Re: Partitioned tables and [un]loggedness Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ZFkFdjW3fjWqcVd1" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ZFkFdjW3fjWqcVd1 Content-Type: multipart/mixed; boundary="rnZniTnZrxzBO4ae" Content-Disposition: inline --rnZniTnZrxzBO4ae Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 02, 2024 at 08:35:15PM -0500, Nathan Bossart wrote: > On Tue, Sep 03, 2024 at 09:22:58AM +0900, Michael Paquier wrote: >> Okay. This is going to be disruptive if we do nothing about pg_dump, >> unfortunately. How about tweaking dumpTableSchema() so as we'd never >> issue UNLOGGED for a partitioned table? We could filter that out as >> there is tbinfo->relkind. >=20 > That's roughly what I had in mind. An idea is attached. The pgbench bit was unexpected. -- Michael --rnZniTnZrxzBO4ae Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="unlogged-part-v3.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablec= mds.c index b3cc6f8f69..b1cc635498 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -728,6 +728,12 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid own= erId, else partitioned =3D false; =20 + if (relkind =3D=3D RELKIND_PARTITIONED_TABLE && + stmt->relation->relpersistence =3D=3D RELPERSISTENCE_UNLOGGED) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("partitioned tables cannot be unlogged"))); + /* * Look up the namespace in which we are supposed to create the relation, * check we have permission to create there, lock it against concurrent diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index dacb033e98..c60d2994f2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15896,8 +15896,13 @@ dumpTableSchema(Archive *fout, const TableInfo *tb= info) binary_upgrade_set_pg_class_oids(fout, q, tbinfo->dobj.catId.oid); =20 + /* + * PostgreSQL 18 has disabled UNLOGGED for partitioned tables, so + * ignore it when dumping if it was set in this case. + */ appendPQExpBuffer(q, "CREATE %s%s %s", - tbinfo->relpersistence =3D=3D RELPERSISTENCE_UNLOGGED ? + tbinfo->relpersistence =3D=3D RELPERSISTENCE_UNLOGGED && + tbinfo->relkind !=3D RELKIND_PARTITIONED_TABLE ? "UNLOGGED " : "", reltypename, qualrelname); diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 61618f2e18..dc4d7408cd 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -4865,7 +4865,7 @@ initCreateTables(PGconn *con) =20 /* Construct new create table statement. */ printfPQExpBuffer(&query, "create%s table %s(%s)", - unlogged_tables ? " unlogged" : "", + unlogged_tables && partition_method =3D=3D PART_NONE ? " unlogged"= : "", ddl->table, (scale >=3D SCALE_32BIT_THRESHOLD) ? ddl->bigcols : ddl->smcols); =20 diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/= expected/create_table.out index 284a7fb85c..2654891524 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -50,6 +50,8 @@ ERROR: cannot create temporary relation in non-temporary= schema LINE 1: CREATE TEMP TABLE public.temp_to_perm (a int primary key); ^ DROP TABLE unlogged1, public.unlogged2; +CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a); -- fail +ERROR: partitioned tables cannot be unlogged CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind =3D 'r'; CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind =3D 'r'; ERROR: relation "as_select1" already exists diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/c= reate_table.sql index 1fd4cbfa7e..5dbb25a092 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -30,6 +30,8 @@ CREATE TEMP TABLE pg_temp.doubly_temp (a int primary key)= ; -- also OK CREATE TEMP TABLE public.temp_to_perm (a int primary key); -- not OK DROP TABLE unlogged1, public.unlogged2; =20 +CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a); -- fail + CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind =3D 'r'; CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind =3D 'r'; CREATE TABLE IF NOT EXISTS as_select1 AS SELECT * FROM pg_class WHERE relk= ind =3D 'r'; diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_t= able.sgml index 93b3f664f2..0859afd75e 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -220,6 +220,10 @@ WITH ( MODULUS numeri= c_literal, REM If this is specified, any sequences created together with the unlogg= ed table (for identity or serial columns) are also created as unlogged. + + + This option is not supported for partitioned tables. + =20 --rnZniTnZrxzBO4ae-- --ZFkFdjW3fjWqcVd1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmbWwdYACgkQnvQgOdby QH1WuhAAqo14I+/ssqS1eU1gKKa/RN/PfShvwUnIj0ZHmWNxGomWyYXerW5Whl4u +ImAbpc7slnwltVcDFZJau21JL5OyrTFvOhiMDPsoyQc5w9wJ9Bn4RWnWKoA+4Fp pqCd7egxkXO2W9fooADJqA6FENt7qqATaavaImnrxoSxwoj8oL12edplfJa6xPGa 5cVdSdV8qroPQL2PydT2fexP50m3ghvOx9Y1N86BxoICPWz1j1Oor2Ih9FwOocai I3RurvH+PE0l+yMaCO+cr3fm6xYYYr/jYnlUnUN+IcJPm2lRpV6h9KNtB3G5bChq XbDb5QAzp1IDGKMc6kmLDFVUmIrHL9Ljv/RiVq3484oMV509MT2V2kB5djdtvlaf 3TccCyl6vP0i5Wxo+xGOnzBbB1wtVWuP7K7DAKgDcXHWGiZTpOSytspz0KLahF/k TG9dpDB+GSKUhy3jRDS6tNXz43mrKT2vh9Q8mpBnPMMLM0iXL08t5xOuU2qIsiDu M8t6W4NqAQ8ulsBDpIds6sgoNJ9p4SLXWyrtKn1WW+5RZ46tsIiSdtJMddg5hxbs J+PqK0tXA8AIY6RVK50nNuExxY1c60XI+tMtP7a1sZcy0eOHD2F7btLeGHon7guM kxVfMx1EBXAMv2b0kPvmtUUjY0tRSC660W+JZ0tSgmrPtn9p0sQ= =GpTi -----END PGP SIGNATURE----- --ZFkFdjW3fjWqcVd1--