# Example configuration for postgres-mcp. Copy to .env, then replace every change-me value.
# Lines starting with # are unset and show the default or an example value.
# Each variable is documented in README.md, section Configuration.
# Set one database form only: DATABASE_URL, PG_DATABASES, PG_DATABASES_FILE or PGDATABASE.
# ---- Databases ----
# One database as a URL; the connection name is the database name unless PG_NAME is set.
DATABASE_URL=postgres://mcp_reader:change-me-reader-password@db.example.com:5432/appdb?sslmode=verify-full
# JSON array of databases, for several databases; cannot be combined with PG_DATABASES_FILE.
# PG_DATABASES=[{"name": "appdb", "url": "postgres://mcp_reader:change-me-reader-password@db.example.com:5432/appdb?sslmode=verify-full"}]
# Path to a file that holds the same JSON array; cannot be combined with PG_DATABASES.
# PG_DATABASES_FILE=/run/secrets/pg_databases.json
# Connection name when the database name is not a valid name (1 to 63 of A-Z a-z 0-9 _ -).
# PG_NAME=appdb
# Host for the PG* form; default 127.0.0.1 (not the libpq socket default).
# PGHOST=db.example.com
# Port for the PG* form; default 5432.
# PGPORT=5432
# Database name for the PG* form; setting it selects that form.
# PGDATABASE=appdb
# Role name for the PG* form; required together with PGDATABASE.
# PGUSER=mcp_reader
# Password for the PG* form; keep it out of version control.
# PGPASSWORD=change-me-reader-password
# TLS mode for the PG* form: disable, prefer (default), require, verify-ca or verify-full.
# PGSSLMODE=verify-full
# PEM file of trusted CA certificates; default is the bundled Mozilla roots. verify-ca needs it.
# PGSSLROOTCERT=/etc/ssl/certs/corp-ca.pem
# Client certificate (PEM file) for the PG* form; needs PGSSLKEY and a sslmode other than disable.
# PGSSLCERT=/run/secrets/pg_client.crt
# Unencrypted private key (PEM file, PKCS#8, PKCS#1 or SEC1) for PGSSLCERT; keep it out of version control.
# PGSSLKEY=/run/secrets/pg_client.key
# Trusted CA certificates as inline PEM, for the DATABASE_URL and PG* forms; a literal \n is read as a newline.
# PGSSLROOTCERT_PEM=-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----
# Client certificate as inline PEM, with PGSSLKEY_PEM; cannot be combined with PGSSLCERT.
# PGSSLCERT_PEM=-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----
# Unencrypted private key as inline PEM, with PGSSLCERT_PEM; cannot be combined with PGSSLKEY.
# PGSSLKEY_PEM=<the PEM text of an unencrypted key, with each newline written as \n>
# Authentication methods the server may use for the PG* form: scram-sha-256, md5, password (cleartext, TLS only) or none.
# Default scram-sha-256,none. A URL takes the same list as the require_auth query parameter.
# PGREQUIREAUTH=scram-sha-256,none
# application_name sent on every connection; default postgres-mcp.
# PGAPPNAME=postgres-mcp
# ---- HTTP and authentication ----
# Address the HTTP server binds to; default 127.0.0.1. Use 0.0.0.0 only behind TLS and an API key.
# MCP_HOST=127.0.0.1
# TCP port for the HTTP server and for the healthcheck command; default 8432.
# MCP_PORT=8432
# API key required on /mcp, at least 16 characters; unset means no key is checked.
# API_KEY=change-me-to-a-random-key-of-16-plus-chars
# File that holds the API key, whitespace trimmed; cannot be combined with API_KEY.
# API_KEY_FILE=/run/secrets/api_key
# Extra browser origins allowed by the Origin check, comma-separated; loopback is always allowed.
# ALLOWED_ORIGINS=https://app.example.com
# Extra Host header names allowed, comma-separated; localhost and loopback are always allowed.
# ALLOWED_HOSTS=mcp.example.com
# ---- Limits and timeouts ----
# Most rows one execute_query call returns; default 1000, bounds 1 to 100000.
# MAX_ROWS=1000
# Longest text or JSON value before it is cut (an array is cut only past 16 times this); default 4096, bounds 64 to 1048576.
# MAX_VALUE_BYTES=4096
# Bytes of a bytea value shown as hex before it is cut; default 256, bounds 16 to 65536.
# MAX_BINARY_PREVIEW_BYTES=256
# Budget for the raw bytes of values in one result; default 48000, bounds 1024 to 16777216.
# MAX_RESPONSE_BYTES=48000
# Largest HTTP request body accepted; default 1048576, bounds 1024 to 16777216.
# MAX_REQUEST_BYTES=1048576
# Longest SQL text the gate accepts; default 102400, bounds 256 to 1048576.
# MAX_SQL_BYTES=102400
# Requests to /mcp handled at once; default 16, bounds 1 to 1024.
# MAX_CONCURRENT_REQUESTS=16
# Server-side limit for each statement in milliseconds; default 30000, bounds 100 to 3600000.
# STATEMENT_TIMEOUT_MS=30000
# Server-side limit for waiting on a lock in milliseconds; default 5000, bounds 10 to 600000.
# LOCK_TIMEOUT_MS=5000
# ---- Toolsets and logging ----
# Tool groups to enable: schema, monitor, logs, timescale, core or all; default schema,monitor,logs,timescale.
# TOOLSETS=schema,monitor,logs,timescale
# One audit line per tool call on stderr: on (default), off, true, false, 1 or 0.
# AUDIT_LOG=on
# Format of log lines on stderr: text (default) or json.
# LOG_FORMAT=text
# Log level used when RUST_LOG is unset; default info, with rmcp held at warn (info,rmcp=warn).
# At debug and trace level the MCP library logs whole requests and responses, which include SQL text and result rows: use those levels only for troubleshooting.
# LOG_LEVEL=info
# Log filter in tracing syntax, used verbatim; takes precedence over LOG_LEVEL; unset by default.
# RUST_LOG=info