Skip to main content
The SPQR Router configuration can be specified in JSON, TOML, or YAML format. The configuration file passing as a parameter to run command:
spqr-router run --config ./examples/router.yaml
Refer to the pkg/config/router.go file for the most up-to-date configuration options.

General Settings

SettingDescriptionPossible Values
log_levelThe level of logging output.debug, info, warning, error, fatal
pretty_loggingWhether to write logs in an colorized, human-friendly format.true, false
daemonizeWhether to run the router as a daemon.true, false
reuse_portWhether to create a socket with SO_REUSEPORT and SO_REUSEADDR options.true, false
use_systemd_notifierWhether to use systemd notifier.true, false
systemd_notifier_debugWhether to run systemd notifier in debug mode.true, false
with_coordinatorWhether to run the router in a special coordinator mode.true, false
enable_role_systemWhether to enable the role-based access control system.true, false
roles_fileThe file path to the roles configuration.Any valid file path
identity_range_sizeSize of range identifiers of sequence which router gets from coordinator.int > 1

Network Settings

SettingDescriptionPossible Values
hostThe host address the router listens on.Any valid hostname
router_portThe port number for the router.Any valid port number
router_ro_portThe port number for the read-only queries router.Any valid port number
admin_console_portThe port number for the admin console.Any valid port number
grpc_api_portThe port number for the gRPC API.Any valid port number

Frontend Rules

Frontend rule is a specification of how clients connect to the router. Refer to the FrontendRule struct in the pkg/config/rules.go file for the most up-to-date configuration options.
SettingDescriptionPossible Values
dbThe database name to which the rule appliesAny valid database name
usrThe user name for which the rule is applicableAny valid username
search_pathThe search path used for the database connectionAny valid search path
auth_ruleSee General Auth SettingsObject of AuthCfg
pool_modeThe mode of connection pooling usedSESSION, TRANSACTION
pool_discardDetermines if DISCARD ALL will be issued after transaction endtrue, false
pool_rollbackSpecifies whether to execute a rollback on connections returned to the pooltrue, false
pool_prepared_statementIndicates if prepared statements should be pooledtrue, false
pool_defaultIf set to true, uses the default pool settings defined elsewheretrue, false

Backend Rules

Backend Rule is a global setting that determines how the router connects to every shard. Refer to the BackendRule struct in the pkg/config/rules.go and pkg/config/auth_backend.go file for the most up-to-date configuration options.
SettingDescriptionPossible Values
dbThe database name to connect to.Any valid database name
usrThe username for database authentication.Any valid username
auth_rulesA map of authentication rules for backend connections.Map of string keys to AuthBackendCfg objects
auth_ruleThe default auth rule. An object with usr and password fieldsAn AuthBackendCfg object
pool_defaultIndicates if the connection should use the default pool settings.true, false
connection_limitThe maximum number of connections allowed to the backend (host shard).Any integer value
connection_retriesThe number of retries for a failed connection attempt.Any integer value
connection_timeoutThe timeout duration for establishing connections to the backend.Any valid duration (e.g., 30s, 1m)
keep_aliveThe duration for keeping connections alive.Any valid duration (e.g., 30s, 1m)
tcp_user_timeoutThe TCP user timeout for backend connections.Any valid duration (e.g., 30s, 1m)

Shards

Map of string to Shard objects. Refer to the Shard struct in the pkg/config/router.go file for the most up-to-date configuration options.
SettingDescriptionPossible Values
hostsA list of host addresses for the shard.Array of host addresses
typeUse DATA alwaysDATA, WORLD
tlsSee auth.mdxObject of TLSConfig

Statistics Settings

SettingDescriptionPossible Values
time_quantilesThe list of time quantiles to show query time statistics. When empty, no statistics is collectedArray of floats. For example, [0.8]

Feature Flags

SettingDescriptionPossible Values
maintain_paramsWhether to maintain parameters flag.true, false
with_jaegerWhether to integrate with Jaeger for tracing.true, false
world_shard_fallbackWhether to enable fallback to world shard.true, false

Query Routing Settings

Query routing settings are nested under the query_routing configuration key and control how queries are routed across shards.
Many of these settings can be overridden at runtime using routing hints.
Refer to the QRouter struct in the pkg/config/router.go file for the most up-to-date configuration options.
SettingDescriptionPossible ValuesOverridable by Hint
query_routing.default_route_behaviourWhether to explicitly block multishard queries. Can be overridden by the __spqr__default_route_behaviour hint.BLOCK, ALLOWYes
query_routing.default_target_session_attrsDefault target_session_attrs for connections. Can be overridden by the __spqr__target_session_attrs hint.read-write, smart-read-write, read-only, prefer-standby, anyYes
query_routing.enhanced_multishard_processingWhether to enable enhanced processing for multishard queries. Can be overridden by the __spqr__engine_v2 hint.true, falseYes
query_routing.always_check_rulesWhether to always check the routing rules for every query. This only makes sense in a single-shard deployment.true, falseNo
query_routing.auto_route_ro_on_standbyWhether to automatically route read-only queries to standby servers. Currently only supported for single-shard topology.true, falseNo

Transaction Settings

SettingDescriptionPossible ValuesOverridable by Hint
default_commit_strategyDefault commit strategy for distributed transactions. Can be overridden per session with the __spqr__commit_strategy hint. See Distributed Transactions for details.best-effort, 1pc, 2pcYes

Mode Settings

SettingDescriptionPossible Values
pool_modeDefines the pool modes.SESSION, TRANSACTION
shard_typeDefines the shard types.DATA, WORLD
router_modeTL;DR Use PROXY always. Defines the router modes. Local mode acts like a connection pooler, Proxy mode acts like a query router in sharded installation.LOCAL, PROXY

Debug Settings

SettingDescriptionPossible ValuesOverridable by Hint
show_notice_messagesWhether to show notice messages. Can be overridden by the __spqr__reply_notice hint.true, falseYes
notice_message_formatFormat template for notice messages. Supported placeholders: {shard}, {host}, {hostname}, {port}, {user}, {db}, {pid}, {az}, {id}, {tx_status}, {tx_served}. Default: "{shard}@{host}". Examples: "{shard}", "{host}", "{shard}@{hostname}:{port}", "{shard}@{host} (user={user}, db={db})"Any valid template stringNo
pid_file_nameThe file name to store the process ID.Any valid filepathNo
log_file_nameThe file name for logging output.Any valid filepathNo
pgproto_debugPostgreSQL protocol debug flag.true, falseNo

DBpool Settings

SettingDescriptionPossible Values
dbpool_cache_ttlTime-to-live for database pool cache entriesAny valid duration (e.g., 30s, 1m)
dbpool_check_intervalInterval for checking database pool health and cleanupAny valid duration (e.g., 30s, 1m)
dbpool_dead_check_intervalBackground health check interval for dead hosts (enables faster recovery)Any valid duration (e.g., 15s, 30s) or 0 to disable

QDB Settings

SettingDescriptionPossible Values
use_init_sqlWhether to execute commands from Init SQL filetrue, false
use_coordinator_initWhether to execute commands from Init SQL file on Routertrue, false
init_sqlPath to SQL file that router will execute before the startAny valid file path
exit_on_init_sqlWhether to exit if the parsing of the SQL file failstrue, false
memqdb_backup_pathMemQDB backup state path. MemQDB’s state restored if a file backup exists during the router startup. If there is no file, init.sql will be usedAny valid file path