Provides PostgreSQL database services with persistent storage.
The PostgreSQL plugin is a global plugin that integrates with the services system.
# Create with default version (latest)
gokku services:create postgres --name pg-0
# Create with specific version
gokku services:create postgres:14 --name pg-0
gokku services:create postgres:15 --name pg-0
gokku services:create postgres:16 --name pg-0
gokku services:create postgres:17 --name pg-0
gokku services:create postgres:14-alpine --name pg-0Available versions: Any PostgreSQL Docker tag (14, 15, 16, 17, latest, alpine variants, etc.)
When you link a service to an app, Gokku automatically adds environment variables to your app's .env file:
gokku services:link pg-0 -a api-prodThis command:
- Links the PostgreSQL service
pg-0to the appapi-prod - Automatically adds the following environment variables to
/opt/gokku/apps/api-prod/shared/.env:DATABASE_URL- Full PostgreSQL connection string (e.g.,postgres://postgres:password@localhost:5432/postgres)POSTGRES_HOST- PostgreSQL host (localhost)POSTGRES_PORT- PostgreSQL portPOSTGRES_USER- PostgreSQL userPOSTGRES_PASSWORD- PostgreSQL passwordPOSTGRES_DB- PostgreSQL database name
- Your app will have access to these variables on next restart/deploy
gokku postgres:info pg-0gokku postgres:psql pg-0Once connected, you can run any SQL commands:
\l -- list databases
\c dbname -- connect to database
CREATE DATABASE mydb; -- create database
\dt -- list tablesgokku postgres:logs pg-0gokku postgres:backup pg-0 > backup.sqlgokku postgres:restore pg-0 backup.sqlgokku services:unlink pg-0 -a api-prodgokku services:destroy pg-0- Persistent data storage using Docker volumes
- Automatic password generation
- PostgreSQL 15 Alpine image for minimal footprint
- Auto-restart on container failure
- Full backup and restore capabilities
- Database management commands
Data is stored in a Docker volume named {service-name}_data. This ensures data persists across container restarts and recreations.
To manually inspect the volume:
docker volume inspect pg-0_dataAfter linking a service to an app, the app will have access to the PostgreSQL credentials through environment variables. You can use the DATABASE_URL to connect to the database:
# Ruby/Rails
database_url = ENV['DATABASE_URL']// Node.js
const databaseUrl = process.env.DATABASE_URL;# Python
import os
database_url = os.getenv('DATABASE_URL')