pgcat icon indicating copy to clipboard operation
pgcat copied to clipboard

pgcat does not honor startup parameters

Open drdrsh opened this issue 3 years ago • 4 comments

Describe the bug I am comparing pgcat's behavior against pgbouncer with both running in transaction mode.

When the client sets any of the following parameters in the connection string, pgbouncer takes note of them and keeps them consistent for each client

application_name
client_encoding
datestyle
timezone
standard_conforming_strings

pgcat doesn't. I think of these variables application_name is perhaps the most important given it can be used for query source attribution in pg_stat_activity

To Reproduce Run the following ruby script against pgcat after modifying the connection strings to point to the correct address

require 'pg'
$stdout.sync = true

conn1 = PG::connect("postgres://main_user:@pgcat:5432/main_db?application_name=app_1")
conn2 = PG::connect("postgres://main_user:@pgcat:5432/main_db?application_name=app_2")

puts "application_name on conn1 = #{conn1.async_exec('SHOW application_name')[0]['application_name']}"
puts "application_name on conn2 = #{conn2.async_exec('SHOW application_name')[0]['application_name']}"

conn1.close
conn2.close

This produces

application_name on conn1 =
application_name on conn2 =

Expected behavior It should output

application_name on conn1 =app_1
application_name on conn2 =app_2

drdrsh avatar Jun 03 '22 04:06 drdrsh

Should be an easy fix, I'll push something soon @drdrsh 👍

levkk avatar Jun 03 '22 05:06 levkk

Fixed application_name, the other ones I'll do later, they are slightly more involved I think. I'll keep this issue open until the remaining parameters are implemented.

levkk avatar Jun 09 '22 02:06 levkk

Hey @levkk, just stumbled across this open ticket while trying to debug some encoding issues. We've seen temporary issues with client_encoding not being set that we suspect are related to this bug as they first started appearing after switching to pgcat.

djohnson avatar Jun 07 '23 21:06 djohnson

Makes sense. You can set client_encoding on the server just like we do with application_name, e.g. https://github.com/levkk/pgcat/blob/master/src/client.rs#L1041

PR welcome!

P.S. Ideally we set all parameters with a single query, so maybe something like server.set_parameters(...) which will execute SET application_name = foo; SET client_encoding = bar;, etc.

levkk avatar Jun 07 '23 21:06 levkk