> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dbhost.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Preview databases for CI and pull requests

> Create short-lived DBHost preview databases from CI with a 24-hour lease, renewals up to 72 hours, optional daily backup and 7-day recovery.

Preview databases give each pull request or CI run its own PostgreSQL
database that expires on its own. Use them for synthetic test data only; do
not put production or personal data in a preview.

<Note>
  Preview databases are available on Pro and Business.
</Note>

## CI key

Create a **preview CI key** under **Settings** →
**API keys**. Each key starts with `dbhci_` and is limited to one namespace,
for example your repository. A normal `dbh_` API key cannot manage previews,
and a CI key cannot manage other databases.

## Lease

| Setting | Value |
| - | - |
| Default lease | 24 hours |
| Each renewal | Up to 72 hours |
| Quota | Counts against your plan's database limit |

Create a preview with `POST /api/v1/previews` and a `ref` such as `pull/42`.
Repeating the same ref with the same choices returns the same preview, so a
re-run CI job does not create a second database. Renew with
`POST /api/v1/previews/{databaseId}/extend`. An expired lease cannot be
renewed.

```bash theme={null}
curl -X POST https://dbhost.app/api/v1/previews \
  -H "Authorization: Bearer $DBHOST_PREVIEW_CI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"ref":"pull/42","ttlHours":24,"scheduledBackup":"none"}'
```

## Backup choice

| Choice | Behavior |
| - | - |
| `none` (default) | No daily logical backup |
| `daily` | Daily logical backup, kept 30 days |

Change it while the preview is active with
`PATCH /api/v1/previews/{databaseId}/backup-policy`. Infrastructure snapshots
of the host can still contain preview data; see
[Backups and retention](/backups-and-retention).

## Delete and recover

Delete a preview with `DELETE /api/v1/previews/{databaseId}`, or let the lease
expire. DBHost takes a verified deletion backup, and the preview can be
recovered for 7 days. Recovery needs the account owner and a full-account key
(`POST /api/v1/databases/{id}/recover`); the CI key cannot recover. A
recovered preview starts a new 24-hour lease. After 7 days the preview and its
deletion backup are deleted permanently.

Full request and response details are in the
[Preview CI lifecycle reference](/api-reference/previews/ci-lifecycle).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.