Re: BUG #19968: ALTER COLUMN TYPE fails with internal errors if a dependent object is dropped concurrently

From: Aman Ganapathy <aman(at)stack-auth(dot)com>
To: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19968: ALTER COLUMN TYPE fails with internal errors if a dependent object is dropped concurrently
Date: 2026-12-03 18:58:27
Message-ID: CA+jUSqQ9wvNzAmfq0U--vbh4WUCpzNC=S44d78Fq-L3q-JEQ8A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

Thanks for taking a look! I've attached a patch and a potential test.

RememberAllDependentForRebuilding() doesn't lock the objects it sees in
pg_depend, so if something is dropped in between, the lookup fails.
0001 looks them up with missing_ok = true and skips the ones that are
gone, since an object that has been dropped no longer uses the column.
If the object is still there, you get the same error as before.

0002 adds an injection point and a small isolation test that drops a
view while the ALTER is waiting. Without 0001 it fails with "could not
find tuple for rule". From #19967, I see that narrow tests may not be
worth it, so I split the test out from the patch in case it is better
to leave it out.

Both are against master. make check passes with 0001 on its own, and
make check in src/test/modules/injection_points passes with both.

Thanks
Aman

On Thu, Dec 3, 2026 at 9:57 AM Kirill Reshke <reshkekirill(at)gmail(dot)com> wrote:

> On Wed, 2 Dec 2026 at 17:30, PG Bug reporting form
> <noreply(at)postgresql(dot)org> wrote:
> >
> > The following bug has been logged on the website:
> >
>
> Hi
>
> > Setup: the official postgres:19.0 Docker image, started with
> >
> > docker run -d --name pg19 --cap-add=SYS_PTRACE \
> > -e POSTGRES_HOST_AUTH_METHOD=trust \
> > -e POSTGRES_INITDB_ARGS="--locale=C.UTF-8 --encoding=UTF8" -e TZ=UTC
> \
> > postgres:19.0 postgres -c log_error_verbosity=verbose
> >
> > and gdb installed in it (apt-get update && apt-get install -y gdb).
> >
> > Steps, in a new, empty database:
> >
> > CREATE TABLE t (id int, v int);
> > CREATE VIEW tv AS SELECT v FROM t;
> >
> > Session 1 (psql -X):
> > \set VERBOSITY verbose
> > SELECT pg_backend_pid();
> >
> > gdb, as the postgres user in the container:
> > gdb -p <pid from session 1>
> > (gdb) break getObjectDescription
> > (gdb) continue
> >
> > Session 1:
> > ALTER TABLE t ALTER COLUMN v TYPE bigint;
> > -- stops at the breakpoint
> >
> > Session 2 (psql -X):
> > DROP VIEW tv;
> >
> > gdb:
> > (gdb) continue
> >
> > Session 1 then prints:
> >
> > ERROR: XX000: could not find tuple for rule 16408
> > LOCATION: getObjectDescription, objectaddress.c:3433
> >
> > Same steps with a function or a publication instead of the view:
> >
> > CREATE FUNCTION f() RETURNS int BEGIN ATOMIC SELECT v FROM t; END;
> > (dropped with DROP FUNCTION f();)
> >
> > ERROR: 0A000: cannot alter type of a column used by a function or
> procedure
> > DETAIL: (null) depends on column "v".
> > LOCATION: RememberAllDependentForRebuilding, tablecmds.c:16243
> >
> > CREATE PUBLICATION p FOR TABLE t WHERE (v > 0);
> > (dropped with DROP PUBLICATION p;)
> >
> > ERROR: XX000: cache lookup failed for publication table 16419
> > LOCATION: getObjectDescription, objectaddress.c:4067
> >
> > On master I also got this with a sequence OWNED BY t.v (breaking in
> > get_rel_relkind() instead): "ERROR: XX000: cache lookup failed for
> > relation NNNNN".
> >
> > Expected: no internal error. Once the object is gone it doesn't depend
> > on the column anymore, so I'd expect the ALTER to just go through, like
> > it does if you drop the object before running the ALTER.
>
> Agree, its a real bug.
>
> >
> > I believe I have a patch with an isolation test, I'll post it as a reply.
>
> Please share.
>
>
> --
> Best regards,
> Kirill Reshke
>

Attachment Content-Type Size
v1-0001-Fix-ALTER-COLUMN-TYPE-when-a-dependent-object-is-.patch application/octet-stream 3.4 KB
v1-0002-Add-a-test-for-ALTER-COLUMN-TYPE-with-a-concurren.patch application/octet-stream 4.6 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-12-03 19:01:01 Re: JSON_SERIALIZE for JSONB returns parts of the internal JSONB representation
Previous Message Kirill Reshke 2026-12-03 18:42:58 Re: btree_gist: <-> fails on same-sign infinite intervals