Databases

JDBC clients fail with 'bind message supplies 0 parameters' after ALTER COLUMN type; prepared statements misbehave on PostgreSQL 14

Environment

Environment

PostgreSQL 14.2 running on Linux (Debian), application server uses PostgreSQL JDBC driver 42.x with HikariCP connection pool; application executes prepared statements extensively and deploys frequent schema migrations that alter column types from INTEGER to BIGINT in production.

Symptoms

Symptoms

After a schema migration that changes a column's data type, Java application immediately starts throwing errors like 'bind message supplies 0 parameters' or 'invalid input syntax for type bigint' for prepared statements that previously worked. Psql clients connected fresh after migration succeed with the same SQL when run manually.

Observations

Observations

Errors are transient per client connection: newly opened JDBC connections after a pool restart work fine. The error appears even without a server restart. pg_prepared_statements view shows prepared statements only when application explicitly prepares named statements. Application uses extended query protocol and automatic server‑side prepares. The problem resolves if the connection pool is fully recycled but recurs if the pool remains across schema changes.

Already attempted

Already attempted

Restarting the application server or fully cycling the connection pool resolves the issue temporarily. Attempted to execute DEALLOCATE ALL on active sessions by connecting to each session (not feasible at scale). Did not perform server-side configuration changes without testing.

Question

Question

What mechanism is causing server‑side prepared statements to break after an ALTER COLUMN type, what safe mitigations exist to avoid application errors during rolling migrations, and what diagnostics should be collected before escalating to DBA?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1w ago• Trouble ID

Most likely causes

Server‑side prepared statements or cached plans referencing old type OIDs after ALTER TABLE ALTER COLUMN type 95%
Connection pool retaining sessions with prepared statements that are invalid after schema change 95%
JDBC driver performing automatic server‑side prepare and caching parameter metadata in the client across connection reuse 80%

Summary

The PostgreSQL server and JDBC driver interaction with prepared statements can cause type OID mismatches when the server schema changes. The JDBC driver may cache parameter type OIDs or the server may retain server‑side prepared plans that expect the old type, causing bind errors once the column type changes. Because client sessions maintain their prepared state, new schema cannot be automatically reconciled for existing prepared statements. The observed behavior (works on new connections, fails on existing pooled connections) strongly indicates cached prepared statements are the culprit.

Suggested Fixes

Diagnostic step 1
Before running migrations, plan to drain or recycle connection pools (perform a controlled rolling restart of application instances) so sessions do not hold stale prepared statements.
Diagnostic step 2
As a hotfix without restarting the app: execute DEALLOCATE ALL or DISCARD ALL in affected sessions to clear server‑side prepared statements. If you cannot run commands in each session, fully recycle the pool as soon as feasible.
Diagnostic step 3
Configure the JDBC driver to avoid automatic server‑side prepares (set prepareThreshold to 0 for the PostgreSQL JDBC driver) during deployments that alter parameter types; test this in staging first.

Continue troubleshooting

Matched from the title, description and tags