# Host a PostgreSQL database

A PostgreSQL database online all the time: your AI agent creates it on Estiba with its password and its files kept, and you pay for the memory, CPU and disk it uses.

## Put it online

1. [Sign up](https://app.estiba.cloud) and [connect your agent](https://estiba.cloud/docs/connect-your-agent) to Estiba, once.
2. Ask it: "create a PostgreSQL database on Estiba".
3. Your agent creates it from the official image, with a major version that only changes when you say so (moving to a new major version of PostgreSQL needs its data upgraded first, with a dump and a restore). It keeps the database's files in a volume, at `/var/lib/postgresql` from PostgreSQL 18 on (`/var/lib/postgresql/data` before), so they last when it restarts or moves. The password goes in as a secret: stored encrypted and never shown again, not even to the agent, so keep the one it gives you.
4. It gives the database a port and tells you its address, such as `ports.estiba.cloud:21450`.
5. [Add credit](https://estiba.cloud/docs/credit-and-prices), from $5. The database starts once there is credit.

## Connect to it

Use the address and port with any client: psql, pgAdmin, DBeaver, TablePlus or your app's driver. An app usually takes one connection URL:

```
postgresql://app:PASSWORD@ports.estiba.cloud:21450/app
```

Your apps on Estiba connect to the same address, wherever each one runs; your agent puts the URL in the app as a secret. Ask it for a database and a user for each app, rather than using the main user.

The address is open to the internet, like any database on a port: the password is what keeps others out, so use a long one. The connection is not encrypted unless the database is set up with TLS: for data that matters from outside Estiba, ask your agent to turn it on.

Is the database on a server of your own instead? Your app on Estiba reaches it over a [private network](https://estiba.cloud/docs/private-network-wireguard), without opening its port to the internet.

## What it costs

You pay for what it uses, measured every second: $4 per GB of memory and $8 per vCPU busy, a month, and $0.10 per GB its files take, taxes included. Your agent keeps it always on, so it never sleeps and your apps always find it.

PostgreSQL starts small. The official PostgreSQL 18 image, started empty on one of Estiba's servers, held about 40 MB of memory, used almost no CPU and wrote 40 MB of files: **about $0.16 a month**. It grows with your data and with what your apps ask of it; at 500 MB of memory, 5 % of a vCPU and 2 GB of files it would be about $2.60. The dashboard shows what yours really uses and costs each day.

## Back it up

Ask your agent for a dump: it runs `pg_dump` against the address and saves the file on your computer. Don't copy the database's files from the volume while it runs; a dump is the safe copy.

### Check that the copy works

A dump you never restored is a hope, not a backup. Once in a while, ask your agent to try it, away from the live database:

1. Dump in PostgreSQL's own format: `pg_dump -Fc -f app.dump "postgresql://app:PASSWORD@ports.estiba.cloud:21450/app"`.
2. Start an empty PostgreSQL of the same major version on your computer, such as `docker run -d --name restore-test -e POSTGRES_PASSWORD=test -p 5433:5432 postgres:18`.
3. Restore into it: `pg_restore --no-owner -d "postgresql://postgres:test@localhost:5433/postgres" app.dump`.
4. Look for a table or a record you know is there. If it is, the copy works. Remove the test with `docker rm -f restore-test`.

The live database is never touched: the dump only reads it.

## If a server goes down

The database keeps its files in its volume, so if the machine it runs on goes down, it waits for it to come back instead of starting somewhere else without them. When Estiba moves it to another machine, its files go with it and the address stays the same; the move restarts it for a few seconds and apps reconnect.
