REPACK (CONCURRENTLY) fails when replica identity index is dropped

Поиск
Список
Период
Сортировка
Искать

REPACK (CONCURRENTLY) fails when replica identity index is dropped

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
Вложения:
I don't fully understand the mechanics of this one, but here is a
reproducer:

    CREATE TABLE t (a INT PRIMARY KEY, b INT, c TEXT);
    INSERT INTO t SELECT g, g, repeat('x', 1000) FROM generate_series(1, 1000000) g;
    CREATE UNIQUE INDEX i ON t (a);
    ALTER TABLE t REPLICA IDENTITY USING INDEX i;
    DROP INDEX i;
    REPACK (CONCURRENTLY) t;

    -- in a separate session, while REPACK is still running
    DELETE FROM t WHERE a = 1;

This produces the following ERROR from the REPACK command:

    ERROR:  incomplete delete info
    CONTEXT:  slot "pg_repack_34213", output plugin "pgrepack", in the change callback, associated LSN 0/A6CC1ED0
    REPACK decoding worker

I think this can be addressed by verifying the index exists in
check_concurrent_repack_requirements() and erroring out if it doesn't.

-- 
nathan


Re: REPACK (CONCURRENTLY) fails when replica identity index is dropped

От:
Antonin Houska <ah@cybertec.at>
Дата:
Alvaro Herrera  wrote:

> On 2026-Sep-01, Alvaro Herrera wrote:
> 
> > On 2026-Sep-01, Antonin Houska wrote:
> > 
> > > I agree that the core issue is that we allow dropping an index that is being
> > > used as replica identity.
> > >
> > > Regarding catalog entries already broken this way, it appears that pg_upgrade
> > > fixes them because pg_dump does not issue "ALTER TABLE ... REPLICA IDENTITY
> > > USING INDEX ..." if there is not identity index. Thus after pg_restore,
> > > pg_class(relreplident) becomes REPLICA_IDENTITY_DEFAULT.
> > 
> > I agree that disallowing the drop is a sensible thing to do.
> 
> Actually, wouldn't it make more sense to reset the replica identity back
> to 'd' when the index is dropped, as in the attached patch?

Even though users probably do not drop the identity index too often, I think
it's possible that someone tries to drop an index that seems to be
unnecessary, but forgets that it's in use by logical replication. In such
case, I tend to consider ERROR better response than broken replication.

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com


FAQ