# Database: connection, compute, disk and backups
Source: https://sovaria.in/docs/settings-database

Connect to your project’s Postgres directly or through the pooler, choose and resize compute, read disk use, and recover data with daily backups and replicas.

Every project has its own Postgres database. The **Database** group under Project settings has four pages: **Connection**, **Compute & disk**, **Pooling & timeouts** ([Pooling and timeouts](https://sovaria.in/docs/settings-pooling-and-timeouts)) and **Backups & recovery**.

(Diagram: Ways into the database)

## Connection

Pick **Pooled** or **Direct**; the page shows the full URI, a ready `psql` command and each part (host, port, database, user).

Every database in an organization is reached at `db.<org-id>.sovarias.in`, port `5432`, over TLS (`sslmode=require`). The user and database name are your project’s own; copy the exact strings from **Connect › Database** rather than typing them.

| Type | Use it for | Avoid it for |
|---|---|---|
| Pooled (transaction mode) | Functions, edge runtimes, serverless and anything that opens many short connections. | Session features: `LISTEN/NOTIFY`, session `SET`, prepared statements and advisory locks held across transactions. |
| Direct | Migrations, long-lived servers, admin tools, `LISTEN/NOTIFY`. | Thousands of short-lived connections — you’ll hit the connection limit. |

psql:
```bash
psql "postgresql://<db-user>:<password>@db.<org-id>.sovarias.in:5432/<database>?sslmode=require"
```

Node (pg):
```ts
import pg from 'pg'
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL, ssl: { rejectUnauthorized: true } })
const { rows } = await pool.query('select id, status from orders where customer_id = $1', [customerId])
```

Python (psycopg):
```python
import psycopg
with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
    rows = conn.execute("select id, status from orders where customer_id = %s", (customer_id,)).fetchall()
```

The password is stored encrypted and never shown again. **Reset password** issues a new one and shows it once — copy it then. Apps using the old password must be updated; their connections fail on the next connect.

> **Warning:** A direct database connection bypasses your Sovaria rules — it is a team credential. Apps should use the project URL and the anon key, which go through the gateway and your rules.

## Compute & disk

Each card is one instance size: vCPUs, memory, connections, disk and the hourly price. Your plan includes one size; larger ones are billed hourly against your compute credits. **Resize** asks you to confirm and restarts the database with the new size — expect a short interruption, and do it outside busy hours. On Free the size is fixed; sizes your plan can’t use are disabled.

CLI:
```bash
sov governance db-resize <org-id> <project-id> --compute-size medium
```

Disk follows the compute size. The meter shows used versus available; to get more disk, move to a larger size.

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Database disk | 500 MB | 8 GB | 25 GB | 100 GB | 1 TB |
| Concurrent database connections | 20 | 200 | 500 | 2,000 | 10,000 |
| Active databases | 1 | 1 | 10 | 100 | 500 |
| Tables | 100 | 2,000 | 10,000 | 50,000 | 200,000 |
| Database extensions | Standard | All | All | All | All custom |

## Availability

| Feature | What it does |
|---|---|
| Pause when idle | Free databases pause after a week without requests; the next request resumes them in a few seconds. Paid plans never pause. |
| Sleep when idle | A database server nobody has connected to for a while is stopped to free memory: staging, branch and preview databases after 3 days, Free projects after 14. Paid production databases never sleep. The next request or connection wakes it in a few seconds; backups keep their schedule. |
| High-availability failover | A standby copy of your database in another zone that takes over if the primary fails. Our team sets it up on request and agrees the switch-over time with you. Request it under [Networking and availability add-ons](https://sovaria.in/docs/settings-networking). |
| Isolated compute | The database runs on hardware no other customer shares. |

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Days without requests before the database is paused (0 = never); the next request resumes it | 7 days | Never | Never | Never | Never |
| High-availability failover (when multi-server redundancy is available) | — | — | — | ✓ | ✓ |
| Isolated compute cluster (set up on request) | — | — | — | ✓ | ✓ |
| Uptime target | Best effort | Best effort | Best effort | Best effort | Best effort |

### Asleep databases

A sleeping database shows **Asleep** on the Datastore and Environments pages with this notice: “This database is asleep; it wakes on the next request, which takes a few seconds.” **Wake now** starts it at once. Through the API the first requests get `503 PROJECT_MAINTENANCE` with `reason: "asleep"` and a short `Retry-After`; the SDKs retry on their own, so apps see a slower first call rather than an error. A server sleeps only when every database on it is idle: a paid project's staging and branch databases share production's server, so they stay awake with it.

## Backups & recovery

| Feature | What it does |
|---|---|
| Daily backups | A logical backup (`pg_dump`) every day, encrypted, kept 7 days on Free, 14 on Pro and 30 on higher plans. **Download** one to restore it or before risky changes. |
| Point-in-time recovery | Restore the whole database to any second in the plan's window (Pro 7 days up to Enterprise 35). Shows the earliest and latest moment; **Check** recovers a copy without changing anything; **Restore** asks you to type the moment's confirmation. Older databases need one restart to turn it on. See [Backups and recovery](https://sovaria.in/docs/backups-and-recovery). |
| Read replicas | Streaming read-only copies of a dedicated database (Pro and up) for reporting, analytics and read-heavy traffic; writes still go to the primary. Each uses your database role and password on its own port. |

How to restore a backup, and which tool to use for which mistake: [Backups and recovery](https://sovaria.in/docs/backups-and-recovery).

CLI:
```bash
sov governance db-backups        <org-id> <project-id>   # list backups
sov governance db-backup-trigger <org-id> <project-id>   # take one now
```

## Read replicas

**Add replica** copies the database with a base backup (a few seconds for small databases, longer for large ones; the replica shows *provisioning* until then) and keeps it current by streaming replication — usually well under a second behind. The panel shows how far behind each replica is. Connect with the replica's connection string and your usual database password; any write is refused there. Removing a replica deletes its copy. Replicas run next to the primary on its host.

CLI:
```bash
sov db replicas add        # starts a replica; check it with: sov db replicas list
sov db replicas list       # status, connection string, how far behind
sov db replicas remove <replica-id>
```

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Point-in-time recovery window | Never | 7 days | 14 days | 28 days | 35 days |
| Read replicas per project database | — | 1 | 2 | 5 | 10 |

> **Tip:** To undo one bad migration, [Version history: see, undo and restore changes](https://sovaria.in/docs/version-history) is faster and safer than a restore: it rolls back just that change and keeps everything else.
