Skip to content

[PHP/PBO] 'prepared statement "pdo_stmt_00000001" does not exist' with transaction pooling mode and max_prepared_statements > 0 #991

Closed
@lucaspouzac

Description

@lucaspouzac

With pgbouncer 1.21.0 configure with transaction pooling mode and max_prepared_statements enabled, php application generate PG error for each request, because it try to deallocate prepared statement with the PDO name.

# LOGS PGBOUNCER
2023-12-05 16:41:02.774 UTC [1] DEBUG C-0x7f4aa87473a0: postgres/dbuser@192.168.144.1:57944 handle_parse_command: creating mapping for statement 'pdo_stmt_00000001' to 'PGBOUNCER_1' (query '    SELECT *
 	    FROM towns t
 	        INNER JOIN departments d ON d.code=t.department
 	        INNER JOIN regions r ON r.code=d.region
 	    WHERE d.name = $1 AND r.name = $2;')
2023-12-05 16:41:02.774 UTC [1] NOISE S-0x7f4aa86d3590: postgres/dbuser@192.168.144.3:5432 prepared statement PGBOUNCER_1 added to server cache, 1 cached items
2023-12-05 16:41:02.775 UTC [1] DEBUG C-0x7f4aa87473a0: postgres/dbuser@192.168.144.1:57944 handle_bind_command: mapped statement 'pdo_stmt_00000001' (query '    SELECT *
 	    FROM towns t
 	        INNER JOIN departments d ON d.code=t.department
 	        INNER JOIN regions r ON r.code=d.region
 	    WHERE d.name = $1 AND r.name = $2;') to 'PGBOUNCER_1'

# LOGS POSTGRES
2023-12-05 16:41:02.778 UTC [73] LOG:  execute PGBOUNCER_1:     SELECT *
 	    FROM towns t
 	        INNER JOIN departments d ON d.code=t.department
 	        INNER JOIN regions r ON r.code=d.region
 	    WHERE d.name = $1 AND r.name = $2;
2023-12-05 16:41:02.778 UTC [73] DETAIL:  parameters: $1 = 'Guyane', $2 = 'Guyane'
2023-12-05 16:41:02.785 UTC [73] LOG:  statement: DEALLOCATE pdo_stmt_00000001
2023-12-05 16:41:02.785 UTC [73] ERROR:  prepared statement "pdo_stmt_00000001" does not exist
2023-12-05 16:41:02.785 UTC [73] STATEMENT:  DEALLOCATE pdo_stmt_00000001

If we configure PBO connection as explained in pgbouncer documentation (PDO::ATTR_EMULATE_PREPARES ==> true, https://www.pgbouncer.org/faq.html#how-to-use-prepared-statements-with-transaction-pooling), are not activated.

Only "work" with PDO::PGSQL_ATTR_DISABLE_PREPARES => false option, but with the previous errors.

In attached files, you could find the full test with docker compose and php app.
pgbouncer.tar.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions