# Databases

> Create a Postgres, Redis, MySQL or MongoDB database, connect to it and run queries. Postgres also gets snapshots and branches.

Source: https://gheima.ma/docs/databases

Gheima runs managed Postgres, Redis, MySQL, and MongoDB for you. Each database gets its own credentials, which are encrypted at rest.

1. Create — Pick Postgres, Redis, MySQL or MongoDB.
2. Provision — The host reads “Provisioning…” until it is ready.
3. Connect tab — Reveal the host, port, username and password.
4. Your app — Paste a ready-made connection string.

### Create a database

1. **New database** — On the Databases page, click “New database”.
2. **Name it and pick an engine** — Choose Postgres, Redis, MySQL, or MongoDB. A database is a standalone account resource. Link it to a service later to inject its connection variables.
3. **Wait for provisioning** — The host shows “Provisioning…” until the database is ready.

### Connect

Open the Connect tab and click “Reveal connection details” (recorded in your audit log) to see the host, port, username, and password, plus ready-made snippets for a .env file, Node.js, and the CLI (psql, mysql, mongosh, redis-cli).

### Key prefix (Redis)

A managed Redis has no database to name. Accounts share one Redis instance and are kept apart by an ACL scoped to your own prefix, shown as "Key prefix" on the database page. Every key your app writes must start with it. An unprefixed key is refused with NOPERM at runtime rather than at connect, so it looks like a permissions bug in your code. Most clients can add the prefix for you: set it once when you construct the client instead of at every call site.

```
const redis = new Redis(process.env.REDIS_URL, {
  keyPrefix: 'u_abc123:', // the value shown on the database page
});
```

ioredis applies the prefix to every command. If your client cannot, prefix the keys yourself.

> Note: If your app writes keys you do not control, as BullMQ does, use a managed queue instead. It is provisioned with the channel permissions BullMQ needs.

### Query console

The Data tab opens a console for all four engines. Postgres and MySQL also get a Browse grid over your tables. Run statements with the Run button (⌘/Ctrl+Enter), format SQL, and export results as CSV or JSON.

```sql
SELECT * FROM your_table LIMIT 100;
```

For MongoDB, pass a JSON query; for Redis, a command like GET your:key.

### Reset credentials

Use "Regenerate password" on the Databases page, or "Reset password" in Settings, to rotate the password. Existing connections are dropped. Running services linked to the database redeploy with the new credentials. Anything else must reconnect with the new password.

### Snapshots & branches (Postgres)

- Snapshots: take an on-demand backup with "Take snapshot" and restore it later.
- Branches: copy a database’s schema and data into an isolated branch, for example pr-123, then reset or delete it.

> Note: Snapshots and branches currently support Postgres databases.

### Extensions (Postgres)

Open Settings on a Postgres database to enable curated extensions with one click. pgvector adds the vector column type for embeddings and similarity search.

```sql
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,2,3]');
```

After enabling pgvector, create a vector column and query by distance.

### Default ports

### Scheduled backups & retention (Postgres)

Under Settings, set a cron schedule to snapshot a Postgres database automatically. Retention keeps only the newest N snapshots and prunes older automated ones, both the record and the stored backup. Any snapshot, manual or automated, can be restored in place with one click.

### Connection pooling (Postgres)

Reveal a Postgres database’s connection details to also get a pooled connection string that routes through PgBouncer (transaction pooling). Use the pooled URL for apps that open many short-lived connections (serverless, high concurrency); use the direct URL for sessions that need prepared statements or LISTEN/NOTIFY.

- `Postgres`: 5432
- `MySQL`: 3306
- `MongoDB`: 27017
- `Redis`: 6379

A database can belong to a project or stand alone. A branch is itself a full database you can connect to, reset, or delete independently of its source.

> Result: Your app has a managed database it can connect to, query, back up, and branch, without you running the server.

---

All docs: https://gheima.ma/docs.md
