Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2bab2d

Browse files
committed
Remove support for unlogged on partitioned tables
The following commands were allowed on partitioned tables, withdifferent effects:1) ALTER TABLE SET [UN]LOGGED did not issue an error, and did not updatepg_class.relpersistence.2) CREATE UNLOGGED TABLE was working with pg_class.relpersistence markedas initially defined, but partitions did not inherit the UNLOGGEDproperty, which was confusing.This commit causes the commands mentioned above to fail for partitionedtables, instead.pg_dump is tweaked so as partitioned tables marked as UNLOGGED ignorethe option when dumped from older server versions. pgbench needs atweak for --unlogged and --partitions=N to ignore the UNLOGGED option onthe partitioned tables created, its partitions still being unlogged.Author: Michael PaquierReviewed-by: Nathan BossartDiscussion:https://postgr.es/m/ZiiyGFTBNkqcMQi_@paquier.xyz
1 parent554d3a1 commite2bab2d

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

‎doc/src/sgml/ref/alter_table.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
797797
(for identity or serial columns). However, it is also possible to
798798
change the persistence of such sequences separately.
799799
</para>
800+
801+
<para>
802+
This form is not supported for partitioned tables.
803+
</para>
800804
</listitem>
801805
</varlistentry>
802806

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
220220
If this is specified, any sequences created together with the unlogged
221221
table (for identity or serial columns) are also created as unlogged.
222222
</para>
223+
224+
<para>
225+
This form is not supported for partitioned tables.
226+
</para>
223227
</listitem>
224228
</varlistentry>
225229

‎src/backend/commands/tablecmds.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,12 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
734734
else
735735
partitioned = false;
736736

737+
if (relkind == RELKIND_PARTITIONED_TABLE &&
738+
stmt->relation->relpersistence == RELPERSISTENCE_UNLOGGED)
739+
ereport(ERROR,
740+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
741+
errmsg("partitioned tables cannot be unlogged")));
742+
737743
/*
738744
* Look up the namespace in which we are supposed to create the relation,
739745
* check we have permission to create there, lock it against concurrent
@@ -4993,8 +4999,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
49934999
break;
49945000
case AT_SetLogged:/* SET LOGGED */
49955001
case AT_SetUnLogged:/* SET UNLOGGED */
4996-
ATSimplePermissions(cmd->subtype, rel,
4997-
ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_SEQUENCE);
5002+
ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_SEQUENCE);
49985003
if (tab->chgPersistence)
49995004
ereport(ERROR,
50005005
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

‎src/bin/pg_dump/pg_dump.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15915,8 +15915,13 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
1591515915
binary_upgrade_set_pg_class_oids(fout, q,
1591615916
tbinfo->dobj.catId.oid);
1591715917

15918+
/*
15919+
* PostgreSQL 18 has disabled UNLOGGED for partitioned tables, so
15920+
* ignore it when dumping if it was set in this case.
15921+
*/
1591815922
appendPQExpBuffer(q, "CREATE %s%s %s",
15919-
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
15923+
(tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED &&
15924+
tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ?
1592015925
"UNLOGGED " : "",
1592115926
reltypename,
1592215927
qualrelname);

‎src/bin/pgbench/pgbench.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4865,7 +4865,7 @@ initCreateTables(PGconn *con)
48654865

48664866
/* Construct new create table statement. */
48674867
printfPQExpBuffer(&query,"create%s table %s(%s)",
4868-
unlogged_tables ?" unlogged" :"",
4868+
(unlogged_tables&&partition_method==PART_NONE) ?" unlogged" :"",
48694869
ddl->table,
48704870
(scale >=SCALE_32BIT_THRESHOLD) ?ddl->bigcols :ddl->smcols);
48714871

‎src/test/regress/expected/create_table.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ ERROR: cannot create temporary relation in non-temporary schema
5050
LINE 1: CREATE TEMP TABLE public.temp_to_perm (a int primary key);
5151
^
5252
DROP TABLE unlogged1, public.unlogged2;
53+
CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a); -- fail
54+
ERROR: partitioned tables cannot be unlogged
55+
CREATE TABLE unlogged1 (a int) PARTITION BY RANGE (a); -- ok
56+
ALTER TABLE unlogged1 SET LOGGED; -- fails
57+
ERROR: ALTER action SET LOGGED cannot be performed on relation "unlogged1"
58+
DETAIL: This operation is not supported for partitioned tables.
59+
ALTER TABLE unlogged1 SET UNLOGGED; -- fails
60+
ERROR: ALTER action SET UNLOGGED cannot be performed on relation "unlogged1"
61+
DETAIL: This operation is not supported for partitioned tables.
62+
DROP TABLE unlogged1;
5363
CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind = 'r';
5464
CREATE TABLE as_select1 AS SELECT * FROM pg_class WHERE relkind = 'r';
5565
ERROR: relation "as_select1" already exists

‎src/test/regress/sql/create_table.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ CREATE TEMP TABLE pg_temp.doubly_temp (a int primary key);-- also OK
3030
CREATE TEMP TABLEpublic.temp_to_perm (aintprimary key);-- not OK
3131
DROPTABLE unlogged1,public.unlogged2;
3232

33+
CREATE UNLOGGED TABLE unlogged1 (aint) PARTITION BY RANGE (a);-- fail
34+
CREATETABLEunlogged1 (aint) PARTITION BY RANGE (a);-- ok
35+
ALTERTABLE unlogged1SET LOGGED;-- fails
36+
ALTERTABLE unlogged1SET UNLOGGED;-- fails
37+
DROPTABLE unlogged1;
38+
3339
CREATETABLEas_select1ASSELECT*FROM pg_classWHERE relkind='r';
3440
CREATETABLEas_select1ASSELECT*FROM pg_classWHERE relkind='r';
3541
CREATETABLEIF NOT EXISTS as_select1ASSELECT*FROM pg_classWHERE relkind='r';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp