Skip to content

Commit 4bbbe94

Browse files
committed
add pgcat connection proxy/pooler to indexer stack
1 parent e224091 commit 4bbbe94

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ NODE_DOCKER_TAG=mainnet-2024-nov-13
1515
DB_USER=postgres
1616
DB_DATABASE=postgres
1717
DB_PASSWORD=postgres
18-
DB_PORT=5432
18+
DB_PORT=6432
1919
DB_HOST=postgres
2020

2121
# Mainnet

docker-compose.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ services:
6868
interval: 30s
6969
retries: 60
7070

71+
# PGCat Proxy
72+
pgcat:
73+
image: ghcr.io/postgresml/pgcat:e1e4929d439313d987c352b4517a6d99627f3e9c
74+
command:
75+
- "pgcat"
76+
- "/etc/pgcat/pgcat.toml"
77+
volumes:
78+
- "./indexers/db/pgcat.toml:/etc/pgcat/pgcat.toml"
79+
ports:
80+
- "5432:5432"
81+
- "9930:9930"
82+
healthcheck:
83+
test: ["CMD", "pgcat", "--version"]
84+
interval: 10s
85+
timeout: 5s
86+
retries: 3
87+
7188
# Postgres Database
7289
postgres:
7390
image: postgres:16-alpine
@@ -84,7 +101,7 @@ services:
84101
POSTGRES_PASSWORD: ${DB_PASSWORD}
85102
POSTGRES_MAX_CONNECTIONS: 500
86103
ports:
87-
- "${DB_PORT}:5432"
104+
- "${DB_PORT}:6432"
88105
healthcheck:
89106
test: ["CMD-SHELL", "pg_isready -U postgres"]
90107
interval: 5s

indexers/db/pgcat.toml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#
2+
# PgCat configuration file
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 = 5432
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 much time to give `SELECT 1` health check query to return with a result (ms).
24+
healthcheck_timeout = 1000
25+
26+
# How long to keep connection available for immediate re-use, without running a healthcheck query on it
27+
healthcheck_delay = 30000
28+
29+
# How much time to give clients during shutdown before forcibly killing client connections (ms).
30+
shutdown_timeout = 60000
31+
32+
# For how long to ban a server if it fails a health check (seconds).
33+
ban_time = 60 # seconds
34+
35+
# If we should log client connections
36+
log_client_connections = false
37+
38+
# If we should log client disconnections
39+
log_client_disconnections = false
40+
41+
# TLS
42+
# tls_certificate = "server.cert"
43+
# tls_private_key = "server.key"
44+
45+
# Credentials to access the virtual administrative database (pgbouncer or pgcat)
46+
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
47+
admin_username = "postgres"
48+
admin_password = "postgres"
49+
50+
# pool
51+
# configs are structured as pool.<pool_name>
52+
# the pool_name is what clients use as database name when connecting
53+
# For the example below a client can connect using "postgres://sharding_user:sharding_user@pgcat_host:pgcat_port/sharded"
54+
[pools.postgres]
55+
# Pool mode (see PgBouncer docs for more).
56+
# session: one server connection per connected client
57+
# transaction: one server connection per client transaction
58+
pool_mode = "transaction"
59+
60+
# If the client doesn't specify, route traffic to
61+
# this role by default.
62+
#
63+
# any: round-robin between primary and replicas,
64+
# replica: round-robin between replicas only without touching the primary,
65+
# primary: all queries go to the primary unless otherwise specified.
66+
default_role = "any"
67+
68+
# Query parser. If enabled, we'll attempt to parse
69+
# every incoming query to determine if it's a read or a write.
70+
# If it's a read query, we'll direct it to a replica. Otherwise, if it's a write,
71+
# we'll direct it to the primary.
72+
query_parser_enabled = true
73+
74+
# If the query parser is enabled and this setting is enabled, we'll attempt to
75+
# infer the role from the query itself.
76+
query_parser_read_write_splitting = true
77+
78+
# If the query parser is enabled and this setting is enabled, the primary will be part of the pool of databases used for
79+
# load balancing of read queries. Otherwise, the primary will only be used for write
80+
# queries. The primary can always be explicitly selected with our custom protocol.
81+
primary_reads_enabled = true
82+
83+
# So what if you wanted to implement a different hashing function,
84+
# or you've already built one and you want this pooler to use it?
85+
#
86+
# Current options:
87+
#
88+
# pg_bigint_hash: PARTITION BY HASH (Postgres hashing function)
89+
# sha1: A hashing function based on SHA1
90+
#
91+
sharding_function = "pg_bigint_hash"
92+
93+
# Credentials for users that may connect to this cluster
94+
[pools.postgres.users.0]
95+
username = "postgres"
96+
password = "postgres"
97+
# Maximum number of server connections that can be established for this user
98+
# The maximum number of connection from a single Pgcat process to any database in the cluster
99+
# is the sum of pool_size across all users.
100+
pool_size = 9
101+
102+
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
103+
statement_timeout = 0
104+
105+
# Shard 0
106+
[pools.postgres.shards.0]
107+
# [ host, port, role ]
108+
servers = [
109+
[ "postgres", 5432, "primary" ],
110+
# [ "postgres", 5432, "replica" ]
111+
]
112+
# Database name (e.g. "postgres")
113+
database = "postgres"
114+
115+
database = "postgres"

0 commit comments

Comments
 (0)