# Self-host Grafana (Postgres)

> Grafana backed by Postgres instead of its default embedded SQLite, for multi-instance or external-DB setups.

- Page: https://levelrail.com/templates/grafana-postgres/
- JSON: https://levelrail.com/templates/grafana-postgres.json
- Category: Monitoring
- Licence: AGPL-3.0-only (Network copyleft (AGPL) license)
- Source: https://github.com/grafana/grafana
- Upstream docs: https://grafana.com/docs/grafana/latest/

## Requirements
- Memory: about 512 MiB
- amd64: published, arm64: published
- Needs configuration before start: no
- Pinned image tag: 16-alpine

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| db | postgres | 16-alpine | none | grafana_postgres_db_data -> /var/lib/postgresql/data |
| grafana | grafana/grafana | 11.2.0 | 3000 | grafana_postgres_data -> /var/lib/grafana |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| db | POSTGRES_DB | preset |
| db | POSTGRES_PASSWORD | generated |
| db | POSTGRES_USER | preset |
| grafana | GF_DATABASE_HOST | preset |
| grafana | GF_DATABASE_NAME | preset |
| grafana | GF_DATABASE_PASSWORD | generated |
| grafana | GF_DATABASE_TYPE | preset |
| grafana | GF_DATABASE_USER | preset |
| grafana | GF_SECURITY_ADMIN_PASSWORD | generated |

## Deploy

### CLI

```bash
levelrail-cli templates deploy grafana-postgres --name my-grafana-postgres
```

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" \
  https://levelrail.example.com/api/v1/service-templates/grafana-postgres/deploy
```

Create a token in the dashboard first. This one-click route deploys it as a trial app you can keep or remove.

## Questions

### Can I deploy Grafana (Postgres) on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for Grafana (Postgres), so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image postgres:16-alpine, grafana/grafana:11.2.0 is what you deploy there.

Self-host Grafana (Postgres), Grafana (Postgres) docker compose file, deploy Grafana (Postgres) on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
