Senate

Deploy PostgreSQL

Deploy PostgreSQL database with Senate

Deploy PostgreSQL

Deploy a production-ready PostgreSQL database with persistent storage.

Quick Setup

Time: ~3 minutes

1. Create Service

  1. Go to ServicesAdd Service
  2. Select your machine
  3. Name your service (e.g., postgres)
  4. Click Create

Create PostgreSQL service

2. Configure Source

  1. Go to the Source tab
  2. Select Docker Image as source type
  3. Enter image: postgres:16-alpine
  4. Click Save

3. Set Environment Variables

Go to the Environment tab and add:

POSTGRES_USER=myapp
POSTGRES_PASSWORD=your-secure-password
POSTGRES_DB=myapp_production

Use a strong password. This will be required to connect to your database.

4. Add Persistent Storage

  1. Go to the Storage tab
  2. Click Add Volume
  3. Configure:
    • Volume Name: postgres-data
    • Container Path: /var/lib/postgresql/data

PostgreSQL storage

5. Expose Port

  1. Go to the Ports tab
  2. Click Add Port
  3. Configure:
    • Protocol: tcp
    • Published: 5432
    • Target: 5432

6. Deploy

Click Deploy to start PostgreSQL.

Connecting

Connection String

postgresql://myapp:your-secure-password@your-server-ip:5432/myapp_production

Using psql

psql -h your-server-ip -U myapp -d myapp_production

From Application

// Node.js example
const { Pool } = require('pg');
const pool = new Pool({
  connectionString: 'postgresql://myapp:your-secure-password@your-server-ip:5432/myapp_production'
});

Backup & Restore

Create Backup

pg_dump -h your-server-ip -U myapp myapp_production > backup.sql

Restore Backup

psql -h your-server-ip -U myapp myapp_production < backup.sql

Security

Exposing PostgreSQL to the internet is risky. Consider these alternatives for production:

Recommended approaches:

  1. Internal only - Don't expose the port; access via SSH tunnel
  2. Firewall rules - Restrict to specific IP addresses
  3. VPN - Access only through private network
ssh -L 5432:localhost:5432 user@your-server-ip
# Then connect to localhost:5432

On this page