# Deploy a database sandbox

Source: https://docs.quake.ai/docs/quickstart/deploy-db-sandbox
Markdown: https://docs.quake.ai/docs/quickstart/deploy-db-sandbox.md

---

# Deploy a database sandbox

Set up a database on a Quake AI VM for prototyping and local development. Choose between SQLite (zero overhead, file-based) and PostgreSQL (tuned for low-RAM tiers).

**What you will learn:**

- When SQLite vs PostgreSQL is the right fit for a sandbox
- How to install and seed a SQLite database
- How to install PostgreSQL and tune it for a 1 GiB RAM tier
- How to create a database, role, and remote-connection rules
- How to connect from your local machine over the public network



- **SQLite**: negligible overhead; runs in-process with your application. Best fit for the Developer Plan.
- **PostgreSQL**: ~400–600 MB RAM after tuning. Functional on the Developer Plan for prototyping; for production database workloads, see [Resource tiers](/docs/account/resource-tiers) for upgrade paths.



## Prerequisites

- A Quake AI account with an active project, see the [Quickstart](/docs/quickstart) if you have not signed up
- An [SSH key pair](/docs/tools/add-ssh-key) uploaded to your account
- A running VM you can SSH into, or follow [Launch your first server](/docs/quickstart/launch-your-first-server) to launch one

## Option A: SQLite

SQLite is a file-based database that runs inside your application process. No separate server, no extra RAM usage. Ideal for prototyping, personal projects, and applications with moderate write throughput.

### Install and create a database

SSH into your VM and install SQLite:

```bash
sudo apt update && sudo apt install -y sqlite3
```

Create a test database:

```bash
sqlite3 ~/myapp.db << 'EOF'
CREATE TABLE users (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  email TEXT UNIQUE NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com');

SELECT * FROM users;
EOF
```

### Connect from your application

SQLite databases are regular files. Any application on the same VM can connect by path:

- **Node.js**: `npm install better-sqlite3`; `new Database('/home/ubuntu/myapp.db')`
- **Python**: `import sqlite3`; `sqlite3.connect('/home/ubuntu/myapp.db')`

### When to use SQLite

- Single-application prototypes
- Read-heavy workloads with moderate writes
- When you want zero database administration

---

## Option B: PostgreSQL

PostgreSQL requires more RAM but gives you a production-grade SQL database for prototyping schemas, testing queries, and developing against a real database engine.

### Install and tune for 1 GB RAM

SSH into your VM and install PostgreSQL:

```bash
sudo apt update && sudo apt install -y postgresql postgresql-client
```

Tune the configuration for the Developer Plan's memory constraints:

```bash
sudo tee /etc/postgresql/16/main/conf.d/dev-plan.conf > /dev/null << 'EOF'
shared_buffers = 128MB
effective_cache_size = 256MB
work_mem = 4MB
maintenance_work_mem = 32MB
max_connections = 20
wal_buffers = 4MB
checkpoint_completion_target = 0.9
EOF

sudo systemctl restart postgresql
```



These settings are conservative to leave room for your application. On the Developer Plan, keep `max_connections` low and avoid memory-intensive queries with large result sets.



### Create a database and user

```bash
sudo -u postgres psql << 'EOF'
CREATE USER devuser WITH PASSWORD 'devpass';
CREATE DATABASE devdb OWNER devuser;
GRANT ALL PRIVILEGES ON DATABASE devdb TO devuser;
EOF
```

Test the connection:

```bash
psql -U devuser -d devdb -h localhost -c "SELECT version();"
```

### Allow remote connections (optional)

To connect to PostgreSQL from your local machine, update the security group and PostgreSQL configuration:

1. Add a security group rule for TCP port 5432 (see the security group pattern from [Deploy an API service](/docs/quickstart/deploy-api-service)).

2. Configure PostgreSQL to listen on all interfaces:

```bash
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" \
  /etc/postgresql/16/main/postgresql.conf

echo "host devdb devuser 0.0.0.0/0 scram-sha-256" | \
  sudo tee -a /etc/postgresql/16/main/pg_hba.conf

sudo systemctl restart postgresql
```

3. Connect from your local machine:

```bash
psql -U devuser -d devdb -h YOUR_INSTANCE_IP
```



Allowing connections from `0.0.0.0/0` is acceptable for prototyping. For anything beyond that, restrict the `remote-ip` in your security group rule to your IP address.



## Next steps

- [Deploy an API service](/docs/quickstart/deploy-api-service): combine a database with an API server
- [Self-Managed PostgreSQL template](/resources/iac-templates/self-managed-postgres): automate this setup with OpenTofu
- [Block storage concepts](/docs/block/concepts/volumes): add a dedicated volume for database files

## See also

- [How to create a volume](/docs/block/how-to/create-volume)
- [Resource tiers](/docs/account/resource-tiers)
