Your Question

Im hosting my app on Digital Ocean and want to use their Postgres connection pool feature [1] based on PgBouncer [2]. When I connect to the app to the connection pool instead of the DB directly I get errors like

/go/pkg/mod/gorm.io/gorm@v1.24.1/callbacks.go:134 ERROR: prepared statement "stmtcache_1" does not exist (SQLSTATE 26000) or /go/pkg/mod/gorm.io/gorm@v1.24.1/callbacks.go:134 ERROR: prepared statement "stmtcache_13" already exists (SQLSTATE 42P05) or /go/pkg/mod/gorm.io/gorm@v1.24.1/callbacks.go:134 ERROR: bind message supplies 1 parameters, but prepared statement "stmtcache_12" requires 3 (SQLSTATE 08P01)

for simple queries like

SELECT * FROM "users" WHERE auth_id = 'FIKUHQfhO9KJfgkGPNnfYz7Wa4La9K2' AND "users"."deleted_at" IS NULL ORDER BY "users"."id" LIMIT 1

When connecting directly to the DB I have no errors whatsoever for these queries.

When connecting to the connection pool without GORM (via CLI) I also have no errors whatsoever for these queries.

Any ideas how to proceed with debugging? Do I need change something in the code to use PgBouncer?

[1] https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-connection-pools/ [2] https://www.pgbouncer.org/

Comment From: perelin

Ok, got a resolution: seems to be a pgbouncer issue: https://stackoverflow.com/questions/7611926/postgres-error-prepared-statement-s-1-already-exists