Files
silverlinux-infra/postgres/README.md
T

3.4 KiB

PostgreSQL

Overview

PostgreSQL is the central database platform for SilverLinux.

Multiple applications use the same PostgreSQL instance while maintaining separate databases and database users.

This approach simplifies:

  • Backup management
  • Monitoring
  • Security
  • Resource utilization

Service Information

Container Name:

postgres

Network:

internal

Purpose:

  • Application databases
  • Centralized data storage
  • Shared database platform

Current Databases

gitea

Owner:

gitea

Purpose:

Source control and repository management.

Used by:

gitea

openproject

Owner:

openproject

Purpose:

Project management and collaboration.

Used by:

openproject

postgres

Owner:

postgres

Purpose:

Administrative database.

Used for PostgreSQL administration and maintenance.


Database Ownership

Database Owner
gitea gitea
openproject openproject
postgres postgres

Each application should use its own dedicated database user whenever possible.


Credentials

Credentials are stored in:

/srv/secrets/company.env

Current variables:

POSTGRES_ROOT_PASSWORD
POSTGRES_OPENPROJECT_PASSWORD

Future variables:

POSTGRES_GITEA_PASSWORD
POSTGRES_BAGET_PASSWORD

Passwords must never be committed to Git repositories.


Administration

Open PostgreSQL shell:

docker exec -it postgres psql -U postgres

List Databases

\l

List Roles

\du

List Connections

SELECT * FROM pg_stat_activity;

Create Database

Example:

CREATE DATABASE myapp;

Create User

Example:

CREATE USER myapp WITH PASSWORD 'StrongPassword';

Grant permissions:

GRANT ALL PRIVILEGES ON DATABASE myapp TO myapp;

Backup

Create database backup:

docker exec postgres pg_dump -U postgres openproject > openproject.sql

Create full cluster backup:

docker exec postgres pg_dumpall -U postgres > postgres-full-backup.sql

Restore

Restore database:

docker exec -i postgres psql -U postgres openproject < openproject.sql

Restore complete cluster:

docker exec -i postgres psql -U postgres < postgres-full-backup.sql

Security

  • PostgreSQL is not exposed publicly.
  • Database traffic is restricted to Docker internal networks.
  • Credentials are stored in /srv/secrets/company.env.
  • Administrative access should use the postgres role only when necessary.
  • Applications should use dedicated database users.

Monitoring

Useful commands:

Database size:

SELECT pg_database.datname,
       pg_size_pretty(pg_database_size(pg_database.datname))
FROM pg_database;

Current connections:

SELECT count(*) FROM pg_stat_activity;

PostgreSQL version:

SELECT version();

Disaster Recovery

Minimum requirements for recovery:

  • PostgreSQL container configuration
  • Database backups
  • /srv/secrets/company.env
  • Docker network configuration

Without the secrets file, applications may not be able to reconnect to their databases after restoration.


  • Gitea
  • OpenProject
  • docs/server.md
  • docs/security.md
  • docs/secrets.md
  • docs/backups.md