pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedREPACK (CONCURRENTLY) doesn't check the table AM
12+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2026-09-08 e8636f2bed fe7b607234 Restrict REPACK (CONCURRENTLY) to the heap access method.
* REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 16:23 Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Nathan Bossart @ 2026-08-27 16:23 UTC (permalink / raw)
To: pgsql-hackers; +Cc: alvherre@kurilemu.de
REPACK (CONCURRENTLY) replays changes by decoding them from WAL, so it
needs the table AM to be logically decodable, but
check_concurrent_repack_requirements() doesn't check that. Should it be
restricted to heap for v19?
--
nathan
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 18:59 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-08-27 18:59 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: pgsql-hackers; alvherre@kurilemu.de
Hi,
On Thu, Aug 27, 2026 at 9:23 AM Nathan Bossart <nathandbossart@gmail.com> wrote:
>
> REPACK (CONCURRENTLY) replays changes by decoding them from WAL, so it
> needs the table AM to be logically decodable, but
> check_concurrent_repack_requirements() doesn't check that. Should it be
> restricted to heap for v19?
Logical decoding doesn't check the table AM type, but goes ahead and
decodes the WAL records (for that matter, none of CLUSTER, VACUUM
FULL, and REPACK have checks on table AM. They hand off at some point
to the table AM layer). I'm not sure if gating it just for concurrent
repack is the right choice. Is it that we want to have it just for
concurrent repack since it's new code with a new logical decoding
plugin and we want some field reports of needing it for other table
AMs?
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 19:16 Nathan Bossart <nathandbossart@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Nathan Bossart @ 2026-08-27 19:16 UTC (permalink / raw)
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: pgsql-hackers; alvherre@kurilemu.de
On Thu, Aug 27, 2026 at 11:59:10AM -0700, Bharath Rupireddy wrote:
> On Thu, Aug 27, 2026 at 9:23 AM Nathan Bossart <nathandbossart@gmail.com> wrote:
>> REPACK (CONCURRENTLY) replays changes by decoding them from WAL, so it
>> needs the table AM to be logically decodable, but
>> check_concurrent_repack_requirements() doesn't check that. Should it be
>> restricted to heap for v19?
>
> Logical decoding doesn't check the table AM type, but goes ahead and
> decodes the WAL records (for that matter, none of CLUSTER, VACUUM
> FULL, and REPACK have checks on table AM. They hand off at some point
> to the table AM layer). I'm not sure if gating it just for concurrent
> repack is the right choice. Is it that we want to have it just for
> concurrent repack since it's new code with a new logical decoding
> plugin and we want some field reports of needing it for other table
> AMs?
If the other commands are similarly broken, then perhaps this isn't a valid
open item for v19. But IIUC concurrent repack is the only one of the
commands you listed that depends on logical decoding, and if the table AM
doesn't support that, then it won't work properly.
--
nathan
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 19:48 Masahiko Sawada <sawada.mshk@gmail.com>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Masahiko Sawada @ 2026-08-27 19:48 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
On Thu, Aug 27, 2026 at 12:16 PM Nathan Bossart
<nathandbossart@gmail.com> wrote:
>
> On Thu, Aug 27, 2026 at 11:59:10AM -0700, Bharath Rupireddy wrote:
> > On Thu, Aug 27, 2026 at 9:23 AM Nathan Bossart <nathandbossart@gmail.com> wrote:
> >> REPACK (CONCURRENTLY) replays changes by decoding them from WAL, so it
> >> needs the table AM to be logically decodable, but
> >> check_concurrent_repack_requirements() doesn't check that. Should it be
> >> restricted to heap for v19?
> >
> > Logical decoding doesn't check the table AM type, but goes ahead and
> > decodes the WAL records (for that matter, none of CLUSTER, VACUUM
> > FULL, and REPACK have checks on table AM. They hand off at some point
> > to the table AM layer). I'm not sure if gating it just for concurrent
> > repack is the right choice. Is it that we want to have it just for
> > concurrent repack since it's new code with a new logical decoding
> > plugin and we want some field reports of needing it for other table
> > AMs?
>
> If the other commands are similarly broken, then perhaps this isn't a valid
> open item for v19. But IIUC concurrent repack is the only one of the
> commands you listed that depends on logical decoding, and if the table AM
> doesn't support that, then it won't work properly.
If the table AM doesn't support logical decoding, concurrent repack
would silently lose some table data as it misses the changes
happened during the rewrites. I think we should have the check for it.
One idea would be to have a new table AM callback returning true if
the table AM supports concurrent repack (i.e., its rmgr provides
rm_decode callback), but I think it's not the right time to introduce
a new table AM callback. So restricting it to heap for v19 seems fine
to me.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 19:57 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Masahiko Sawada <sawada.mshk@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-08-27 19:57 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
Hi,
On Thu, Aug 27, 2026 at 12:49 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> On Thu, Aug 27, 2026 at 12:16 PM Nathan Bossart
> <nathandbossart@gmail.com> wrote:
> >
> > On Thu, Aug 27, 2026 at 11:59:10AM -0700, Bharath Rupireddy wrote:
> > > On Thu, Aug 27, 2026 at 9:23 AM Nathan Bossart <nathandbossart@gmail.com> wrote:
> > >> REPACK (CONCURRENTLY) replays changes by decoding them from WAL, so it
> > >> needs the table AM to be logically decodable, but
> > >> check_concurrent_repack_requirements() doesn't check that. Should it be
> > >> restricted to heap for v19?
> > >
> > > Logical decoding doesn't check the table AM type, but goes ahead and
> > > decodes the WAL records (for that matter, none of CLUSTER, VACUUM
> > > FULL, and REPACK have checks on table AM. They hand off at some point
> > > to the table AM layer). I'm not sure if gating it just for concurrent
> > > repack is the right choice. Is it that we want to have it just for
> > > concurrent repack since it's new code with a new logical decoding
> > > plugin and we want some field reports of needing it for other table
> > > AMs?
> >
> > If the other commands are similarly broken, then perhaps this isn't a valid
> > open item for v19. But IIUC concurrent repack is the only one of the
> > commands you listed that depends on logical decoding, and if the table AM
> > doesn't support that, then it won't work properly.
>
> If the table AM doesn't support logical decoding, concurrent repack
> would silently lose some table data as it misses the changes
> happened during the rewrites.
Yes, that's correct. I came to the same conclusion.
> I think we should have the check for it.
> One idea would be to have a new table AM callback returning true if
> the table AM supports concurrent repack (i.e., its rmgr provides
> rm_decode callback), but I think it's not the right time to introduce
> a new table AM callback.
Agreed. Adding a new table AM callback needs consensus and is time
consuming. Perhaps we can try for HEAD based on field reports that
require the concurrent repack feature for non-heap table AMs.
> So restricting it to heap for v19 seems fine
> to me.
+1. I will send a patch soon.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 20:45 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-08-27 20:45 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
Hi,
On Thu, Aug 27, 2026 at 12:57 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> > If the table AM doesn't support logical decoding, concurrent repack
> > would silently lose some table data as it misses the changes
> > happened during the rewrites.
>
> Yes, that's correct. I came to the same conclusion.
>
> > I think we should have the check for it.
> > One idea would be to have a new table AM callback returning true if
> > the table AM supports concurrent repack (i.e., its rmgr provides
> > rm_decode callback), but I think it's not the right time to introduce
> > a new table AM callback.
>
> Agreed. Adding a new table AM callback needs consensus and is time
> consuming. Perhaps we can try for HEAD based on field reports that
> require the concurrent repack feature for non-heap table AMs.
>
> > So restricting it to heap for v19 seems fine
> > to me.
>
> +1. I will send a patch soon.
Please find the attached patch. I didn't add a test, I don't think we need one.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Attachments:
v1-0001-Restrict-concurrent-repack-to-the-heap-access-met.patch (application/x-patch, 2.4K) download
From 72917b6cd02313e4ffb31e256914d5ad3db43013 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Thu, 27 Aug 2026 20:16:09 +0000
Subject: [PATCH v1] Restrict concurrent repack to the heap access method.
Concurrent repack (28d534e2ae0) replays the data changes made
during the table rewrite by decoding them from WAL, which only
works if the table's access method supports logical decoding.
check_concurrent_repack_requirements() didn't check for that.
For an access method that doesn't support it, the concurrent
changes are never decoded and are silently lost from the
rewritten table.
Fix by erroring out for tables that use a non-heap access method.
Recognizing logical-decoding support properly would need a new
table AM callback, which is more than this open item warrants, so
restrict it to heap for now.
Backpatch to v19, where concurrent repack was introduced.
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/apBkixO4xAGFoiT3%40nathan
Backpatch-through: 19
---
src/backend/commands/repack.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 477c86b2ba6..05c0662a510 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -877,6 +877,20 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
errdetail("%s requires \"wal_level\" to be set to \"replica\" or higher.",
"REPACK (CONCURRENTLY)"));
+ /*
+ * A table AM that doesn't support logical decoding would cause concurrent
+ * repack to silently lose the changes made during the rewrite. Detecting
+ * such support cleanly would need a new table AM callback, so for now
+ * just restrict the command to heap.
+ */
+ if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot execute %s on relation \"%s\"",
+ "REPACK (CONCURRENTLY)", RelationGetRelationName(rel)),
+ errhint("%s is only supported for the \"heap\" access method.",
+ "REPACK (CONCURRENTLY)"));
+
/* Data changes in system relations are not logically decoded. */
if (IsCatalogRelation(rel))
ereport(ERROR,
--
2.47.3
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-08-27 22:51 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-08-27 22:51 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
Hi,
On Thu, Aug 27, 2026 at 1:45 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> Hi,
>
> On Thu, Aug 27, 2026 at 12:57 PM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
> >
> > > If the table AM doesn't support logical decoding, concurrent repack
> > > would silently lose some table data as it misses the changes
> > > happened during the rewrites.
> >
> > Yes, that's correct. I came to the same conclusion.
> >
> > > I think we should have the check for it.
> > > One idea would be to have a new table AM callback returning true if
> > > the table AM supports concurrent repack (i.e., its rmgr provides
> > > rm_decode callback), but I think it's not the right time to introduce
> > > a new table AM callback.
> >
> > Agreed. Adding a new table AM callback needs consensus and is time
> > consuming. Perhaps we can try for HEAD based on field reports that
> > require the concurrent repack feature for non-heap table AMs.
> >
> > > So restricting it to heap for v19 seems fine
> > > to me.
> >
> > +1. I will send a patch soon.
>
> Please find the attached patch. I didn't add a test, I don't think we need one.
Added the limitation to the repack docs. Please find the attached v2
patch. Sorry for the noise.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Attachments:
v2-0001-Restrict-concurrent-repack-to-the-heap-access-met.patch (application/octet-stream, 3.0K) download
From 39985bf011f4c82f4a523bccc3a100e6cba5cd82 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Thu, 27 Aug 2026 20:16:09 +0000
Subject: [PATCH v2] Restrict concurrent repack to the heap access method.
Concurrent repack (28d534e2ae0) replays the data changes made
during the table rewrite by decoding them from WAL, which only
works if the table's access method supports logical decoding.
check_concurrent_repack_requirements() didn't check for that.
For an access method that doesn't support it, the concurrent
changes are never decoded and are silently lost from the
rewritten table.
Fix by erroring out for tables that use a non-heap access method,
and document the limitation. Recognizing logical-decoding support
properly would need a new table AM callback, which is more than
this open item warrants, so restrict it to heap for now.
Backpatch to v19, where concurrent repack was introduced.
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/apBkixO4xAGFoiT3%40nathan
Backpatch-through: 19
---
doc/src/sgml/ref/repack.sgml | 6 ++++++
src/backend/commands/repack.c | 14 ++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/doc/src/sgml/ref/repack.sgml b/doc/src/sgml/ref/repack.sgml
index 0cb72b6b289..0496cd24af1 100644
--- a/doc/src/sgml/ref/repack.sgml
+++ b/doc/src/sgml/ref/repack.sgml
@@ -285,6 +285,12 @@ REPACK [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] USING
</para>
</listitem>
+ <listitem>
+ <para>
+ The table uses an access method other than <literal>heap</literal>.
+ </para>
+ </listitem>
+
<listitem>
<para>
<command>REPACK</command> is executed inside a transaction block.
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 477c86b2ba6..05c0662a510 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -877,6 +877,20 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
errdetail("%s requires \"wal_level\" to be set to \"replica\" or higher.",
"REPACK (CONCURRENTLY)"));
+ /*
+ * A table AM that doesn't support logical decoding would cause concurrent
+ * repack to silently lose the changes made during the rewrite. Detecting
+ * such support cleanly would need a new table AM callback, so for now
+ * just restrict the command to heap.
+ */
+ if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot execute %s on relation \"%s\"",
+ "REPACK (CONCURRENTLY)", RelationGetRelationName(rel)),
+ errhint("%s is only supported for the \"heap\" access method.",
+ "REPACK (CONCURRENTLY)"));
+
/* Data changes in system relations are not logically decoded. */
if (IsCatalogRelation(rel))
ereport(ERROR,
--
2.47.3
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-09-01 03:45 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-09-01 03:45 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
Hi,
On Thu, Aug 27, 2026 at 3:51 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> > On Thu, Aug 27, 2026 at 12:57 PM Bharath Rupireddy
> > <bharath.rupireddyforpostgres@gmail.com> wrote:
> > >
> > > > If the table AM doesn't support logical decoding, concurrent repack
> > > > would silently lose some table data as it misses the changes
> > > > happened during the rewrites.
> > >
> > > Yes, that's correct. I came to the same conclusion.
Please find the attached v3 patch with a test added similar to other
restricted error cases. Sorry for the noise.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Attachments:
v3-0001-Restrict-concurrent-repack-to-the-heap-access-met.patch (application/octet-stream, 4.8K) download
From 98134b1edf9ac81868969c88ff3f76c443cd0ae5 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Tue, 1 Sep 2026 03:29:27 +0000
Subject: [PATCH v3] Restrict concurrent repack to the heap access method.
Concurrent repack (28d534e2ae0) replays the data changes made
during the table rewrite by decoding them from WAL, which only
works if the table's access method supports logical decoding.
check_concurrent_repack_requirements() didn't check for that.
For an access method that doesn't support it, the concurrent
changes are never decoded and are silently lost from the
rewritten table.
Fix by erroring out for tables that use a non-heap access method,
and document the limitation. Recognizing logical-decoding support
properly would need a new table AM callback, which is more than
this open item warrants, so restrict it to heap for now.
Backpatch to v19, where concurrent repack was introduced.
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/apBkixO4xAGFoiT3%40nathan
Backpatch-through: 19
---
contrib/test_decoding/expected/repack.out | 8 ++++++++
contrib/test_decoding/sql/repack.sql | 7 +++++++
doc/src/sgml/ref/repack.sgml | 6 ++++++
src/backend/commands/repack.c | 14 ++++++++++++++
4 files changed, 35 insertions(+)
diff --git a/contrib/test_decoding/expected/repack.out b/contrib/test_decoding/expected/repack.out
index 5ddc63238c5..7872d567070 100644
--- a/contrib/test_decoding/expected/repack.out
+++ b/contrib/test_decoding/expected/repack.out
@@ -57,6 +57,14 @@ CREATE TABLE clstrpart (a int) PARTITION BY RANGE (a);
REPACK (CONCURRENTLY) clstrpart;
ERROR: REPACK (CONCURRENTLY) is not supported for partitioned tables
HINT: Consider running the command on individual partitions.
+-- Only supported for the heap access method
+CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE repack_conc_heap2 (i int) USING heap2;
+REPACK (CONCURRENTLY) repack_conc_heap2;
+ERROR: cannot execute REPACK (CONCURRENTLY) on relation "repack_conc_heap2"
+HINT: REPACK (CONCURRENTLY) is only supported for the "heap" access method.
+DROP TABLE repack_conc_heap2;
+DROP ACCESS METHOD heap2;
-- Disallowed in catalogs
REPACK (CONCURRENTLY) pg_class;
ERROR: cannot execute REPACK (CONCURRENTLY) on relation "pg_class"
diff --git a/contrib/test_decoding/sql/repack.sql b/contrib/test_decoding/sql/repack.sql
index f461f5479f4..ce8ed6c3b26 100644
--- a/contrib/test_decoding/sql/repack.sql
+++ b/contrib/test_decoding/sql/repack.sql
@@ -39,6 +39,13 @@ DROP TABLE rpk_missing;
CREATE TABLE clstrpart (a int) PARTITION BY RANGE (a);
REPACK (CONCURRENTLY) clstrpart;
+-- Only supported for the heap access method
+CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE repack_conc_heap2 (i int) USING heap2;
+REPACK (CONCURRENTLY) repack_conc_heap2;
+DROP TABLE repack_conc_heap2;
+DROP ACCESS METHOD heap2;
+
-- Disallowed in catalogs
REPACK (CONCURRENTLY) pg_class;
diff --git a/doc/src/sgml/ref/repack.sgml b/doc/src/sgml/ref/repack.sgml
index 0cb72b6b289..0496cd24af1 100644
--- a/doc/src/sgml/ref/repack.sgml
+++ b/doc/src/sgml/ref/repack.sgml
@@ -285,6 +285,12 @@ REPACK [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] USING
</para>
</listitem>
+ <listitem>
+ <para>
+ The table uses an access method other than <literal>heap</literal>.
+ </para>
+ </listitem>
+
<listitem>
<para>
<command>REPACK</command> is executed inside a transaction block.
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 477c86b2ba6..05c0662a510 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -877,6 +877,20 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
errdetail("%s requires \"wal_level\" to be set to \"replica\" or higher.",
"REPACK (CONCURRENTLY)"));
+ /*
+ * A table AM that doesn't support logical decoding would cause concurrent
+ * repack to silently lose the changes made during the rewrite. Detecting
+ * such support cleanly would need a new table AM callback, so for now
+ * just restrict the command to heap.
+ */
+ if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot execute %s on relation \"%s\"",
+ "REPACK (CONCURRENTLY)", RelationGetRelationName(rel)),
+ errhint("%s is only supported for the \"heap\" access method.",
+ "REPACK (CONCURRENTLY)"));
+
/* Data changes in system relations are not logically decoded. */
if (IsCatalogRelation(rel))
ereport(ERROR,
--
2.47.3
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-09-04 21:04 Masahiko Sawada <sawada.mshk@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Masahiko Sawada @ 2026-09-04 21:04 UTC (permalink / raw)
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
On Mon, Aug 31, 2026 at 8:46 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> Hi,
>
> On Thu, Aug 27, 2026 at 3:51 PM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
> >
> > > On Thu, Aug 27, 2026 at 12:57 PM Bharath Rupireddy
> > > <bharath.rupireddyforpostgres@gmail.com> wrote:
> > > >
> > > > > If the table AM doesn't support logical decoding, concurrent repack
> > > > > would silently lose some table data as it misses the changes
> > > > > happened during the rewrites.
> > > >
> > > > Yes, that's correct. I came to the same conclusion.
>
> Please find the attached v3 patch with a test added similar to other
> restricted error cases. Sorry for the noise.
I've looked at the patch and have one comment:
+ if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
Probably it's better to use GetHeapamTableAmRoutine() instead of using
heap AM oid. It would allow the following use case the patch adds in
the regression tests:
+CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler;
+CREATE TABLE repack_conc_heap2 (i int) USING heap2;
+REPACK (CONCURRENTLY) repack_conc_heap2;
REPACK'ing on such a table technically works fine. It's unlikely to
drop the check so I think we can add the check without regression
tests.
I attached the updated patch. Please review it.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
Attachments:
v4-0001-Restrict-REPACK-CONCURRENTLY-to-the-heap-access-m.patch (text/x-patch, 2.7K) download
From 9b94ac46635753e0dd26787416865bb00aa397a4 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Tue, 1 Sep 2026 03:29:27 +0000
Subject: [PATCH v4] Restrict REPACK (CONCURRENTLY) to the heap access method.
REPACK (CONCURRENTLY) didn't check the table AM of the table being
repacked, so if the table AM doesn't support logical decoding, the
concurrent changes are never decoded and are silently lost from the
rewritten table.
Fix by erroring out for tables that use a non-heap access method.
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/apBkixO4xAGFoiT3@nathan
Backpatch-through: 19
---
doc/src/sgml/ref/repack.sgml | 6 ++++++
src/backend/commands/repack.c | 15 +++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/doc/src/sgml/ref/repack.sgml b/doc/src/sgml/ref/repack.sgml
index 0cb72b6b289..0496cd24af1 100644
--- a/doc/src/sgml/ref/repack.sgml
+++ b/doc/src/sgml/ref/repack.sgml
@@ -285,6 +285,12 @@ REPACK [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] USING
</para>
</listitem>
+ <listitem>
+ <para>
+ The table uses an access method other than <literal>heap</literal>.
+ </para>
+ </listitem>
+
<listitem>
<para>
<command>REPACK</command> is executed inside a transaction block.
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 477c86b2ba6..91e46532132 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -877,6 +877,21 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
errdetail("%s requires \"wal_level\" to be set to \"replica\" or higher.",
"REPACK (CONCURRENTLY)"));
+ /*
+ * A table AM that doesn't support logical decoding would cause REPACK
+ * (CONCURRENTLY) to silently lose the changes made during the rewrite.
+ * Nothing in TableAmRoutine tells us whether it does, so for now restrict
+ * to heap. Check the routine rather than the AM OID, so that an AM
+ * reusing the heap handler still works.
+ */
+ if (rel->rd_tableam != GetHeapamTableAmRoutine())
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot execute %s on relation \"%s\"",
+ "REPACK (CONCURRENTLY)", RelationGetRelationName(rel)),
+ errhint("%s is only supported for the \"heap\" access method.",
+ "REPACK (CONCURRENTLY)"));
+
/* Data changes in system relations are not logically decoded. */
if (IsCatalogRelation(rel))
ereport(ERROR,
--
2.55.0
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-09-04 23:13 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Masahiko Sawada <sawada.mshk@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-09-04 23:13 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
Hi,
On Fri, Sep 4, 2026 at 2:05 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> I've looked at the patch and have one comment:
Thanks for reviewing it.
> + if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
>
> Probably it's better to use GetHeapamTableAmRoutine() instead of using
> heap AM oid. It would allow the following use case the patch adds in
> the regression tests:
> +CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler;
> +CREATE TABLE repack_conc_heap2 (i int) USING heap2;
> +REPACK (CONCURRENTLY) repack_conc_heap2;
>
> REPACK'ing on such a table technically works fine. It's unlikely to
> drop the check so I think we can add the check without regression
> tests.
That works for me. If a table AM that just copies the heap AM handler
as-is works with repack, that is fine. If a table AM that copies the
heap AM handler but overwrites one or more functions errors out with
repack, that still serves the purpose. Also, I am fine without a test
for this because we don't have another table AM in the core and all
tests rely on reusing the same heap AM handler.
> I attached the updated patch. Please review it.
The v4 patch looks good to me. pgindent and tests are happy.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-09-08 17:23 Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 1 reply; 12+ messages in thread
From: Bharath Rupireddy @ 2026-09-08 17:23 UTC (permalink / raw)
To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
Hi,
On Fri, Sep 4, 2026 at 4:13 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> > I attached the updated patch. Please review it.
>
> The v4 patch looks good to me. pgindent and tests are happy.
Please find the attached v5 patch containing detail instead of hint
and also consistent wording as discussed here:
https://postgr.es/m/CALj2ACXyTPZEcGeKgHQjtSCScOOLpHNhAdH3Cn2T48aXg2LZfA%40mail.gmail.com
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Attachments:
v5-0001-Restrict-REPACK-CONCURRENTLY-to-the-heap-access-m.patch (application/octet-stream, 2.7K) download
From d46287b2badfb7784b1d609a512fa10cbdee2752 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Tue, 8 Sep 2026 17:17:24 +0000
Subject: [PATCH v5] Restrict REPACK (CONCURRENTLY) to the heap access method.
REPACK (CONCURRENTLY) didn't check the table AM of the table being
repacked, so if the table AM doesn't support logical decoding, the
concurrent changes are never decoded and are silently lost from the
rewritten table.
Fix by erroring out for tables that use a non-heap access method.
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/apBkixO4xAGFoiT3@nathan
Backpatch-through: 19
---
doc/src/sgml/ref/repack.sgml | 6 ++++++
src/backend/commands/repack.c | 14 ++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/doc/src/sgml/ref/repack.sgml b/doc/src/sgml/ref/repack.sgml
index d9c7c9e6b95..3c83f529298 100644
--- a/doc/src/sgml/ref/repack.sgml
+++ b/doc/src/sgml/ref/repack.sgml
@@ -285,6 +285,12 @@ REPACK [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] USING
</para>
</listitem>
+ <listitem>
+ <para>
+ The table's access method is not <literal>heap</literal>.
+ </para>
+ </listitem>
+
<listitem>
<para>
<command>REPACK</command> is executed inside a transaction block.
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 89aa038d23d..7cba8bece9c 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -888,6 +888,20 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
errdetail("%s requires \"wal_level\" to be set to \"replica\" or higher.",
"REPACK (CONCURRENTLY)"));
+ /*
+ * A table AM that doesn't support logical decoding would cause REPACK
+ * (CONCURRENTLY) to silently lose the changes made during the rewrite.
+ * Nothing in TableAmRoutine tells us whether it does, so for now restrict
+ * to heap. Check the routine rather than the AM OID, so that an AM
+ * reusing the heap handler still works.
+ */
+ if (rel->rd_tableam != GetHeapamTableAmRoutine())
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot execute %s on relation \"%s\"",
+ "REPACK (CONCURRENTLY)", RelationGetRelationName(rel)),
+ errdetail("This operation is only supported for the \"heap\" access method."));
+
/* Data changes in system relations are not logically decoded. */
if (IsCatalogRelation(rel))
ereport(ERROR,
--
2.47.3
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: REPACK (CONCURRENTLY) doesn't check the table AM
@ 2026-09-08 18:54 Masahiko Sawada <sawada.mshk@gmail.com>
parent: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
0 siblings, 0 replies; 12+ messages in thread
From: Masahiko Sawada @ 2026-09-08 18:54 UTC (permalink / raw)
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; pgsql-hackers; alvherre@kurilemu.de
On Tue, Sep 8, 2026 at 10:24 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
>
> Hi,
>
> On Fri, Sep 4, 2026 at 4:13 PM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
> >
> > > I attached the updated patch. Please review it.
> >
> > The v4 patch looks good to me. pgindent and tests are happy.
>
> Please find the attached v5 patch containing detail instead of hint
> and also consistent wording as discussed here:
> https://postgr.es/m/CALj2ACXyTPZEcGeKgHQjtSCScOOLpHNhAdH3Cn2T48aXg2LZfA%40mail.gmail.com
Thank you for updating the patch. It looks good to me so I've pushed.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 12+ messages in thread
end of thread, other threads:[~2026-09-08 18:54 UTC | newest]
Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-27 16:23 REPACK (CONCURRENTLY) doesn't check the table AM Nathan Bossart <nathandbossart@gmail.com>
2026-08-27 18:59 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-27 19:16 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-27 19:48 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-08-27 19:57 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-27 20:45 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-08-27 22:51 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-09-01 03:45 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-09-04 21:04 ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-09-04 23:13 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-09-08 17:23 ` Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
2026-09-08 18:54 ` Masahiko Sawada <sawada.mshk@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox