Hi! 👋 We are doing a big documentation refresh. Help us improve — what's missing or could be better? Let us know! Simply send an email or start a conversation in Google Groups!

PostgreSQL Session Settings

ProxySQL tracks supported PostgreSQL session settings changed with SET so it can apply the client’s settings to a pooled backend connection before using it. In ProxySQL 3.0.13, 3.1.13, and 4.0.13, the ParserSQL SET parser can also track changes made by a standalone set_config() call. When ProxySQL recognizes a statement that can change settings it cannot track, it generally forwards the statement and pins the session to its current hostgroup. Pinning limits routing and prevents a backend connection with untracked settings from being shared with another session.

Enable set_config() tracking

In ProxySQL Admin, select ParserSQL for PostgreSQL SET and load the change to runtime.

SET pgsql-set_parser_algorithm='3';
LOAD PGSQL VARIABLES TO RUNTIME;
SAVE PGSQL VARIABLES TO DISK;

Tracking is also active when pgsql-query_processor_parser is 1 (ParserSQL). If you already use that query processor setting, it also selects ParserSQL for SET. With the defaults (pgsql-set_parser_algorithm=2 and pgsql-query_processor_parser=0), ProxySQL forwards set_config() as an ordinary query without tracking it or pinning the session for that call. Tracking works with query digests and command statistics disabled.

Track a session-level change

From a PostgreSQL client connected through ProxySQL, use a standalone SELECT with a supported setting name, a literal value, and the Boolean false for the third argument. You can qualify the function with pg_catalog and give the result an alias.

SELECT pg_catalog.set_config('DateStyle', 'SQL, DMY', false);
SHOW DateStyle;
SELECT pg_catalog.set_config('search_path', 'app, public', false) AS path;

Send each statement separately. In the search_path example, app and public are two schemas. ProxySQL may return the normalized form "app", "public" over the simple query protocol. Over the extended query protocol, PostgreSQL returns the result row. A tracked change made in a transaction is undone by ROLLBACK or by ROLLBACK TO SAVEPOINT when the change was made after that savepoint.

With the simple query protocol, a NULL value restores the client’s connect-time value for a tracked setting, if one exists. Without a connect-time value, ProxySQL forwards the call and pins the session. Over the extended query protocol, a tracked set_config() call with a NULL value returns SQLSTATE 0A000.

When ProxySQL pins the session

With the default routing rules, ProxySQL forwards the following statements to PostgreSQL and pins the session to its hostgroup.

  • Calls with a third argument of true, which make a transaction-local change like SET LOCAL.
  • Calls with an untracked setting, such as statement_timeout or a custom setting such as app.tenant. application_name is an exception. ProxySQL forwards that setting without tracking it or pinning the session.
  • Calls that use bind parameters, casts, or expressions as arguments, or that appear inside a larger query, such as a subquery or a SELECT with multiple result expressions. The same applies to a call sent as part of a multi-statement query.
  • Calls that set TimeZone to a non-NULL value. PostgreSQL validates and applies the time zone.
  • Unqualified calls when search_path explicitly includes pg_catalog, or calls with arguments that could resolve to a user-defined overload. Use pg_catalog.set_config() with string literals and a Boolean literal to select the built-in function explicitly.
  • An UPDATE pg_settings or a DO block that mentions set_config or pg_settings.

ProxySQL forwards calls from a session that is already pinned without tracking them. It can only track changes it can see in the SQL text the client sends. Changes made inside a stored function, a trigger, or dynamic SQL in PL/pgSQL are outside this tracking.

See PostgreSQL Variables for parser settings and Extended Query Protocol for protocol behavior.