ALTER TABLE: warn when actions do not recurse to partitions

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: ALTER TABLE: warn when actions do not recurse to partitions
Date: 2026-01-12 09:02:19
Message-ID: CAEoWx2=SLga-xH09Cq_PAvsHhQHrBK+V0vF821JKgzS=Bm0haA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hacker,

This patch is part of a broader effort to make ALTER TABLE actions behave
more consistently with respect to partitioned tables. There has been
ongoing discussion around this area; see [1], which also links to earlier
related threads.

In short, changing ALTER TABLE semantics requires more discussion and
coordination than a single patch can realistically achieve. Before that
larger work happens, I’m following up on [1] by trying to clarify the
current behavior, both in documentation and in user-facing feedback.

This patch adds warning messages for sub-commands that appear to recurse
but in fact do not. These currently include:

* SET STATISTICS
* SET/RESET (attribute_option = value)
* ENABLE/DISABLE [ REPLICA | ALWAYS] RULE
* ENABLE/DISABLE ROW LEVEL SECURITY
* NO FORCE / FORCE ROW LEVEL SECURITY
* OWNER TO
* REPLICA IDENTITY
* SET SCHEMA

For example, if a user runs:
```
ALTER TABLE ONLY a_partitioned_table REPLICA IDENTITY FULL;
```
the semantics are clear: only the partitioned table itself is modified.

However, if the user runs the same command without ONLY:
```
ALTER TABLE a_partitioned_table REPLICA IDENTITY FULL;
```
there is potential confusion. From the command syntax alone, it is
reasonable to assume that the change would propagate to child partitions,
but in reality, it does not. Since the ALTER TABLE documentation does not
explicitly spell this out, users often need to test the behavior themselves
to be sure, which is a poor user experience.

With this patch, the command instead emits a warning such as:
```
evantest=# alter table sensor_data replica identity full;
WARNING: REPLICA IDENTITY is only applied to the partitioned table itself
ALTER TABLE
```
This makes the behavior explicit and removes the ambiguity.

For now, I’ve limited the change to REPLICA IDENTITY to see whether there
are objections to this approach. If there are none, I plan to extend the
same warning behavior to the other sub-commands listed above. After that,
users can reasonably assume that an ALTER TABLE partitioned_table
... action will recurse to child partitions unless a warning explicitly
tells them otherwise.

[1] https://postgr.es/m/59FB38EF-FA62-41B7-A082-DDA251B04F9E@gmail.com

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v1-0001-Add-warning-when-ALTER-TABLE-REPLICA-IDENTITY-doe.patch application/octet-stream 3.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Konstantin Knizhnik 2026-01-12 09:16:11 Re: global temporary table (GTT) - are there some ideas how to implement it?
Previous Message Amit Kapila 2026-01-12 08:52:24 Re: [Proposal] Adding Log File Capability to pg_createsubscriber