Skip to content

Commit bd675ea

Browse files
committed
Add auth_query config and make pass in pools optional
1 parent 8720ed3 commit bd675ea

8 files changed

+479
-13
lines changed

.rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edition = "2021"
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#
2+
# PgCat config example.
3+
#
4+
5+
#
6+
# General pooler settings
7+
[general]
8+
# What IP to run on, 0.0.0.0 means accessible from everywhere.
9+
host = "0.0.0.0"
10+
11+
# Port to run on, same as PgBouncer used in this example.
12+
port = 6432
13+
14+
# Whether to enable prometheus exporter or not.
15+
enable_prometheus_exporter = true
16+
17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
20+
# How long to wait before aborting a server connection (ms).
21+
connect_timeout = 5000
22+
23+
# How long an idle connection with a server is left open (ms).
24+
idle_timeout = 30000
25+
26+
# How much time to give the health check query to return with a result (ms).
27+
healthcheck_timeout = 1000
28+
29+
# How long to keep connection available for immediate re-use, without running a healthcheck query on it
30+
healthcheck_delay = 30000
31+
32+
# How much time to give clients during shutdown before forcibly killing client connections (ms).
33+
shutdown_timeout = 60000
34+
35+
# For how long to ban a server if it fails a health check (seconds).
36+
ban_time = 60 # seconds
37+
38+
# If we should log client connections
39+
log_client_connections = false
40+
41+
# If we should log client disconnections
42+
log_client_disconnections = false
43+
44+
# Reload config automatically if it changes.
45+
autoreload = false
46+
47+
# Number of worker threads the Runtime will use (4 by default).
48+
worker_threads = 5
49+
50+
# TLS
51+
# tls_certificate = "server.cert"
52+
# tls_private_key = "server.key"
53+
54+
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
55+
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
56+
admin_username = "admin_user"
57+
admin_password = "admin_pass"
58+
59+
auth_query = "SELECT 1"
60+
auth_query_user = "testuser"
61+
62+
# pool
63+
# configs are structured as pool.<pool_name>
64+
# the pool_name is what clients use as database name when connecting
65+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
66+
[pools.sharded_db]
67+
# Pool mode (see PgBouncer docs for more).
68+
# session: one server connection per connected client
69+
# transaction: one server connection per client transaction
70+
pool_mode = "transaction"
71+
72+
# If the client doesn't specify, route traffic to
73+
# this role by default.
74+
#
75+
# any: round-robin between primary and replicas,
76+
# replica: round-robin between replicas only without touching the primary,
77+
# primary: all queries go to the primary unless otherwise specified.
78+
default_role = "any"
79+
80+
# Query parser. If enabled, we'll attempt to parse
81+
# every incoming query to determine if it's a read or a write.
82+
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
83+
# we'll direct it to the primary.
84+
query_parser_enabled = true
85+
86+
# If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
87+
# load balancing of read queries. Otherwise, the primary will only be used for write
88+
# queries. The primary can always be explicitly selected with our custom protocol.
89+
primary_reads_enabled = true
90+
91+
# So what if you wanted to implement a different hashing function,
92+
# or you've already built one and you want this pooler to use it?
93+
#
94+
# Current options:
95+
#
96+
# pg_bigint_hash: PARTITION BY HASH (Postgres hashing function)
97+
# sha1: A hashing function based on SHA1
98+
#
99+
sharding_function = "pg_bigint_hash"
100+
101+
# Automatically parse this from queries and route queries to the right shard!
102+
automatic_sharding_key = "id"
103+
104+
# Idle timeout can be overwritten in the pool
105+
idle_timeout = 40000
106+
107+
# Credentials for users that may connect to this cluster
108+
[pools.sharded_db.users.0]
109+
username = "sharding_user"
110+
# Maximum number of server connections that can be established for this user
111+
# The maximum number of connection from a single Pgcat process to any database in the cluster
112+
# is the sum of pool_size across all users.
113+
pool_size = 9
114+
115+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
116+
statement_timeout = 0
117+
118+
[pools.sharded_db.users.1]
119+
username = "other_user"
120+
password = "other_user"
121+
pool_size = 21
122+
statement_timeout = 15000
123+
124+
# Shard 0
125+
[pools.sharded_db.shards.0]
126+
# [ host, port, role ]
127+
servers = [
128+
[ "127.0.0.1", 5432, "primary" ],
129+
[ "localhost", 5432, "replica" ]
130+
]
131+
# Database name (e.g. "postgres")
132+
database = "shard0"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#
2+
# PgCat config example.
3+
#
4+
5+
#
6+
# General pooler settings
7+
[general]
8+
# What IP to run on, 0.0.0.0 means accessible from everywhere.
9+
host = "0.0.0.0"
10+
11+
# Port to run on, same as PgBouncer used in this example.
12+
port = 6432
13+
14+
# Whether to enable prometheus exporter or not.
15+
enable_prometheus_exporter = true
16+
17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
20+
# How long to wait before aborting a server connection (ms).
21+
connect_timeout = 5000
22+
23+
# How long an idle connection with a server is left open (ms).
24+
idle_timeout = 30000
25+
26+
# How much time to give the health check query to return with a result (ms).
27+
healthcheck_timeout = 1000
28+
29+
# How long to keep connection available for immediate re-use, without running a healthcheck query on it
30+
healthcheck_delay = 30000
31+
32+
# How much time to give clients during shutdown before forcibly killing client connections (ms).
33+
shutdown_timeout = 60000
34+
35+
# For how long to ban a server if it fails a health check (seconds).
36+
ban_time = 60 # seconds
37+
38+
# If we should log client connections
39+
log_client_connections = false
40+
41+
# If we should log client disconnections
42+
log_client_disconnections = false
43+
44+
# Reload config automatically if it changes.
45+
autoreload = false
46+
47+
# Number of worker threads the Runtime will use (4 by default).
48+
worker_threads = 5
49+
50+
# TLS
51+
# tls_certificate = "server.cert"
52+
# tls_private_key = "server.key"
53+
54+
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
55+
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
56+
admin_username = "admin_user"
57+
admin_password = "admin_pass"
58+
59+
# pool
60+
# configs are structured as pool.<pool_name>
61+
# the pool_name is what clients use as database name when connecting
62+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
63+
[pools.sharded_db]
64+
# Pool mode (see PgBouncer docs for more).
65+
# session: one server connection per connected client
66+
# transaction: one server connection per client transaction
67+
pool_mode = "transaction"
68+
69+
# If the client doesn't specify, route traffic to
70+
# this role by default.
71+
#
72+
# any: round-robin between primary and replicas,
73+
# replica: round-robin between replicas only without touching the primary,
74+
# primary: all queries go to the primary unless otherwise specified.
75+
default_role = "any"
76+
77+
# Query parser. If enabled, we'll attempt to parse
78+
# every incoming query to determine if it's a read or a write.
79+
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
80+
# we'll direct it to the primary.
81+
query_parser_enabled = true
82+
83+
# If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
84+
# load balancing of read queries. Otherwise, the primary will only be used for write
85+
# queries. The primary can always be explicitly selected with our custom protocol.
86+
primary_reads_enabled = true
87+
88+
# So what if you wanted to implement a different hashing function,
89+
# or you've already built one and you want this pooler to use it?
90+
#
91+
# Current options:
92+
#
93+
# pg_bigint_hash: PARTITION BY HASH (Postgres hashing function)
94+
# sha1: A hashing function based on SHA1
95+
#
96+
sharding_function = "pg_bigint_hash"
97+
98+
# Automatically parse this from queries and route queries to the right shard!
99+
automatic_sharding_key = "id"
100+
101+
# Idle timeout can be overwritten in the pool
102+
idle_timeout = 40000
103+
104+
# Credentials for users that may connect to this cluster
105+
[pools.sharded_db.users.0]
106+
username = "sharding_user"
107+
# Maximum number of server connections that can be established for this user
108+
# The maximum number of connection from a single Pgcat process to any database in the cluster
109+
# is the sum of pool_size across all users.
110+
pool_size = 9
111+
112+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
113+
statement_timeout = 0
114+
115+
[pools.sharded_db.users.1]
116+
username = "other_user"
117+
password = "other_user"
118+
pool_size = 21
119+
statement_timeout = 15000
120+
121+
# Shard 0
122+
[pools.sharded_db.shards.0]
123+
# [ host, port, role ]
124+
servers = [
125+
[ "127.0.0.1", 5432, "primary" ],
126+
[ "localhost", 5432, "replica" ]
127+
]
128+
# Database name (e.g. "postgres")
129+
database = "shard0"
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#
2+
# PgCat config example.
3+
#
4+
5+
#
6+
# General pooler settings
7+
[general]
8+
# What IP to run on, 0.0.0.0 means accessible from everywhere.
9+
host = "0.0.0.0"
10+
11+
# Port to run on, same as PgBouncer used in this example.
12+
port = 6432
13+
14+
# Whether to enable prometheus exporter or not.
15+
enable_prometheus_exporter = true
16+
17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
20+
# How long to wait before aborting a server connection (ms).
21+
connect_timeout = 5000
22+
23+
# How long an idle connection with a server is left open (ms).
24+
idle_timeout = 30000
25+
26+
# How much time to give the health check query to return with a result (ms).
27+
healthcheck_timeout = 1000
28+
29+
# How long to keep connection available for immediate re-use, without running a healthcheck query on it
30+
healthcheck_delay = 30000
31+
32+
# How much time to give clients during shutdown before forcibly killing client connections (ms).
33+
shutdown_timeout = 60000
34+
35+
# For how long to ban a server if it fails a health check (seconds).
36+
ban_time = 60 # seconds
37+
38+
# If we should log client connections
39+
log_client_connections = false
40+
41+
# If we should log client disconnections
42+
log_client_disconnections = false
43+
44+
# Reload config automatically if it changes.
45+
autoreload = false
46+
47+
# Number of worker threads the Runtime will use (4 by default).
48+
worker_threads = 5
49+
50+
# TLS
51+
# tls_certificate = "server.cert"
52+
# tls_private_key = "server.key"
53+
54+
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
55+
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
56+
admin_username = "admin_user"
57+
admin_password = "admin_pass"
58+
59+
auth_query = "SELECT 1"
60+
auth_query_user = "testuser"
61+
auth_query_password = "testpassword"
62+
auth_query_database = "postgres"
63+
64+
# pool
65+
# configs are structured as pool.<pool_name>
66+
# the pool_name is what clients use as database name when connecting
67+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded_db"
68+
[pools.sharded_db]
69+
# Pool mode (see PgBouncer docs for more).
70+
# session: one server connection per connected client
71+
# transaction: one server connection per client transaction
72+
pool_mode = "transaction"
73+
74+
# If the client doesn't specify, route traffic to
75+
# this role by default.
76+
#
77+
# any: round-robin between primary and replicas,
78+
# replica: round-robin between replicas only without touching the primary,
79+
# primary: all queries go to the primary unless otherwise specified.
80+
default_role = "any"
81+
82+
# Query parser. If enabled, we'll attempt to parse
83+
# every incoming query to determine if it's a read or a write.
84+
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
85+
# we'll direct it to the primary.
86+
query_parser_enabled = true
87+
88+
# If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
89+
# load balancing of read queries. Otherwise, the primary will only be used for write
90+
# queries. The primary can always be explicitly selected with our custom protocol.
91+
primary_reads_enabled = true
92+
93+
# So what if you wanted to implement a different hashing function,
94+
# or you've already built one and you want this pooler to use it?
95+
#
96+
# Current options:
97+
#
98+
# pg_bigint_hash: PARTITION BY HASH (Postgres hashing function)
99+
# sha1: A hashing function based on SHA1
100+
#
101+
sharding_function = "pg_bigint_hash"
102+
103+
# Automatically parse this from queries and route queries to the right shard!
104+
automatic_sharding_key = "id"
105+
106+
# Idle timeout can be overwritten in the pool
107+
idle_timeout = 40000
108+
109+
# Credentials for users that may connect to this cluster
110+
[pools.sharded_db.users.0]
111+
username = "sharding_user"
112+
# Maximum number of server connections that can be established for this user
113+
# The maximum number of connection from a single Pgcat process to any database in the cluster
114+
# is the sum of pool_size across all users.
115+
pool_size = 9
116+
117+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
118+
statement_timeout = 0
119+
120+
[pools.sharded_db.users.1]
121+
username = "other_user"
122+
password = "other_user"
123+
pool_size = 21
124+
statement_timeout = 15000
125+
126+
# Shard 0
127+
[pools.sharded_db.shards.0]
128+
# [ host, port, role ]
129+
servers = [
130+
[ "127.0.0.1", 5432, "primary" ],
131+
[ "localhost", 5432, "replica" ]
132+
]
133+
# Database name (e.g. "postgres")
134+
database = "shard0"

0 commit comments

Comments
 (0)