Skip to content
SHC Docs

PostgreSQL

PostgreSQL is a powerful, open-source relational database.

Key features:

  • ACID compliance
  • Advanced indexing
  • Full-text search
  • JSON support
Terminal window
shc install postgres --stack db

Common variables:

  • postgres_user - Superuser name (default: postgres)
  • postgres_password - Superuser password (auto-generated)
  • postgres_db - Initial database name

PostgreSQL provides a socket for other apps:

Terminal window
shc install postgres --stack db
shc install keycloak --stack iam # Auto-connects to postgres

The socket exports:

  • POSTGRES_HOST - Database hostname
  • POSTGRES_PORT - Port (default: 5432)
  • POSTGRES_USER - Username
  • POSTGRES_PASSWORD - Password (from vault)
  • POSTGRES_DB - Database name

PostgreSQL uses pg_dump converter for consistent backups:

Terminal window
shc backup create --stack db

The backup includes:

  • All databases (via pg_dump)
  • User roles and permissions
  • Configuration files

Restore with pg_restore:

Terminal window
shc restore --stack db --backup abc123.bak
Terminal window
# Interactive shell
shc shell --stack db --service postgres
# Inside container
psql -U postgres
# Run SQL command
shc exec --stack db --service postgres -- \
psql -U postgres -c "SELECT version();"

Common issues:

Problem: Connection refused Solution: Check if the service is healthy: shc status db

Problem: Authentication failed Solution: Verify password: shc vault get db/postgres_password