Databases
KamuiDash lets you easily create and manage PostgreSQL databases.
Supported Databases
Currently, only PostgreSQL is supported.
Creating a Database
- In the project detail screen, click "New Database"
- Enter the following information:
| Field | Description | Example |
|---|---|---|
| Database Name | Identifier name | main-db |
| Spec | Resource size | Nano / Small / Medium / Large |
- Click "Create"
Database creation may take a few minutes. It's available once the status shows "running".
Connecting from Applications
Automatic Environment Variable Injection
When you select a database while creating an application, the following environment variables are automatically set:
| Environment Variable | Description |
|---|---|
DB_HOST |
Hostname |
DB_PORT |
Port number (usually 5432) |
DB_NAME |
Database name |
DB_USER |
Username |
DB_PASSWORD |
Password |
DATABASE_URL |
Full connection string: postgresql://user:password@host:port/dbname |
Use DATABASE_URL for a single connection string. Individual variables (DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD) are also available if your library requires them separately.
Connection Examples
Node.js (pg library)
const { Pool } = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
const result = await pool.query('SELECT NOW()');
console.log(result.rows[0]);
Go
import (
"database/sql"
"os"
_ "github.com/lib/pq"
)
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
Python
import os
import psycopg2
conn = psycopg2.connect(os.environ['DATABASE_URL'])
cursor = conn.cursor()
cursor.execute('SELECT NOW()')
print(cursor.fetchone())
Viewing Connection Information
- Open the database detail screen
- Check the "Connection Info" section for:
- Connection URL
- Host
- Port
- Username
- Password (click the show button)
Security Note: Keep your password secure.
Database Status
| Status | Description |
|---|---|
| success | Running normally |
| stop | Stopped |
| error | Error occurred |
Editing a Database
- Click the "Settings" tab in the database detail screen
- Editable fields:
- Spec (resource size)
- Click "Save"
Note: Changing the spec will restart the database.
Deleting a Database
- Click the "Settings" tab in the database detail screen
- Click "Delete Database"
- Enter the database name in the confirmation dialog
- Click "Delete"
Warning: Deleting a database will permanently delete all data. This action cannot be undone. We recommend backing up before deletion.
Best Practices
Use Connection Pooling
Don't keep database connections open. Use connection pools instead.
// Bad: Creating connection per request
const client = new Client({
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT),
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
});
await client.connect();
// Good: Using connection pool
const pool = new Pool({
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT),
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
});
const result = await pool.query('SELECT * FROM users');