You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_factory_pgtap extension fails to install on PostgreSQL 17: ON COMMIT DROP conflicts with extension ownership #12
CREATE EXTENSION test_factory_pgtap always fails on PostgreSQL 17 (and likely other versions) due to a conflict between ON COMMIT DROP and PostgreSQL's extension ownership tracking.
Root Cause
test_factory_pgtap--0.1.0.sql begins with:
CREATE TEMP TABLE original_role ONCOMMIT DROP ASSELECTcurrent_userAS original_role;
When CREATE EXTENSION runs this SQL, PostgreSQL records the temp table as extension-owned. At commit time, ON COMMIT DROP fires and attempts to drop the table — but PostgreSQL refuses because the extension owns it:
ERROR: cannot drop table original_role because extension test_factory_pgtap requires it
HINT: You can drop extension test_factory_pgtap instead.
This causes CREATE EXTENSION test_factory_pgtap to always fail (the transaction is rolled back), making the extension completely uninstallable.
Steps to Reproduce
CREATE EXTENSION test_factory_pgtap CASCADE;
-- ERROR: cannot drop table original_role because extension test_factory_pgtap requires it-- HINT: You can drop extension test_factory_pgtap instead.
Expected Behavior
Extension installs successfully.
Affected Versions
PostgreSQL 17 (confirmed)
Likely all PostgreSQL versions that enforce extension ownership on objects created during CREATE EXTENSION
Suggested Fix
Remove ON COMMIT DROP from the temp table creation:
-- Before (broken):
CREATE TEMP TABLE original_role ONCOMMIT DROP ASSELECTcurrent_userAS original_role;
-- After (fixed):
CREATE TEMP TABLE original_role ASSELECTcurrent_userAS original_role;
The table is only used during extension installation to restore the original role at the end of the script. It will be cleaned up automatically at session end (which is fine for a temp table used only during installation).
Additionally, the explicit DROP TABLE pg_temp.original_role; at line 39 of the script should be kept or also removed — it currently runs before the ON COMMIT DROP would fire, so it was the intended cleanup mechanism. With ON COMMIT DROP removed, the explicit DROP TABLE at the end of the script remains the correct approach and can stay as-is.
File Reference
sql/test_factory_pgtap--0.1.0.sql, lines 2 and 39.
Resolving as part of the test_factory pgxntool-sync + test/install/ + fix work.
Root cause is the install-time CREATE TEMP TABLE original_role ON COMMIT DROP used to save the caller's role — an extension-owned temp object, which is inherently fragile (also causes a name-collision failure if the caller already has an original_role temp table). The specific commit-time failure reported here has been masked since commit 0a51bf7 (2025-06, predates these issues) by an explicit DROP TABLE before commit, so it no longer reproduces on current code.
The proper fix removes the temp table entirely: save the caller's role via set_config('test_factory.original_role', current_user, true) and restore it with SET ROLE at end of script — no extension-owned temp object, no ON COMMIT DROP, no collision. This is being done on top of the pgxntool sync (#19), switching the install test to pgxntool's committed test/install/ path. Closing per maintainer direction.
Activity
jnasbyupgrade commentedon Jul 14, 2026
Resolving as part of the test_factory pgxntool-sync +
test/install/+ fix work.Root cause is the install-time
CREATE TEMP TABLE original_role ON COMMIT DROPused to save the caller's role — an extension-owned temp object, which is inherently fragile (also causes a name-collision failure if the caller already has anoriginal_roletemp table). The specific commit-time failure reported here has been masked since commit 0a51bf7 (2025-06, predates these issues) by an explicitDROP TABLEbefore commit, so it no longer reproduces on current code.The proper fix removes the temp table entirely: save the caller's role via
set_config('test_factory.original_role', current_user, true)and restore it withSET ROLEat end of script — no extension-owned temp object, noON COMMIT DROP, no collision. This is being done on top of the pgxntool sync (#19), switching the install test to pgxntool's committedtest/install/path. Closing per maintainer direction.Squashed 'pgxntool/' changes from bed3604..eb84bc6
Squashed 'pgxntool/' changes from bed3604..eb84bc6
Drop the original_role temp table from install (#12/#13) (#20)
Squashed 'pgxntool/' changes from bed3604..b67064b
Squashed 'pgxntool/' changes from bed3604..e80485e