Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.pg-sharding.tech/llms.txt

Use this file to discover all available pages before exploring further.

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 ValuesDefault
log_levelThe level of logging output.debug, info, warning, error, fatalinfo
pretty_loggingWhether to write logs in a colorized, human-friendly format.true, falsefalse
daemonizeWhether to run the router as a daemon.true, falsefalse
reuse_portWhether to create a socket with SO_REUSEPORT and SO_REUSEADDR options.true, falsefalse
use_systemd_notifierWhether to use systemd notifier.true, falsefalse
systemd_notifier_debugWhether to run systemd notifier in debug mode.true, falsefalse
with_coordinatorWhether to run the router in a special coordinator mode.true, falsefalse
enable_role_systemWhether to enable the role-based access control system.true, falsefalse
roles_fileThe file path to the roles configuration.Any valid file path(none)
identity_range_sizeSize of range identifiers of sequence which router gets from coordinator.int > 10

Network Settings

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

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 ValuesDefault
dbThe database name to which the rule appliesAny valid database name(none)
usrThe user name for which the rule is applicableAny valid username(none)
search_pathThe search path used for the database connectionAny valid search path(none)
auth_ruleSee General Auth SettingsObject of AuthCfg(none)
pool_modeThe mode of connection pooling usedSESSION, TRANSACTION(none)
pool_discardDetermines if DISCARD ALL will be issued after transaction endtrue, falsefalse
pool_rollbackSpecifies whether to execute a rollback on connections returned to the pooltrue, falsefalse
pool_prepared_statementIndicates if prepared statements should be pooledtrue, falsefalse
pool_defaultIf set to true, uses the default pool settings defined elsewheretrue, falsefalse

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 ValuesDefault
dbThe database name to connect to.Any valid database name(none)
usrThe username for database authentication.Any valid username(none)
auth_rulesA map of authentication rules for backend connections.Map of string keys to AuthBackendCfg objects(none)
auth_ruleThe default auth rule. An object with usr and password fieldsAn AuthBackendCfg object(none)
pool_defaultIndicates if the connection should use the default pool settings.true, falsefalse
connection_limitThe maximum number of connections allowed to the backend (host shard). 0 means use default.Any integer value50
connection_retriesThe number of retries for a failed connection attempt. 0 means use default.Any integer value10
connection_timeoutThe timeout duration for establishing connections to the backend. 0 means use default.Any valid duration (e.g., 30s, 1m)1s
keep_aliveThe duration for keeping connections alive. 0 means use default.Any valid duration (e.g., 30s, 1m)1s
tcp_user_timeoutThe TCP user timeout for backend connections. 0 means use default.Any valid duration (e.g., 30s, 1m)9.5s

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 ValuesDefault
hostsA list of host addresses for the shard.Array of host addresses(none)
typeUse DATA alwaysDATA, WORLD(none)
tlsSee auth.mdxObject of TLSConfig(none)

Statistics Settings

Collects query execution time statistics at specified percentile levels. The router tracks two independent timing metrics:
  • Router Time (time spent in SPQR router)
  • Shard Time (time waiting for backend database)
When empty, statistics collection is disabled.
SettingDescriptionPossible ValuesDefault
time_quantilesArray of time quantiles (percentiles) for query execution statistics.Array of strings, e.g., ["0.75", "0.90", "0.999"](none)
time_quantiles_strSame as time_quantiles. This option is deprecated.Array of strings, e.g., ["0.75", "0.90", "0.999"](none)

Feature Flags

SettingDescriptionPossible ValuesDefault
maintain_paramsWhen enabled, forwards all session parameters (application_name, search_path, lock_timeout, etc.) to shard backends during query deployment. Can be overridden by the __spqr__maintain_params hint.true, falsefalse
world_shard_fallbackWhether to enable fallback to world shard.true, falsefalse

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 HintDefault
query_routing.default_route_behaviourWhether to explicitly block multishard queries. Can be overridden by the __spqr__default_route_behaviour hint.BLOCK, ALLOWYesALLOW
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, anyYesread-write
query_routing.enhanced_multishard_processingEnables engine V2 with enhanced multishard query processing, including automatic batch INSERT/COPY splitting across shards. Can be overridden by the __spqr__engine_v2 hint.true, falseYesfalse
query_routing.always_check_rulesWhether to always check the routing rules for every query. This only makes sense in a single-shard deployment.true, falseNofalse
query_routing.auto_route_ro_on_standbyWhether to automatically route read-only queries to standby servers. Currently only supported for single-shard topology.true, falseNofalse

Transaction Settings

SettingDescriptionPossible ValuesOverridable by HintDefault
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(none)

Mode Settings

SettingDescriptionPossible ValuesDefault
pool_modeDefines the pool modes.SESSION, TRANSACTION(none)
shard_typeDefines the shard types.DATA, WORLD(none)
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(none)

Debug Settings

SettingDescriptionPossible ValuesOverridable by HintDefault
show_notice_messagesWhether to show notice messages. Can be overridden by the __spqr__reply_notice hint.true, falseYesfalse
display_greetingWhether to display greeting message on client connection.true, falseNotrue
notice_message_formatFormat template for notice messages. Supported placeholders: {shard}, {host}, {hostname}, {port}, {user}, {db}, {pid}, {az}, {id}, {tx_status}, {tx_served}. Examples: "{shard}", "{host}", "{shard}@{hostname}:{port}", "{shard}@{host} (user={user}, db={db})"Any valid template stringNo"{shard}@{host}"
pid_filenameThe file name to store the process ID.Any valid filepathNo(none)
log_filenameThe file name for logging output.Any valid filepathNo(none)
pgproto_debugPostgreSQL protocol debug flag.true, falseNofalse
log_min_duration_statementLog queries that exceed this duration. Set to -1 to disable query logging by duration.Duration in milliseconds (e.g., 100ms, 1s) or -1 to disableNo-1

DBpool Settings

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

QDB Settings

SettingDescriptionPossible ValuesDefault
use_init_sqlWhether to execute commands from Init SQL filetrue, falsefalse
use_coordinator_initWhether to execute commands from Init SQL file on Routertrue, falsefalse
init_sqlPath to SQL file that router will execute before the startAny valid file path(none)
exit_on_init_sqlWhether to exit if the parsing of the SQL file failstrue, falsefalse
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(none)
qdb_max_txn_opsMaximum number of subcommands allowed in a single qdb transaction. Default is 128. coordinator param etcd_max_txn_ops is strongerInteger value in the range 0–65535