# PgBouncer einrichten – PostgreSQL Connection Pooling auf VPS

PgBouncer auf VPS/Root Server: Installation, pool_mode, max_connections, Docker & systemd – PostgreSQL 10× effizienter für Web-Apps.

**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

- [Database Hosting](/de/database-hosting-mysql-postgresql)
- [Docker Compose Production](/de/root-v-server/docker-compose-production)
- [API Hosting Backend](/de/api-hosting-backend)
*VPS & Root Server: [VPS in Deutschland bestellen](https://nexorahost.com/Dedicated-server) · [panel.nexorahost.de](https://panel.nexorahost.de) · [nexorahost.com](https://nexorahost.com) (Maincubes FRA01 Frankfurt · Ryzen · NVMe)*
