Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Database Management

Create, list, and manage local PostgreSQL databases.

Creating Databases

Basic Creation

postbase db create myapp

Output:

✓ Database 'myapp' created
 
Connection:
  postgresql://postgres:postgres@localhost:5432/myapp

With Template

Create from an existing database:

postbase db create myapp_test --template myapp

Listing Databases

postbase db list

Output:

Databases:
 
  myapp
    Size:    12.5 MB
    Tables:  8
    Created: 2026-01-25 10:30:00
 
  demo
    Size:    3.2 MB
    Tables:  3
    Created: 2026-01-24 15:45:00

JSON Output

postbase db list --json
{
  "databases": [
    {
      "name": "myapp",
      "size": 13107200,
      "tableCount": 8,
      "createdAt": "2026-01-25T10:30:00Z"
    }
  ]
}

Database Details

postbase db info myapp

Output:

Database: myapp
 
Size:       12.5 MB
Tables:     8
Views:      2
Functions:  5
Indexes:    12
 
Schemas:
  - public (8 tables)
  - auth (2 tables)
 
Extensions:
  - uuid-ossp
  - pgcrypto

Deleting Databases

With Confirmation

postbase db drop myapp

Output:

⚠ This will permanently delete the database 'myapp'
  and all its data. This cannot be undone.
 
Are you sure? (y/N): y
 
✓ Database 'myapp' dropped

Force Delete

postbase db drop myapp --force

Connection Details

Get Connection String

postbase connect myapp

Output:

Database: myapp
 
Connection Details:
  Host:     localhost
  Port:     5432
  Database: myapp
  User:     postgres
  Password: postgres
 
Connection String:
  postgresql://postgres:postgres@localhost:5432/myapp
 
psql Command:
  psql "postgresql://postgres:postgres@localhost:5432/myapp"

Copy to Clipboard

postbase connect myapp --copy

JSON Output

postbase connect myapp --json
{
  "host": "localhost",
  "port": 5432,
  "database": "myapp",
  "user": "postgres",
  "password": "postgres",
  "connectionString": "postgresql://postgres:postgres@localhost:5432/myapp"
}

Using with Applications

Environment Variables

# .env
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/myapp"

Node.js (pg)

import pg from 'pg'
 
const pool = new pg.Pool({
  connectionString: 'postgresql://postgres:postgres@localhost:5432/myapp',
})
 
const result = await pool.query('SELECT * FROM users')

Postbase SDK

import { createClient } from '@postbase/sdk'
 
const db = createClient({
  connectionString: 'postgresql://postgres:postgres@localhost:5432/myapp',
})
 
const users = await db.from('users').execute()

Prisma

// schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Drizzle

import { drizzle } from 'drizzle-orm/node-postgres'
import { Pool } from 'pg'
 
const pool = new Pool({
  connectionString: 'postgresql://postgres:postgres@localhost:5432/myapp',
})
 
const db = drizzle(pool)

Direct psql Access

# Connect with psql
psql "postgresql://postgres:postgres@localhost:5432/myapp"
 
# Or using environment variable
export PGPASSWORD=postgres
psql -h localhost -U postgres -d myapp

Database Operations via API

All operations are available via the daemon API:

List Databases

curl http://localhost:9432/databases

Create Database

curl -X POST http://localhost:9432/databases \
  -H "Content-Type: application/json" \
  -d '{"name": "newdb"}'

Get Database Details

curl http://localhost:9432/databases/myapp

Delete Database

curl -X DELETE http://localhost:9432/databases/myapp

Best Practices

Naming Conventions

  • Use lowercase names: myapp not MyApp
  • Use underscores for multi-word: my_app not my-app
  • Avoid reserved words: user, order, table

Development Workflow

# Create development database
postbase db create myapp_dev
 
# Create test database
postbase db create myapp_test --template myapp_dev
 
# Run tests
npm test
 
# Drop test database
postbase db drop myapp_test --force

Database per Environment

# Local development
postbase db create myapp_dev
 
# Local testing
postbase db create myapp_test
 
# CI environment (use cloud)
postbase cloud provision ci --ephemeral