Skip to content

Avoid retaining PostgreSQL query results and prepared plans - #87

Merged
Araq merged 3 commits into
Araq:masterfrom
elcritch:fix/postgres-result-lifetime-upstream
Oct 22, 2026
Merged

Araq merged 3 commits into
Araq:masterfrom
elcritch:fix/postgres-result-lifetime-upstream

Conversation

@elcritch

@elcritch elcritch commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Ormin currently calls PQprepare for every query invocation with a fresh name and retains each named plan for the lifetime of the PostgreSQL connection. It also retains the PGresult from PQprepare, and failed query results can escape cleanup. On long-lived connections this caused PostgreSQL backend memory to grow without bound.

Use PQexecParams to preserve bound parameters without persistent named plans. Clear failed PGresult values before raising while preserving the database error. Add PostgreSQL regression coverage for repeated parameterized and command queries, failure recovery, and error messages.

Tested in debug and release against PostgreSQL. The prior implementation accumulated 1,000 named plans in the repeated-query test.

@Araq
Araq merged commit d737ec9 into Araq:master Oct 22, 2026
1 check passed
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.

2 participants