Skip to content

fix: emit variant-specific command tag for DEALLOCATE ALL and DISCARD#4315

Open
praboud-ant wants to merge 1 commit intoGoogleCloudPlatform:postgresql-dialectfrom
praboud-ant:fix-deallocate-discard-command-tag
Open

fix: emit variant-specific command tag for DEALLOCATE ALL and DISCARD#4315
praboud-ant wants to merge 1 commit intoGoogleCloudPlatform:postgresql-dialectfrom
praboud-ant:fix-deallocate-discard-command-tag

Conversation

@praboud-ant
Copy link
Copy Markdown

@praboud-ant praboud-ant commented Apr 9, 2026

Problem

When processing DEALLOCATE ALL, PGAdapter replies with DEALLOCATE - unlike a real postgres, which replies with DEALLOCATE ALL. A similar problem exists for DISCARD.

This matters for clients that validate the response against the expected string; for some clients (in particular: pgbouncer), it causes the client to think that PGAdapter has not actually processed the DEALLOCATE, which causes incorrect client behavior later on.

Fix

Emit the full tag on each response, e.g: DEALLOCATE ALL, rather than DEALLOCATE.

Tests

New unit tests to validate this behavior.

PGAdapter was returning the CommandComplete tag 'DEALLOCATE' for both
'DEALLOCATE name' and 'DEALLOCATE ALL', and 'DISCARD' for every DISCARD
variant. Real PostgreSQL emits the subcommand in the tag: 'DEALLOCATE ALL',
'DISCARD ALL', 'DISCARD PLANS', 'DISCARD SEQUENCES', 'DISCARD TEMP'.

This matters for pgbouncer (1.22+) running in transaction pooling with
prepared-statement support. pgbouncer clears its per-server-connection
prepared-statement tracking by sniffing the CommandComplete tag in
server.c's handler, with an exact byte-length check and strcmp against
'DEALLOCATE ALL' and 'DISCARD ALL'. Because PGAdapter emitted plain
'DEALLOCATE', the length check failed, pgbouncer did not clear its
tracking, and it would subsequently send Bind for a prepared statement
name that PGAdapter had just wiped via closeAllStatements(). The client
would see 'prepared statement PGBOUNCER_N does not exist' (SQLSTATE
26000) on what looked like a previously-Parsed statement.

Return the variant-specific tag to match Postgres's cmdtaglist.h so
pgbouncer's tracking stays in sync with PGAdapter's statementsMap.
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 9, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@olavloite
Copy link
Copy Markdown
Collaborator

@praboud-ant This looks generally good to me. Would you mind signing the CLA? Without it, it will not be possible to merge this pull request.

@praboud-ant
Copy link
Copy Markdown
Author

@olavloite yeah, sorry - I'm just waiting on our legal team to add me to the existing corporate CLA. I'll let you know when that goes through.

@praboud-ant
Copy link
Copy Markdown
Author

@olavloite I should be in the corporate CLA now - not sure if you need to boop the build step for it to see that.

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