Skip to content

Drop temporary tables when resetting a pooled connection - #1392

Open
vsaraikin wants to merge 1 commit into
MagicStack:masterfrom
vsaraikin:pool-reset-discard-temp
Open

vsaraikin wants to merge 1 commit into
MagicStack:masterfrom
vsaraikin:pool-reset-discard-temp

Conversation

@vsaraikin

Copy link
Copy Markdown

Fixes #1293

The default reset query doesn't drop temporary tables, so a temp table created by one acquirer is still there for the next one, data included. A second CREATE TEMPORARY TABLE with the same name fails with DuplicateTableError, and a table with leftover rows can be read by whatever code gets the connection next. The pool docs say the reset should leave the connection in a well-defined state, and the rest of the reset query already clears cursors, listeners, settings and advisory locks.

This adds DISCARD TEMP to the reset query. DISCARD ALL would also deallocate prepared statements and break the statement cache, DISCARD TEMP only drops the temp tables. It is gated on a new sql_discard_temp capability that is set for standard PostgreSQL and off for Redshift, CockroachDB and CrateDB. The field defaults to False, so code that builds ServerCapabilities itself by keyword (guillotina does this to turn the reset off) keeps working and keeps its current reset query.

test_pool_release_drops_temp_tables fails on master and passes with the change. The rest of tests/ gives the same result as master against PostgreSQL 17, and flake8 passes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Temporary tables still visible after releasing connection to pool

1 participant