Poisoned Postgres connection pools

This post introduces the concept of 'poisoned' connection pools in Postgres, where stale session states from previous client connections can cause subsequent queries to fail. It details how PgBouncer in transaction mode can lead to this issue, specifically when session characteristics like `SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY` are left active. The post explains the error code `25006` and differentiates it from cluster-level read-only errors. It offers `DISCARD ALL` as a quick fix and suggests using `pscale branch connections top` to identify and kill problematic sessions. Furthermore, it introduces PlanetScale's MCP server as a tool to help agents find and fix the root cause of these leaks in application code, and recommends sending read traffic to replicas or ensuring strict timeouts and avoiding session variable modifications on primary transactions to prevent future occurrences.