Skip to content

Instantly share code, notes, and snippets.

@digitalmio
Created April 16, 2025 09:08
Show Gist options
  • Save digitalmio/c4cdbb869c1808dc89b263c8ff53c4ba to your computer and use it in GitHub Desktop.
Save digitalmio/c4cdbb869c1808dc89b263c8ff53c4ba to your computer and use it in GitHub Desktop.
PgCat-example-config.toml
# =====================
# PgCat Configuration
# =====================
[general]
host = "0.0.0.0" # Bind to all interfaces
port = 6432 # PgCat listens on this port
connect_timeout = 5000 # in ms
idle_timeout = 30000 # in ms
server_lifetime = 86400000 # in ms (1 day)
healthcheck_timeout = 1000 # in ms
healthcheck_delay = 10000 # ms between healthchecks
enable_prometheus_exporter = true
prometheus_exporter_port = 9930
log_level = "info"
log_client_connections = true
log_client_disconnections = true
log_connections = true
log_disconnections = true
# Reload this config automatically every 15s
autoreload = 15000 # in ms
# =====================
# Pool Configuration
# =====================
[pools.mydb] # 'mydb' is the name of your logical database pool
pool_mode = "transaction" # Use transaction pooling
query_parser_enabled = true # Enable PgCat's query parser
primary_reads_enabled = true # Enable 'read-your-writes' consistency
# =====================
# Shard and Backend Setup
# =====================
[pools.mydb.shards.0]
# Replace these with your actual DB hostnames and ports
servers = [
["<PRIMARY_DB_HOST>", 5432, "primary", { ssl_mode = "require", user = "$PRIMARY_DB_USER", password = "$PRIMARY_DB_PASSWORD" }],
["<REPLICA_DB_HOST>", 5432, "replica", { ssl_mode = "require", user = "$REPLICA_DB_USER", password = "$REPLICA_DB_PASSWORD" }]
]
database = "your_database_name"
# =====================
# User Configuration
# =====================
[[pools.mydb.users]]
username = "$DB_USER" # Reference to the environment variable for the DB username
password = "$DB_PASSWORD" # Reference to the environment variable for the DB password
pool_size = 50 # Max number of pooled connections for this user
[[pools.mydb.users]]
username = "$DB_USER_READER" # Reference to the read-only user
password = "$DB_PASSWORD_READER" # Reference to the read-only password
pool_size = 30 # Max number of pooled connections for this user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment