mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Fix error message for concurrent repack on materialized views
Previously, running REPACK (CONCURRENTLY) on a materialized view failed with a confusing "has no identity index" error. REPACK (CONCURRENTLY) replays changes decoded from WAL, but a materialized view produces none, since it cannot be modified by DML and REFRESH rewrites it through a transient heap that is not logically decoded. Fix this by reporting a clear error for materialized views upfront, alongside the existing checks for system catalogs and TOAST tables, and document the limitation. Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Kiran Kaki <itskkpg@gmail.com> Backpatch-through: 19 Discussion: https://postgr.es/m/CALj2ACXPvy4_LkQ0nHKgbZjAGK9fkDqRYUvXA3hgwxPm_X7Eng@mail.gmail.com
This commit is contained in:
@@ -87,6 +87,12 @@ REPACK (CONCURRENTLY) repack_conc_unlogged;
|
||||
ERROR: cannot execute REPACK (CONCURRENTLY) on relation "repack_conc_unlogged"
|
||||
HINT: REPACK (CONCURRENTLY) is only allowed for permanent relations.
|
||||
DROP TABLE repack_conc_unlogged;
|
||||
-- Doesn't support materialized views
|
||||
CREATE MATERIALIZED VIEW repack_conc_matview AS SELECT 1 AS i;
|
||||
REPACK (CONCURRENTLY) repack_conc_matview;
|
||||
ERROR: cannot execute REPACK (CONCURRENTLY) on relation "repack_conc_matview"
|
||||
DETAIL: This operation is not supported for materialized views.
|
||||
DROP MATERIALIZED VIEW repack_conc_matview;
|
||||
-- Doesn't support tables with REPLICA IDENTITY NOTHING, even if they have a primary key
|
||||
CREATE TABLE repack_conc_replident (i int PRIMARY KEY);
|
||||
ALTER TABLE repack_conc_replident REPLICA IDENTITY NOTHING;
|
||||
|
||||
@@ -64,6 +64,11 @@ CREATE UNLOGGED TABLE repack_conc_unlogged (i int PRIMARY KEY);
|
||||
REPACK (CONCURRENTLY) repack_conc_unlogged;
|
||||
DROP TABLE repack_conc_unlogged;
|
||||
|
||||
-- Doesn't support materialized views
|
||||
CREATE MATERIALIZED VIEW repack_conc_matview AS SELECT 1 AS i;
|
||||
REPACK (CONCURRENTLY) repack_conc_matview;
|
||||
DROP MATERIALIZED VIEW repack_conc_matview;
|
||||
|
||||
-- Doesn't support tables with REPLICA IDENTITY NOTHING, even if they have a primary key
|
||||
CREATE TABLE repack_conc_replident (i int PRIMARY KEY);
|
||||
ALTER TABLE repack_conc_replident REPLICA IDENTITY NOTHING;
|
||||
|
||||
@@ -261,6 +261,12 @@ REPACK [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] USING
|
||||
following cases:
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
The relation is not a table (e.g., it is a materialized view).
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The table is <literal>UNLOGGED</literal>.
|
||||
|
||||
@@ -945,6 +945,14 @@ check_concurrent_repack_requirements(Relation rel, Oid *ident_idx_p)
|
||||
errhint("%s is only allowed for permanent relations.",
|
||||
"REPACK (CONCURRENTLY)"));
|
||||
|
||||
/* A materialized view produces no logically decoded changes. */
|
||||
if (rel->rd_rel->relkind == RELKIND_MATVIEW)
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot execute %s on relation \"%s\"",
|
||||
"REPACK (CONCURRENTLY)", RelationGetRelationName(rel)),
|
||||
errdetail_relkind_not_supported(rel->rd_rel->relkind));
|
||||
|
||||
/*
|
||||
* With NOTHING, WAL does not contain the old tuple; FULL is not yet
|
||||
* supported.
|
||||
|
||||
Reference in New Issue
Block a user