public inbox for [email protected]
help / color / mirror / Atom feedFrom: Chao Li <[email protected]>
To: David G. Johnston <[email protected]>
Cc: Greg Sabino Mullane <[email protected]>
Cc: Postgres hackers <[email protected]>
Subject: Re: ALTER TABLE: warn when actions do not recurse to partitions
Date: Tue, 13 Jan 2026 12:02:54 +0800
Message-ID: <CAEoWx2kQ9aSn-0LGPKc=woj+h-HR4uBV9TL20aeM3HzLmFqgFQ@mail.gmail.com> (raw)
In-Reply-To: <CAKFQuwahxpPKT-LXGJ34BO5cVBUxFxzgNPTY8E_VW-cuNU_DkQ@mail.gmail.com>
References: <CAEoWx2=SLga-xH09Cq_PAvsHhQHrBK+V0vF821JKgzS=Bm0haA@mail.gmail.com>
<CAKFQuwZXt2dAuHFs6MtRCzfMP6YZFzssuzdW2woJBVmco=CDdQ@mail.gmail.com>
<CAEoWx2nic2MaPUEKwb0Me1iwO3LsCf8wUHm55pjqaTRgJEZpcQ@mail.gmail.com>
<CAKFQuwahxpPKT-LXGJ34BO5cVBUxFxzgNPTY8E_VW-cuNU_DkQ@mail.gmail.com>
On Tue, Jan 13, 2026 at 11:42 AM David G. Johnston <
[email protected]> wrote:
> On Monday, January 12, 2026, Chao Li <[email protected]> wrote:
>
>>
>> Now, the message is like:
>> ```
>> evantest=# alter table sensor_data replica identity full;
>> NOTICE: REPLICA IDENTITY does not apply to partitions (1 affected)
>> ALTER TABLE
>>
>
>
> If it doesn't recurse there should be no count. It would either always be
> 1, so not helpful, or if did show a partition count, beside the point. In
> the later case suppress the message if there are no partitions present.
>
The count was real. I agree that we can suppress the message when there are
no partitions. Addressed that in v3.
>
> The statement “does not apply to partitions” is also factually wrong. One
> would just need to name the partition explicitly.
>
> NOTICE: present partitions not affected
> HINT: partitions may be modified individually using separate commands
> ALTER TABLE
>
Thanks for the suggestion, I took that in v3.
PSA v3:
* Rephrased the notice message as David's suggestion.
* Removed partition count from notice message.
* If a partitioned table doesn't have any partition, then suppress the
message.
Now the command outputs look like:
```
evantest=# alter table sensor_data replica identity full;
NOTICE: present partitions not affected
HINT: partitions may be modified individually using separate commands
ALTER TABLE
```
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
[application/octet-stream] v3-0001-Add-notice-when-ALTER-TABLE-REPLICA-IDENTITY-does.patch (4.0K, 3-v3-0001-Add-notice-when-ALTER-TABLE-REPLICA-IDENTITY-does.patch)
download | inline diff:
From 6dd5cb5ff078e03944f180bac57e9432e880700e Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Mon, 12 Jan 2026 16:56:58 +0800
Subject: [PATCH v3] Add notice when ALTER TABLE REPLICA IDENTITY does not
recurse
ALTER TABLE ... REPLICA IDENTITY accepts a recursive form on
partitioned tables, but the change is applied only to the partitioned
table itself and does not propagate to child partitions.
Previously this case was silently accepted, which could mislead users
into assuming that the setting would recurse. Add a notice when
recursion is requested on a partitioned table to make the behavior
explicit and avoid confusion.
This change does not alter semantics; it only provides user-visible
feedback. Similar notices may be added for other ALTER TABLE
sub-commands with non-recursive behavior in follow-up commits.
Author: Chao Li <[email protected]>
Reviewed-by: David G. Johnston <[email protected]>
Reviewed-by: Greg Sabino Mullane <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2=SLga-xH09Cq_PAvsHhQHrBK+V0vF821JKgzS=Bm0haA@mail.gmail.com
---
src/backend/commands/tablecmds.c | 33 +++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f976c0e5c7e..31ae0b9e827 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -693,7 +693,7 @@ static void drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid,
DependencyType deptype);
static ObjectAddress ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode);
static void ATExecDropOf(Relation rel, LOCKMODE lockmode);
-static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode);
+static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, bool recurse, LOCKMODE lockmode);
static void ATExecGenericOptions(Relation rel, List *options);
static void ATExecSetRowSecurity(Relation rel, bool rls);
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls);
@@ -5227,8 +5227,15 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
ATSimplePermissions(cmd->subtype, rel,
ATT_TABLE | ATT_PARTITIONED_TABLE | ATT_MATVIEW);
pass = AT_PASS_MISC;
- /* This command never recurses */
- /* No command-specific prep needed */
+
+ /*
+ * This command now doesn't recurse, but we want to notify user if
+ * recurse is set
+ *
+ * No command-specific prep needed
+ */
+ if (recurse)
+ cmd->recurse = true;
break;
case AT_EnableTrig: /* ENABLE TRIGGER variants */
case AT_EnableAlwaysTrig:
@@ -5643,7 +5650,8 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
ATExecDropOf(rel, lockmode);
break;
case AT_ReplicaIdentity:
- ATExecReplicaIdentity(rel, (ReplicaIdentityStmt *) cmd->def, lockmode);
+ ATExecReplicaIdentity(rel, (ReplicaIdentityStmt *) cmd->def,
+ cmd->recurse, lockmode);
break;
case AT_EnableRowSecurity:
ATExecSetRowSecurity(rel, true);
@@ -18515,12 +18523,27 @@ relation_mark_replica_identity(Relation rel, char ri_type, Oid indexOid,
* ALTER TABLE <name> REPLICA IDENTITY ...
*/
static void
-ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode)
+ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, bool recurse, LOCKMODE lockmode)
{
Oid indexOid;
Relation indexRel;
int key;
+ if (recurse && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+ {
+ PartitionDesc pd = RelationGetPartitionDesc(rel, true);
+ int nparts = pd->nparts;
+
+ /*
+ * The recurse flag is set, but this command does not actually
+ * recurse. Emit a NOTICE to make this behavior explicit to the user.
+ */
+ if (nparts > 0)
+ ereport(NOTICE,
+ (errmsg("present partitions not affected")),
+ errhint("partitions may be modified individually using separate commands"));
+ }
+
if (stmt->identity_type == REPLICA_IDENTITY_DEFAULT)
{
relation_mark_replica_identity(rel, stmt->identity_type, InvalidOid, true);
--
2.39.5 (Apple Git-154)
view thread (5+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: ALTER TABLE: warn when actions do not recurse to partitions
In-Reply-To: <CAEoWx2kQ9aSn-0LGPKc=woj+h-HR4uBV9TL20aeM3HzLmFqgFQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox