Session settings, prepared statements and the slow-query log

This page lists the run-time settings (PostgreSQL calls them GUCs) that SET, SHOW and RESET work with, which of them change how the engine behaves, and which are only remembered so that SHOW can echo them back. MySQL session variables (@@sql_mode, foreign_key_checks and the rest) are handled by the MySQL protocol layer and are described in MySQL protocol.

How SET, SHOW and RESET are handled

SET, SHOW and RESET never reach the SQL parser. execute_with_timeout_inner recognises them from the raw statement text and calls handle_set_command, handle_show_command or handle_reset_command. Values are kept per session in the session's config map and do not leak to other sessions. (source: src/query/engine.rs, execute_with_timeout_inner, handle_set_command, handle_show_command, handle_reset_command) Tests: test_show_command, test_set_does_not_leak_between_sessions.

flowchart TD A["statement text"] --> B{"starts with SET, SHOW or RESET?"} B -- no --> P["SQL parser and planner"] B -- SET --> C{"shape"} C -- "TRANSACTION ISOLATION LEVEL" --> D["set isolation, also GUC transaction_isolation"] C -- "ROLE name" --> E["handle_set_role, membership check"] C -- "CONSTRAINTS" --> F["handle_set_constraints"] C -- "name = value, TIME ZONE x" --> G["store in session config"] C -- "SESSION AUTHORIZATION" --> H["ignored"] B -- SHOW --> I["guc_value, session value or built-in default"] B -- RESET --> J["remove session value"]

(source: src/query/engine.rs, handle_set_command, parse_set_assignment, handle_show_command, handle_reset_command)

SET

Form Behaviour
SET name = value, SET name TO value, with optional SESSION stores the value for the session; any name is accepted without error
SET name TO DEFAULT removes the session value, like RESET name
SET LOCAL name = value inside a transaction value lasts until COMMIT or ROLLBACK, then the previous value returns
SET LOCAL name = value outside a transaction does nothing (PostgreSQL warns)
SET TIME ZONE x sets timezone; LOCAL and DEFAULT set it to UTC
SET [LOCAL] TRANSACTION ISOLATION LEVEL level sets the level for the open transaction, or for the next BEGIN; an unknown level is a syntax error
SET [SESSION \| LOCAL] ROLE name, SET ROLE NONE switches the role used for privileges, row-level security and current_user; refused with 42501 unless the login role is a superuser or a member of name
SET CONSTRAINTS ALL \| names DEFERRED \| IMMEDIATE see Constraints
SET SESSION AUTHORIZATION ... accepted and ignored

(source: src/query/engine.rs, handle_set_command, parse_set_assignment, restore_set_local, handle_set_role, handle_set_constraints)

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ selects snapshot isolation. The levels themselves are described in Isolation levels. (source: src/query/engine.rs, handle_set_command) Test: test_set_transaction_is_not_treated_as_guc.

Role switching tests: test_set_role, test_set_local_role_applies_rls_and_privileges (src/plan/rls_injector.rs), session_set_reset_role (tests/security_auth.rs).

Not verified: SET LOCAL for ordinary settings (as opposed to SET LOCAL ROLE) has no test.

SHOW

SHOW name returns one row with one column named after the setting. SHOW TIME ZONE is read as SHOW timezone. The value is the session's value if one was set, else the built-in default below, else an empty string. SHOW ALL is not special-cased and is treated as a setting named all, so it returns an empty string. (source: src/query/engine.rs, handle_show_command, guc_value, guc_default)

RESET

Form Behaviour
RESET name removes the session value
RESET ALL removes every session value except the role, as in PostgreSQL
RESET ROLE returns to the login role

(source: src/query/engine.rs, handle_reset_command)

set_config and current_setting

Call Behaviour
SELECT set_config('name', 'value', is_local) as the whole statement applied like SET (or SET LOCAL when is_local is true); bound parameters are filled in first
set_config(...) inside a larger expression returns the value and changes nothing
current_setting('name') the session value or built-in default; NULL for an unknown name
current_setting('name', missing_ok) missing_ok is ignored; never raises an error

(source: src/query/engine.rs, try_set_config_statement, "current_setting" and "set_config" arms of evaluate_row_expr)

PostgreSQL raises 42704 for current_setting of an unknown name without missing_ok; SynergyDB returns NULL. (source: src/query/engine.rs, "current_setting" arm)

Tests: test_set_config_with_bound_param_feeds_rls, test_current_setting_cast_policy_filters_rows (src/plan/rls_injector.rs).

Built-in defaults

These are the values SHOW and current_setting report before any SET. Any other name reports an empty string from SHOW and NULL from current_setting.

Setting Default
server_version 15.0
server_version_num 150000
server_encoding UTF8
client_encoding UTF8
DateStyle ISO, MDY
TimeZone UTC
integer_datetimes on
standard_conforming_strings on
transaction_isolation read committed
max_identifier_length 63
bytea_output hex
search_path "$user", public
transaction_read_only, default_transaction_read_only, in_hot_standby on on a read-only cluster node, else off

(source: src/query/engine.rs, guc_default) Tests: test_search_path_default_and_set_roundtrip, test_search_path_default_without_set.

The startup ParameterStatus messages report TimeZone as Etc/UTC, while SHOW timezone reports UTC. See PostgreSQL protocol. (source: src/query/engine.rs, guc_default; src/protocol/postgres/mod.rs, startup ParameterStatus)

pg_settings is a separate fixed list and does not show session values; see System catalogs. (source: src/protocol/postgres/catalog.rs, SystemCatalog::pg_settings)

Settings that change behaviour

Setting Effect Read by
search_path schema lookup for unqualified names effective_search_path
transaction_isolation (and SET TRANSACTION ISOLATION LEVEL) isolation of the current or next transaction handle_set_command
lock_timeout how long a row-lock wait lasts before error 55P03; 0 or unset means the lock manager's cap of 300 seconds; any value is capped at 300 seconds lock_wait_timeout
hnsw.ef_search candidate count for approximate vector search, at least 16 vector_session_fetch_floor
role (via SET ROLE) privileges, row-level security, current_user handle_set_role
custom names such as app.tenant_id readable by current_setting() in row-level security policies and queries RlsInjector, current_setting

(source: src/query/engine.rs, effective_search_path, lock_wait_timeout, vector_session_fetch_floor, handle_set_role; src/transaction/lock.rs, LockManagerConfig::default, max_timeout; src/plan/rls_injector.rs, RlsInjector)

Not verified: no engine test sets lock_timeout; the lock manager's own timeout is tested by test_lock_timeout in src/transaction/lock.rs.

On the MySQL wire, innodb_lock_wait_timeout (default 50 seconds, minimum 1 second, same 300-second cap) replaces lock_timeout. (source: src/query/engine.rs, lock_wait_timeout)

Settings that are stored but ignored

Every other name is accepted and echoed by SHOW, with no effect. The ones clients commonly send:

Setting What a client might expect What happens
statement_timeout cancel long statements stored only
idle_in_transaction_session_timeout end idle transactions stored only
TimeZone convert timestamptz output stored only; no output conversion reads it
DateStyle, IntervalStyle change date and interval text format stored only
client_encoding transcode stored only; no transcoding code reads it
application_name label the session stored only; pg_stat_activity is always empty
client_min_messages filter notices stored only; no notices are sent
session_replication_role = replica disable triggers and foreign key checks during a load stored only; triggers and foreign keys stay active
work_mem, maintenance_work_mem, enable_*, random_page_cost, jit planner and memory tuning stored only
default_transaction_isolation, default_transaction_read_only defaults for new transactions stored only

(source: src/query/engine.rs, handle_set_command; settings not read by any code path in src/query or src/plan other than guc_value)

The engine has a separate per-engine query timeout of 30 seconds (QueryTimeout::default) and a check_timeout method that would raise 57014. Not wired: nothing calls check_timeout or set_query_timeout, so no statement is cancelled for running too long. (source: src/query/types.rs, QueryTimeout::default; src/query/engine.rs, check_timeout, set_query_timeout)

Because session_replication_role has no effect, loading a pg_dump data-only dump into tables with triggers fires those triggers for every row. Not verified: no test covers a load with session_replication_role. (source: src/query/engine.rs, fire_before_row_triggers)

SQL-level PREPARE

PREPARE, EXECUTE and DEALLOCATE at the SQL level are covered in Statements. Protocol-level prepared statements (Parse, Bind, Execute) are covered in PostgreSQL protocol.

Slow-query log

The slow-query log is configured with environment variables, not with SET:

Variable Meaning
SYNERGYDB_SLOW_QUERY_US threshold in microseconds; unset means the log is off
SYNERGYDB_SLOW_QUERY_LOG file path; default /tmp/synergydb-slow.log
SYNERGYDB_MEMORY_LOG_SECS turns on heap counting; each line then adds the memory the statement's thread holds, its peak and its total allocations

(source: src/query/slow_log.rs, config, begin, mem_note)

Each line has five tab-separated fields: UTC time, user@database client-address, elapsed microseconds, state (ok, err or running) and the SQL text, flattened to one line and cut at 4000 characters. A watcher thread writes running lines for statements still in progress, checking at a quarter of the threshold (between 200 ms and 5 s) and repeating every 60 seconds. (source: src/query/slow_log.rs, one_line, write, spawn_watcher; src/query/engine.rs, execute_with_timeout) Not verified: src/query/slow_log.rs has no tests.

Operating the log is described in Operations and the variables are listed in Configuration reference.