pgcat.toml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #
  2. # PgCat config example.
  3. #
  4. #
  5. # General pooler settings
  6. [general]
  7. # What IP to run on, 0.0.0.0 means accessible from everywhere.
  8. host = "0.0.0.0"
  9. # Port to run on, same as PgBouncer used in this example.
  10. port = 6432
  11. # Whether to enable prometheus exporter or not.
  12. enable_prometheus_exporter = true
  13. # Port at which prometheus exporter listens on.
  14. prometheus_exporter_port = 9930
  15. # How long to wait before aborting a server connection (ms).
  16. connect_timeout = 5000 # milliseconds
  17. # How long an idle connection with a server is left open (ms).
  18. idle_timeout = 30000 # milliseconds
  19. # Max connection lifetime before it's closed, even if actively used.
  20. server_lifetime = 86400000 # 24 hours
  21. # How long a client is allowed to be idle while in a transaction (ms).
  22. idle_client_in_transaction_timeout = 0 # milliseconds
  23. # How much time to give the health check query to return with a result (ms).
  24. healthcheck_timeout = 1000 # milliseconds
  25. # How long to keep connection available for immediate re-use, without running a healthcheck query on it
  26. healthcheck_delay = 30000 # milliseconds
  27. # How much time to give clients during shutdown before forcibly killing client connections (ms).
  28. shutdown_timeout = 60000 # milliseconds
  29. # How long to ban a server if it fails a health check (seconds).
  30. ban_time = 60 # seconds
  31. # If we should log client connections
  32. log_client_connections = false
  33. # If we should log client disconnections
  34. log_client_disconnections = false
  35. # When set to true, PgCat reloads configs if it detects a change in the config file.
  36. autoreload = 15000
  37. # Number of worker threads the Runtime will use (4 by default).
  38. worker_threads = 5
  39. # Number of seconds of connection idleness to wait before sending a keepalive packet to the server.
  40. tcp_keepalives_idle = 5
  41. # Number of unacknowledged keepalive packets allowed before giving up and closing the connection.
  42. tcp_keepalives_count = 5
  43. # Number of seconds between keepalive packets.
  44. tcp_keepalives_interval = 5
  45. # Path to TLS Certificate file to use for TLS connections
  46. # tls_certificate = ".circleci/server.cert"
  47. # Path to TLS private key file to use for TLS connections
  48. # tls_private_key = ".circleci/server.key"
  49. # Enable/disable server TLS
  50. server_tls = false
  51. # Verify server certificate is completely authentic.
  52. verify_server_certificate = false
  53. # User name to access the virtual administrative database (pgbouncer or pgcat)
  54. # Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
  55. admin_username = "admin_user"
  56. # Password to access the virtual administrative database
  57. admin_password = "admin_pass"
  58. # Default plugins that are configured on all pools.
  59. [plugins]
  60. # Prewarmer plugin that runs queries on server startup, before giving the connection
  61. # to the client.
  62. [plugins.prewarmer]
  63. enabled = false
  64. queries = [
  65. "SELECT pg_prewarm('pgbench_accounts')",
  66. ]
  67. # Log all queries to stdout.
  68. [plugins.query_logger]
  69. enabled = false
  70. # Block access to tables that Postgres does not allow us to control.
  71. [plugins.table_access]
  72. enabled = false
  73. tables = [
  74. "pg_user",
  75. "pg_roles",
  76. "pg_database",
  77. ]
  78. # Intercept user queries and give a fake reply.
  79. [plugins.intercept]
  80. enabled = true
  81. [plugins.intercept.queries.0]
  82. query = "select current_database() as a, current_schemas(false) as b"
  83. schema = [
  84. ["a", "text"],
  85. ["b", "text"],
  86. ]
  87. result = [
  88. ["${DATABASE}", "{public}"],
  89. ]
  90. [plugins.intercept.queries.1]
  91. query = "select current_database(), current_schema(), current_user"
  92. schema = [
  93. ["current_database", "text"],
  94. ["current_schema", "text"],
  95. ["current_user", "text"],
  96. ]
  97. result = [
  98. ["${DATABASE}", "public", "${USER}"],
  99. ]
  100. # pool configs are structured as pool.<pool_name>
  101. # the pool_name is what clients use as database name when connecting.
  102. # For a pool named `sharded_db`, clients access that pool using connection string like
  103. # `postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db`
  104. [pools.sharded_db]
  105. # Pool mode (see PgBouncer docs for more).
  106. # `session` one server connection per connected client
  107. # `transaction` one server connection per client transaction
  108. pool_mode = "transaction"
  109. # Load balancing mode
  110. # `random` selects the server at random
  111. # `loc` selects the server with the least outstanding busy conncetions
  112. load_balancing_mode = "random"
  113. # If the client doesn't specify, PgCat routes traffic to this role by default.
  114. # `any` round-robin between primary and replicas,
  115. # `replica` round-robin between replicas only without touching the primary,
  116. # `primary` all queries go to the primary unless otherwise specified.
  117. default_role = "any"
  118. # If Query Parser is enabled, we'll attempt to parse
  119. # every incoming query to determine if it's a read or a write.
  120. # If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
  121. # we'll direct it to the primary.
  122. query_parser_enabled = true
  123. # If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
  124. # load balancing of read queries. Otherwise, the primary will only be used for write
  125. # queries. The primary can always be explicitly selected with our custom protocol.
  126. primary_reads_enabled = true
  127. # Allow sharding commands to be passed as statement comments instead of
  128. # separate commands. If these are unset this functionality is disabled.
  129. # sharding_key_regex = '/\* sharding_key: (\d+) \*/'
  130. # shard_id_regex = '/\* shard_id: (\d+) \*/'
  131. # regex_search_limit = 1000 # only look at the first 1000 characters of SQL statements
  132. # So what if you wanted to implement a different hashing function,
  133. # or you've already built one and you want this pooler to use it?
  134. # Current options:
  135. # `pg_bigint_hash`: PARTITION BY HASH (Postgres hashing function)
  136. # `sha1`: A hashing function based on SHA1
  137. sharding_function = "pg_bigint_hash"
  138. # Query to be sent to servers to obtain the hash used for md5 authentication. The connection will be
  139. # established using the database configured in the pool. This parameter is inherited by every pool
  140. # and can be redefined in pool configuration.
  141. # auth_query = "SELECT $1"
  142. # User to be used for connecting to servers to obtain the hash used for md5 authentication by sending the query
  143. # specified in `auth_query_user`. The connection will be established using the database configured in the pool.
  144. # This parameter is inherited by every pool and can be redefined in pool configuration.
  145. # auth_query_user = "sharding_user"
  146. # Password to be used for connecting to servers to obtain the hash used for md5 authentication by sending the query
  147. # specified in `auth_query_user`. The connection will be established using the database configured in the pool.
  148. # This parameter is inherited by every pool and can be redefined in pool configuration.
  149. # auth_query_password = "sharding_user"
  150. # Automatically parse this from queries and route queries to the right shard!
  151. # automatic_sharding_key = "data.id"
  152. # Idle timeout can be overwritten in the pool
  153. idle_timeout = 40000
  154. # Connect timeout can be overwritten in the pool
  155. connect_timeout = 3000
  156. # When enabled, ip resolutions for server connections specified using hostnames will be cached
  157. # and checked for changes every `dns_max_ttl` seconds. If a change in the host resolution is found
  158. # old ip connections are closed (gracefully) and new connections will start using new ip.
  159. # dns_cache_enabled = false
  160. # Specifies how often (in seconds) cached ip addresses for servers are rechecked (see `dns_cache_enabled`).
  161. # dns_max_ttl = 30
  162. # Plugins can be configured on a pool-per-pool basis. This overrides the global plugins setting,
  163. # so all plugins have to be configured here again.
  164. [pool.sharded_db.plugins]
  165. [pools.sharded_db.plugins.prewarmer]
  166. enabled = true
  167. queries = [
  168. "SELECT pg_prewarm('pgbench_accounts')",
  169. ]
  170. [pools.sharded_db.plugins.query_logger]
  171. enabled = false
  172. [pools.sharded_db.plugins.table_access]
  173. enabled = false
  174. tables = [
  175. "pg_user",
  176. "pg_roles",
  177. "pg_database",
  178. ]
  179. [pools.sharded_db.plugins.intercept]
  180. enabled = true
  181. [pools.sharded_db.plugins.intercept.queries.0]
  182. query = "select current_database() as a, current_schemas(false) as b"
  183. schema = [
  184. ["a", "text"],
  185. ["b", "text"],
  186. ]
  187. result = [
  188. ["${DATABASE}", "{public}"],
  189. ]
  190. [pools.sharded_db.plugins.intercept.queries.1]
  191. query = "select current_database(), current_schema(), current_user"
  192. schema = [
  193. ["current_database", "text"],
  194. ["current_schema", "text"],
  195. ["current_user", "text"],
  196. ]
  197. result = [
  198. ["${DATABASE}", "public", "${USER}"],
  199. ]
  200. # User configs are structured as pool.<pool_name>.users.<user_index>
  201. # This section holds the credentials for users that may connect to this cluster
  202. [pools.sharded_db.users.0]
  203. # PostgreSQL username used to authenticate the user and connect to the server
  204. # if `server_username` is not set.
  205. username = "sharding_user"
  206. # PostgreSQL password used to authenticate the user and connect to the server
  207. # if `server_password` is not set.
  208. password = "sharding_user"
  209. pool_mode = "session"
  210. # PostgreSQL username used to connect to the server.
  211. # server_username = "another_user"
  212. # PostgreSQL password used to connect to the server.
  213. # server_password = "another_password"
  214. # Maximum number of server connections that can be established for this user
  215. # The maximum number of connection from a single Pgcat process to any database in the cluster
  216. # is the sum of pool_size across all users.
  217. pool_size = 9
  218. # Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
  219. # 0 means it is disabled.
  220. statement_timeout = 0
  221. [pools.sharded_db.users.1]
  222. username = "other_user"
  223. password = "other_user"
  224. pool_size = 21
  225. statement_timeout = 15000
  226. # Shard configs are structured as pool.<pool_name>.shards.<shard_id>
  227. # Each shard config contains a list of servers that make up the shard
  228. # and the database name to use.
  229. [pools.sharded_db.shards.0]
  230. # Array of servers in the shard, each server entry is an array of `[host, port, role]`
  231. servers = [["127.0.0.1", 5432, "primary"], ["localhost", 5432, "replica"]]
  232. # Array of mirrors for the shard, each mirror entry is an array of `[host, port, index of server in servers array]`
  233. # Traffic hitting the server identified by the index will be sent to the mirror.
  234. # mirrors = [["1.2.3.4", 5432, 0], ["1.2.3.4", 5432, 1]]
  235. # Database name (e.g. "postgres")
  236. database = "shard0"
  237. [pools.sharded_db.shards.1]
  238. servers = [["127.0.0.1", 5432, "primary"], ["localhost", 5432, "replica"]]
  239. database = "shard1"
  240. [pools.sharded_db.shards.2]
  241. servers = [["127.0.0.1", 5432, "primary" ], ["localhost", 5432, "replica" ]]
  242. database = "shard2"
  243. [pools.simple_db]
  244. pool_mode = "session"
  245. default_role = "primary"
  246. query_parser_enabled = true
  247. primary_reads_enabled = true
  248. sharding_function = "pg_bigint_hash"
  249. [pools.simple_db.users.0]
  250. username = "simple_user"
  251. password = "simple_user"
  252. pool_size = 5
  253. min_pool_size = 3
  254. server_lifetime = 60000
  255. statement_timeout = 0
  256. [pools.simple_db.shards.0]
  257. servers = [
  258. [ "127.0.0.1", 5432, "primary" ],
  259. [ "localhost", 5432, "replica" ]
  260. ]
  261. database = "some_db"