# Self-host PostgreSQL with pgweb

> A PostgreSQL 17 server paired with the pgweb browser console, already wired together. The database is not published on the host, so other services in this project reach it at db:5432. pgweb opens straight into the database with the generated credentials, so keep its address private.

- Page: https://levelrail.com/templates/postgres-pgweb/
- JSON: https://levelrail.com/templates/postgres-pgweb.json
- Category: Database Tools
- Licence: MIT (Permissive license)
- Source: https://github.com/sosedoff/pgweb
- Upstream docs: https://github.com/sosedoff/pgweb/wiki

## Requirements
- Memory: about 384 MiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 17.11-alpine

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| db | postgres | 17.11-alpine | none | pgdata -> /var/lib/postgresql/data |
| pgweb | sosedoff/pgweb | 0.17.0 | 8081 | none |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| db | POSTGRES_PASSWORD | generated |
| pgweb | PGWEB_DATABASE_URL | generated |

## Deploy

### CLI

```bash
levelrail-cli templates install postgres-pgweb --name my-postgres-pgweb
```

Add --domain SERVICE=HOST to serve a service on your own domain, for example --domain db=app.example.com.

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://levelrail.example.com/api/v1/service-templates/postgres-pgweb/install \
  -d '{
    "name": "my-postgres-pgweb"
  }'
```

Create a token in the dashboard first. Name, env and domains are the request fields.

## First run
1. Open the page, the console is already connected to the bundled database.

## Questions

### Can I deploy PostgreSQL with pgweb 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 PostgreSQL with pgweb, 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:17.11-alpine, sosedoff/pgweb:0.17.0 is what you deploy there.

Self-host PostgreSQL with pgweb, PostgreSQL with pgweb docker compose file, deploy PostgreSQL with pgweb on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
