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

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: aman(at)stack-auth(dot)com
Subject: BUG #19968: ALTER COLUMN TYPE fails with internal errors if a dependent object is dropped concurrently
Date: 2026-12-02 01:39:50
Message-ID: 19968-d24000922918f552@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19968
Logged by: Aman Ganapathy
Email address: aman(at)stack-auth(dot)com
PostgreSQL version: 19.0
Operating system: Debian 13 (trixie), aarch64
Description:

If another session drops a view that depends on a column while ALTER
TABLE ... ALTER COLUMN ... TYPE is checking that column's dependencies,
the ALTER fails with an internal error. Same thing with a SQL function
or a publication WHERE clause. For the function it's the normal error,
but the DETAIL says "(null)" instead of the function name.

The window is really small, so to reproduce it I paused the ALTER in
getObjectDescription() with gdb, dropped the view from a second session,
then let the ALTER continue. I couldn't hit it without a debugger. It first
showed
up in a stress test that runs a lot of concurrent DDL.

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.

Same results on master at b4cc5e924b7 (2026-11-25), built with
--enable-debug --with-icu --enable-cassert.

Environment: PostgreSQL 19.0 (Debian 19.0-2.pgdg13+1) on
aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0,
64-bit; psql 19.0 (Debian 19.0-2.pgdg13+1); GNU gdb (Debian) 16.3.
Debian 13 (trixie) in the image, Linux 7.0.14 aarch64, glibc 2.41, 14
CPUs, 16 GB RAM, running in an OrbStack VM on macOS 15.7.9 (Apple
Silicon).

I believe I have a patch with an isolation test, I'll post it as a reply.

Browse pgsql-bugs by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-12-02 01:40:00 RE: BUG #18754: Logical replication cannot restart if client sent a copyDone
Previous Message PG Bug reporting form 2026-12-02 01:20:17 BUG #19967: ecpg crashes after "cursor does not exist" on FETCH or MOVE