diff --git a/pgxn/neon/control_plane_connector.c b/pgxn/neon/control_plane_connector.c index debbbce117..8b0035b8e8 100644 --- a/pgxn/neon/control_plane_connector.c +++ b/pgxn/neon/control_plane_connector.c @@ -741,6 +741,13 @@ NeonProcessUtility( break; case T_DropdbStmt: HandleDropDb(castNode(DropdbStmt, parseTree)); + /* + * We do this here to hack around the fact that Postgres performs the drop + * INSIDE of standard_ProcessUtility, which means that if we try to + * abort the drop normally it'll be too late. DROP DATABASE can't be inside + * of a transaction block anyway, so this should be fine to do. + */ + NeonXactCallback(XACT_EVENT_PRE_COMMIT, NULL); break; case T_CreateRoleStmt: HandleCreateRole(castNode(CreateRoleStmt, parseTree)); diff --git a/test_runner/regress/test_ddl_forwarding.py b/test_runner/regress/test_ddl_forwarding.py index 740e489759..d4cf1b4739 100644 --- a/test_runner/regress/test_ddl_forwarding.py +++ b/test_runner/regress/test_ddl_forwarding.py @@ -211,4 +211,12 @@ def test_ddl_forwarding(ddl: DdlForwardingContext): ddl.wait() ddl.failures(False) + cur.execute("CREATE DATABASE failure WITH OWNER=cork") + ddl.wait() + with pytest.raises(psycopg2.InternalError): + ddl.failures(True) + cur.execute("DROP DATABASE failure") + ddl.wait() + ddl.pg.connect(dbname="failure") # Ensure we can connect after a failed drop + conn.close()