🇩🇪 DE 🇬🇧 EN
NexoraHost / Docs Start
Beliebte Suchen:Minecraft startet nichtMinecraft Server erstellenHytale Server 2026Gameserver mieten DEProject ZomboidFiveM txAdminVPS DeutschlandPort 25565 freigebenDiscord Bot hostenDNS Troubleshooting

PgBouncer einrichten – PostgreSQL Connection Pooling auf VPS

Kurzantwort: PgBouncer recycelt PostgreSQL-Verbindungen – statt 500 Connections nur 20 echte. Installiere es zwischen App und DB auf deinem VPS.

Wenn du hier landest: Deine App wirft too many connections oder die DB frisst RAM.

Docker Compose (Copy & Paste)

# docker-compose.yml
services:
  postgres:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: geheim
    volumes:
      - pgdata:/var/lib/postgresql/data

  pgbouncer:
    image: edoburu/pgbouncer
    environment:
      DATABASE_URL: postgres://postgres:geheim@postgres:5432/postgres
      POOL_MODE: transaction
      MAX_CLIENT_CONN: 500
      DEFAULT_POOL_SIZE: 20
    ports:
      - "6432:5432"
    depends_on:
      - postgres

  app:
    image: deine-app
    environment:
      DATABASE_URL: postgres://postgres:geheim@pgbouncer:5432/postgres

volumes:
  pgdata:

Native Installation (Ubuntu)

apt install -y pgbouncer postgresql-client

# /etc/pgbouncer/pgbouncer.ini
[databases]
meinedb = host=127.0.0.1 port=5432 dbname=meinedb

[pgbouncer]
listen_port = 6432
listen_addr = 127.0.0.1
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
pool_mode = transaction
max_client_conn = 500
default_pool_size = 20

systemctl enable --now pgbouncer

Fehler → Ursache → Lösung

SymptomUrsacheFix
too many connectionsKein PoolingPgBouncer, App auf Port 6432
prepared statement errortransaction modepool_mode=session oder App anpassen
Connection refused 6432PgBouncer nicht gestartetsystemctl status pgbouncer

Weiterführend

VPS & Root Server: VPS in Deutschland bestellen · panel.nexorahost.de · nexorahost.com (Maincubes FRA01 Frankfurt · Ryzen · NVMe)

Häufige Fragen (FAQ)

Wann brauche ich PgBouncer?
Ab ~50 gleichzeitigen DB-Verbindungen oder wenn deine App pro Request eine neue Connection öffnet (PHP, Serverless-artig). Symptom: "too many connections".
transaction oder session pool_mode?
transaction (Standard): Connection nach jeder Transaktion zurück. session: für Prepared Statements. statement: selten, nur spezielle Fälle.
PgBouncer Port?
PostgreSQL bleibt 5432 intern. PgBouncer lauscht auf 6432 (Standard). App verbindet sich mit 6432 statt 5432.
PgBouncer mit Docker Compose?
Ja – beliebtestes Setup. App → pgbouncer:6432 → postgres:5432. Siehe Copy-Paste Compose unten.
Wie viele Connections reichen?
default_pool_size=20 reicht oft für 500+ App-User. PostgreSQL max_connections kann niedrig bleiben (50–100).

NexoraHost

Root & VPS Server

Ryzen-Power im Maincubes FRA01 – voller Root-Zugriff, NVMe, DDoS-Schutz inklusive.

nexorahost.com · Maincubes FRA01 · 1 Tbit/s DDoS · 99,9 % Uptime