Skip to main content
Virtual functions let you check router status and query SPQR metadata from an application database connection. They require router_mode: PROXY. If the router has only one shard, set query_routing.always_check_rules to true; otherwise, these queries are forwarded directly to PostgreSQL.

__spqr__is_ready()

Returns the router’s readiness status as a boolean.
Readiness is based on cached host health checks. The router is considered ready if at least one host is alive or the cache is empty. This does not guarantee that every shard is reachable or has a writable host.

__spqr__shards()

Lists the shards in SPQR metadata, with one row per shard and a single text column named shard name.
For shard configuration details, use SELECT * FROM __spqr__show('shards_extended');.

__spqr__show(target)

Runs a router console SHOW command. Pass the target as a lowercase string, for example 'key_ranges'. Both forms return one row per key range:
All columns have type text: Use the function in FROM to select columns and filter rows:
ORDER BY works only when postprocessing is enabled in one of these ways:
  • Set query_routing.allow_postprocessing to true in the router configuration.
  • Run SET __spqr__allow_postprocessing TO true for the current session.
  • Add the /* __spqr__allow_postprocessing: true */ query hint.

__spqr__host_status(host)

Returns a host’s cached read-write status. Pass the host address, including its port, as a string literal:
The result has two text columns: host is the address, and rw is 'true' for a writable host or 'false' otherwise. The call fails if the host has no cached health check result.