Prepared Statement doesn't exist

妖精的绣舞 提交于 2019-12-04 08:35:02

follwing Richard Huxton advice, and after some trial and error.

my final setup looks like

database.yml

had to set prepared_statements to true

production:
  adapter: postgresql
  database: fakedatabase
  username: admin
  host: localhost
  port: 5444
  reconnect: true
  prepared_statements: true

pgbouncer.ini

had to uncomment server_reset_query=DISCARD ALL;

and set pool_mode=session

; #########################################################
; ############# SECTION HEADER [DATABASES] ################
; #########################################################

[databases]

fakedatabase=fake

[pgbouncer]

; ----- Generic Settings --------------------------
; -------------------------------------------------
logfile=/opt/local/var/log/pgbouncer/pgbouncer.log
pidfile=/opt/local/var/run/pgbouncer/pgbouncer.pid
listen_addr=*
listen_port=5444

; unix_socket_dir=/tmp
user=_webuser
auth_file=/Users/Shared/data/global/pg_auth
auth_type=trust
pool_mode=session
; max_client_conn=100
; default_pool_size=20
; reserve_pool_size=0
; reserve_pool_timeout=5
; server_round_robin=0

; ----- Log Settings ------------------------------
; -------------------------------------------------
; syslog=0
; syslog_ident=pgbouncer
; syslog_facility=daemon
; log_connections=1
; log_disconnections=1
; log_pooler_errors=1

; ----- Console Access Control --------------------
; -------------------------------------------------
admin_users=admin,nagios
; -------------------------------------------------
server_reset_query=DISCARD ALL;
server_check_delay=0
server_check_query=SELECT 1;
; server_lifetime=3600
; server_idle_timeout=600
; server_connect_timeout=600
; server_login_retry=15

basically allow prepared statements in a session pool mode with the default server reset query.

Perhaps reading the FAQ would help? Unless you have a good reason not to, session-pooling should be sensible.

You can use transaction pooling, provided that you PREPARE and EXECUTE the prepared query inside the same transaction (to avoid pgBouncer running the server_reset_query in between).

In my case access to postgres directory and run "DEALLOCATE ALL" resolve the problem.

If you use heroku, like this

> heroku pg:psql -a app_name
app_name::DATABASE=> DEALLOCATE ALL
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!