Templates

PostgreSQL

Deploy PostgreSQL 17 with persistent storage — one command, auto-generated credentials

Ink deploys PostgreSQL 17 as a container service with a persistent volume. Your agent provisions the database using a template — credentials are auto-generated and returned immediately.

Deploying

Your agent uses the template_deploy MCP tool:

Tool Call
(
  : "postgresql",
  : "my-db"
)
{
  "services": [object Object],
  "outputs": [object Object]
}

Or via the CLI:

ink template deploy postgresql --name my-db

Auto-generated credentials

VariableValue
POSTGRES_USERpostgres
POSTGRES_PASSWORDAuto-generated at deploy time
POSTGRES_DBrailway

Passwords are randomly generated. The agent receives them as outputs — no manual password management required.

Persistent storage

A persistent volume is attached at /var/lib/postgresql/data (1 Gi default). Data survives container restarts and redeployments.

Connecting

After deployment, template_deploy returns a DATABASE_URL in the format:

postgresql://user:pass@hostname:5432/dbname

The internal URL (my-db:5432) is used for service-to-service communication within the same project. Any sibling service can connect by hostname — no external networking required.

Client libraries

Node.js

npm install pg
import pg from 'pg';

const pool = new pg.Pool({
  connectionString: process.env.DATABASE_URL,
});

const result = await pool.query('SELECT * FROM users');

Python

pip install psycopg2-binary
import os
import psycopg2

conn = psycopg2.connect(os.environ["DATABASE_URL"])
cursor = conn.cursor()
cursor.execute("SELECT * FROM users")

Specs

PropertyValue
EnginePostgreSQL 17
Imagepostgres:17
Port5432
Volume/var/lib/postgresql/data
Default Memory512Mi
Default vCPU0.5

On this page