User Tools

Site Tools


services:postgresql

This is an old revision of the document!


PostgreSQL

Shared database server for n8n and Vaultwarden.

Access

Item Value
Host 10.100.161.110
Port 5432
Container CT 110

Databases

Database User Service
n8n n8n n8n
vaultwarden vaultwarden Vaultwarden

Credentials in Vaultwarden (Network Automation collection).

Installation

# Container erstellen (Proxmox)
pct create 110 local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst \
  --hostname postgres \
  --memory 1024 --swap 512 \
  --cores 2 \
  --net0 name=eth0,bridge=vmbr0,tag=160,ip=10.100.161.110/23,gw=10.100.161.254 \
  --features nesting=1 \
  --unprivileged 1 \
  --start 1
 
# PostgreSQL installieren
pct exec 110 -- bash -c '
apt update && apt install -y postgresql postgresql-contrib
 
# Auf alle IPs hören
sed -i "s/#listen_addresses.*/listen_addresses = '\''*'\''/" /etc/postgresql/*/main/postgresql.conf
 
# Remote-Zugriff erlauben
echo "host all all 10.100.160.0/23 scram-sha-256" >> /etc/postgresql/*/main/pg_hba.conf
 
systemctl restart postgresql
'
 
# Admin-User erstellen
pct exec 110 -- su - postgres -c "psql -c \"ALTER USER postgres PASSWORD 'SECURE_PASSWORD';\""

Datenbank für Service anlegen

pct exec 110 -- su - postgres -c "psql" << SQL
CREATE USER myservice WITH PASSWORD 'SERVICE_PASSWORD';
CREATE DATABASE myservice OWNER myservice;
GRANT ALL PRIVILEGES ON DATABASE myservice TO myservice;
SQL

Backup

# Alle Datenbanken sichern
pct exec 110 -- su - postgres -c "pg_dumpall" > /backup/postgres_$(date +%Y%m%d).sql
 
# Einzelne DB
pct exec 110 -- su - postgres -c "pg_dump n8n" > /backup/n8n_$(date +%Y%m%d).sql

Management

# Status
pct exec 110 -- systemctl status postgresql
 
# Logs
pct exec 110 -- journalctl -u postgresql -f
 
# psql Shell
pct exec 110 -- su - postgres -c "psql"
 
# Datenbanken auflisten
pct exec 110 -- su - postgres -c "psql -c '\l'"
services/postgresql.1770460812.txt.gz · Last modified: by admin