analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Pod error: prepared statement \"ecto_69\" does not exist error when using existing postgresql connected using pgbouncer

Open Falcondevils opened this issue 5 months ago • 1 comments

Past Issues Searched

  • [x] I have searched open and closed issues to make sure that the bug has not yet been reported

Issue is a Bug Report

  • [x] This is a bug report and not a feature request, nor asking for self-hosted support

Using official Plausible Cloud hosting or self-hosting?

Self-hosting

Describe the bug

I am using community edition plausible analytics image.

I am trying to use existing postgresql instance. I use pgbouncer to connect to postgres in transaction mode. pgbouncer uses prepared statements in transaction mode.

So when i redeploy analytics container, the pod keeps restarting with error:

  • /entrypoint.sh run 21:11:58.072 [error] Error refreshing 'sites_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_9061" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 1095456199, query: nil} 21:11:58.072 [error] Error refreshing 'hostname_allowlist_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_9125" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 1095456199, query: nil} 21:11:58.073 [error] Error refreshing 'page_blocklist_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_1186" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 110844769, query: nil} 21:11:58.073 [error] Error refreshing 'country_blocklist_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_1122" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 725085946, query: nil} 21:11:58.073 [error] Error refreshing 'country_blocklist_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_1154" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 52924400, query: nil} 21:11:58.073 [error] Error refreshing 'ip_blocklist_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_1090" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 1809192939, query: nil} 21:11:58.074 [error] Error refreshing 'page_blocklist_by_domain' - %Postgrex.Error{message: nil, postgres: %{code: :invalid_sql_statement_name, line: "448", message: "prepared statement "ecto_1218" does not exist", file: "prepare.c", unknown: "ERROR", severity: "ERROR", pg_code: "26000", routine: "FetchPreparedStatement"}, connection_id: 1809192939, query: nil} 21:11:58.083 [notice] Application plausible exited: Plausible.Application.start(:normal, []) returned an error: shutdown: failed to start child: Plausible.Session.Salts

Expected behavior

The code should be enhanced to be able to change the statement behavior while using pgbouncer something like below: config :plausible, Plausible.Repo, statement_cache_mode: :describe

Screenshots

No response

Environment

- OS: 
- Browser:
- Browser Version:

Falcondevils avatar Jul 03 '25 21:07 Falcondevils

👋 @Falcondevils

You might be able to do it with custom configs

# in your custom config file

import Config

config :plausible, Plausible.Repo,
  prepare: :unnamed

Here's the full options list: https://hexdocs.pm/ecto_sql/3.13.2/Ecto.Adapters.Postgres.html#module-connection-options

ruslandoga avatar Jul 05 '25 17:07 ruslandoga