2022-02-08 09:25:59 -08:00
|
|
|
#
|
|
|
|
|
# PgCat config example.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# General pooler settings
|
|
|
|
|
[general]
|
|
|
|
|
# What IP to run on, 0.0.0.0 means accessible from everywhere.
|
|
|
|
|
host = "0.0.0.0"
|
|
|
|
|
|
|
|
|
|
# Port to run on, same as PgBouncer used in this example.
|
|
|
|
|
port = 6432
|
|
|
|
|
|
2022-08-14 01:25:14 +08:00
|
|
|
# Whether to enable prometheus exporter or not.
|
2022-08-09 15:19:11 -04:00
|
|
|
enable_prometheus_exporter = true
|
|
|
|
|
|
2022-08-14 01:25:14 +08:00
|
|
|
# Port at which prometheus exporter listens on.
|
|
|
|
|
prometheus_exporter_port = 9930
|
|
|
|
|
|
2022-02-08 09:25:59 -08:00
|
|
|
# How long to wait before aborting a server connection (ms).
|
|
|
|
|
connect_timeout = 5000
|
|
|
|
|
|
Allow setting `idle_timeout` for server connections. (#257)
In postgres, you can specify an `idle_session_timeout` which will close
sessions idling for that amount of time. If a session is closed because
of a timeout, PgCat will erroneously mark the server as unhealthy as the next
health check will return an error because the connection was drop, if no
health check is to be executed, it will simply fail trying to send the query
to the server for the same reason, the conn was drop.
Given that bb8 allows configuring an idle_timeout for pools, it would be
nice to allow setting this parameter in the config file, this way you can
set it to something shorter than the server one. Also, server pool will be kept
smaller in moments of less traffic. Actually, currently this value is set as its
default in bb8, which is 10 minutes.
This changes allows setting the parameter using the config file. It can be set both
globally and per pool. When creating the pool, if the pool don't have it defined, global
value is used.
2022-12-16 17:01:00 +01:00
|
|
|
# How long an idle connection with a server is left open (ms).
|
|
|
|
|
idle_timeout = 30000
|
|
|
|
|
|
2022-08-08 15:15:48 -05:00
|
|
|
# How much time to give the health check query to return with a result (ms).
|
2022-02-08 09:25:59 -08:00
|
|
|
healthcheck_timeout = 1000
|
|
|
|
|
|
2022-08-11 17:42:40 -04:00
|
|
|
# How long to keep connection available for immediate re-use, without running a healthcheck query on it
|
|
|
|
|
healthcheck_delay = 30000
|
|
|
|
|
|
2022-08-08 19:01:24 -04:00
|
|
|
# How much time to give clients during shutdown before forcibly killing client connections (ms).
|
|
|
|
|
shutdown_timeout = 60000
|
|
|
|
|
|
2022-02-08 09:25:59 -08:00
|
|
|
# For how long to ban a server if it fails a health check (seconds).
|
2022-07-27 21:47:55 -05:00
|
|
|
ban_time = 60 # seconds
|
2022-02-08 09:25:59 -08:00
|
|
|
|
2022-11-16 22:15:47 -08:00
|
|
|
# If we should log client connections
|
|
|
|
|
log_client_connections = false
|
|
|
|
|
|
|
|
|
|
# If we should log client disconnections
|
|
|
|
|
log_client_disconnections = false
|
|
|
|
|
|
2022-06-25 11:46:20 -07:00
|
|
|
# Reload config automatically if it changes.
|
|
|
|
|
autoreload = false
|
|
|
|
|
|
2022-12-16 20:13:13 +01:00
|
|
|
# Number of worker threads the Runtime will use (4 by default).
|
|
|
|
|
worker_threads = 5
|
|
|
|
|
|
2022-06-27 09:46:33 -07:00
|
|
|
# TLS
|
2022-06-27 16:45:41 -07:00
|
|
|
# tls_certificate = "server.cert"
|
|
|
|
|
# tls_private_key = "server.key"
|
2022-06-27 09:46:33 -07:00
|
|
|
|
2022-07-27 21:47:55 -05:00
|
|
|
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
|
|
|
|
|
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
|
2022-08-08 15:15:48 -05:00
|
|
|
admin_username = "admin_user"
|
|
|
|
|
admin_password = "admin_pass"
|
2022-02-08 15:48:28 -08:00
|
|
|
|
2022-07-27 21:47:55 -05:00
|
|
|
# pool
|
|
|
|
|
# configs are structured as pool.<pool_name>
|
|
|
|
|
# the pool_name is what clients use as database name when connecting
|
2022-08-08 15:15:48 -05:00
|
|
|
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
|
|
|
|
|
[pools.sharded_db]
|
2022-07-27 21:47:55 -05:00
|
|
|
# Pool mode (see PgBouncer docs for more).
|
|
|
|
|
# session: one server connection per connected client
|
|
|
|
|
# transaction: one server connection per client transaction
|
|
|
|
|
pool_mode = "transaction"
|
2022-02-11 11:19:40 -08:00
|
|
|
|
|
|
|
|
# If the client doesn't specify, route traffic to
|
|
|
|
|
# this role by default.
|
|
|
|
|
#
|
|
|
|
|
# any: round-robin between primary and replicas,
|
|
|
|
|
# replica: round-robin between replicas only without touching the primary,
|
|
|
|
|
# primary: all queries go to the primary unless otherwise specified.
|
2022-02-11 11:21:32 -08:00
|
|
|
default_role = "any"
|
2022-02-18 07:10:18 -08:00
|
|
|
|
|
|
|
|
# Query parser. If enabled, we'll attempt to parse
|
|
|
|
|
# every incoming query to determine if it's a read or a write.
|
|
|
|
|
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
|
|
|
|
|
# we'll direct it to the primary.
|
2022-06-24 14:52:38 -07:00
|
|
|
query_parser_enabled = true
|
2022-02-18 07:10:18 -08:00
|
|
|
|
|
|
|
|
# If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
|
|
|
|
|
# load balancing of read queries. Otherwise, the primary will only be used for write
|
2022-08-09 15:19:11 -04:00
|
|
|
# queries. The primary can always be explicitly selected with our custom protocol.
|
2022-02-18 07:10:18 -08:00
|
|
|
primary_reads_enabled = true
|
2022-02-23 11:47:24 -08:00
|
|
|
|
2023-02-15 15:19:16 -06:00
|
|
|
# Allow sharding commands to be passed as statement comments instead of
|
|
|
|
|
# separate commands. If these are unset this functionality is disabled.
|
|
|
|
|
# sharding_key_regex = '/\* sharding_key: (\d+) \*/'
|
|
|
|
|
# shard_id_regex = '/\* shard_id: (\d+) \*/'
|
|
|
|
|
# regex_search_limit = 1000 # only look at the first 1000 characters of SQL statements
|
|
|
|
|
|
2022-02-23 11:47:24 -08:00
|
|
|
# So what if you wanted to implement a different hashing function,
|
|
|
|
|
# or you've already built one and you want this pooler to use it?
|
|
|
|
|
#
|
|
|
|
|
# Current options:
|
|
|
|
|
#
|
|
|
|
|
# pg_bigint_hash: PARTITION BY HASH (Postgres hashing function)
|
|
|
|
|
# sha1: A hashing function based on SHA1
|
|
|
|
|
#
|
|
|
|
|
sharding_function = "pg_bigint_hash"
|
2022-07-27 21:47:55 -05:00
|
|
|
|
2022-10-25 11:47:41 -07:00
|
|
|
# Automatically parse this from queries and route queries to the right shard!
|
2023-03-02 00:53:31 -05:00
|
|
|
automatic_sharding_key = "data.id"
|
2022-10-25 11:47:41 -07:00
|
|
|
|
Allow setting `idle_timeout` for server connections. (#257)
In postgres, you can specify an `idle_session_timeout` which will close
sessions idling for that amount of time. If a session is closed because
of a timeout, PgCat will erroneously mark the server as unhealthy as the next
health check will return an error because the connection was drop, if no
health check is to be executed, it will simply fail trying to send the query
to the server for the same reason, the conn was drop.
Given that bb8 allows configuring an idle_timeout for pools, it would be
nice to allow setting this parameter in the config file, this way you can
set it to something shorter than the server one. Also, server pool will be kept
smaller in moments of less traffic. Actually, currently this value is set as its
default in bb8, which is 10 minutes.
This changes allows setting the parameter using the config file. It can be set both
globally and per pool. When creating the pool, if the pool don't have it defined, global
value is used.
2022-12-16 17:01:00 +01:00
|
|
|
# Idle timeout can be overwritten in the pool
|
|
|
|
|
idle_timeout = 40000
|
|
|
|
|
|
2022-07-27 21:47:55 -05:00
|
|
|
# Credentials for users that may connect to this cluster
|
2022-08-08 15:15:48 -05:00
|
|
|
[pools.sharded_db.users.0]
|
2022-07-27 21:47:55 -05:00
|
|
|
username = "sharding_user"
|
|
|
|
|
password = "sharding_user"
|
|
|
|
|
# Maximum number of server connections that can be established for this user
|
|
|
|
|
# The maximum number of connection from a single Pgcat process to any database in the cluster
|
|
|
|
|
# is the sum of pool_size across all users.
|
|
|
|
|
pool_size = 9
|
|
|
|
|
|
2022-08-17 01:01:46 +08:00
|
|
|
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
|
2022-08-13 13:45:58 -07:00
|
|
|
statement_timeout = 0
|
|
|
|
|
|
2022-08-08 15:15:48 -05:00
|
|
|
[pools.sharded_db.users.1]
|
2022-07-27 21:47:55 -05:00
|
|
|
username = "other_user"
|
|
|
|
|
password = "other_user"
|
|
|
|
|
pool_size = 21
|
2022-08-13 13:45:58 -07:00
|
|
|
statement_timeout = 15000
|
2022-07-27 21:47:55 -05:00
|
|
|
|
|
|
|
|
# Shard 0
|
2022-08-08 15:15:48 -05:00
|
|
|
[pools.sharded_db.shards.0]
|
2022-07-27 21:47:55 -05:00
|
|
|
# [ host, port, role ]
|
|
|
|
|
servers = [
|
|
|
|
|
[ "127.0.0.1", 5432, "primary" ],
|
|
|
|
|
[ "localhost", 5432, "replica" ]
|
|
|
|
|
]
|
|
|
|
|
# Database name (e.g. "postgres")
|
|
|
|
|
database = "shard0"
|
|
|
|
|
|
2022-08-08 15:15:48 -05:00
|
|
|
[pools.sharded_db.shards.1]
|
2022-07-27 21:47:55 -05:00
|
|
|
servers = [
|
|
|
|
|
[ "127.0.0.1", 5432, "primary" ],
|
|
|
|
|
[ "localhost", 5432, "replica" ],
|
|
|
|
|
]
|
|
|
|
|
database = "shard1"
|
|
|
|
|
|
2022-08-08 15:15:48 -05:00
|
|
|
[pools.sharded_db.shards.2]
|
2022-07-27 21:47:55 -05:00
|
|
|
servers = [
|
|
|
|
|
[ "127.0.0.1", 5432, "primary" ],
|
|
|
|
|
[ "localhost", 5432, "replica" ],
|
|
|
|
|
]
|
|
|
|
|
database = "shard2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[pools.simple_db]
|
|
|
|
|
pool_mode = "session"
|
|
|
|
|
default_role = "primary"
|
|
|
|
|
query_parser_enabled = true
|
|
|
|
|
primary_reads_enabled = true
|
|
|
|
|
sharding_function = "pg_bigint_hash"
|
|
|
|
|
|
|
|
|
|
[pools.simple_db.users.0]
|
|
|
|
|
username = "simple_user"
|
|
|
|
|
password = "simple_user"
|
|
|
|
|
pool_size = 5
|
2022-08-13 13:45:58 -07:00
|
|
|
statement_timeout = 0
|
2022-07-27 21:47:55 -05:00
|
|
|
|
|
|
|
|
[pools.simple_db.shards.0]
|
|
|
|
|
servers = [
|
|
|
|
|
[ "127.0.0.1", 5432, "primary" ],
|
|
|
|
|
[ "localhost", 5432, "replica" ]
|
|
|
|
|
]
|
|
|
|
|
database = "some_db"
|