You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pgflow auto-detects your database connection in local development and requires minimal configuration for production. This guide explains how connection detection works and how to configure it for different environments.
11
11
12
12
## Connection Priority
13
13
14
14
When an Edge Worker starts, pgflow resolves the database connection using this priority chain:
15
15
16
-
| Priority | Source | Use Case |
17
-
|----------|--------|----------|
18
-
| 1 |`config.sql`| Full postgres.js control (SSL, custom options) |
| 3 |`EDGE_WORKER_DB_URL`| Production environment variable|
21
+
| 4 | Local fallback | Supabase local development (automatic)|
22
22
23
23
If none of these are available, the worker throws an error: `"No database connection available"`.
24
24
25
25
<Asidetype="note"title="Explicit config wins">
26
-
Providing `config.sql`, `config.connectionString`, or `EDGE_WORKER_DB_URL`**skips the automatic local connection**. The local fallback only applies when no explicit configuration is provided.
26
+
Providing `config.sql`, `config.connectionString`, or `EDGE_WORKER_DB_URL`
27
+
**skips the automatic local connection**. The local fallback only applies when
28
+
no explicit configuration is provided.
27
29
</Aside>
28
30
29
31
## Local Development
30
32
31
33
When running locally with `supabase start`, pgflow automatically connects to your database without any configuration needed.
<Asidetype="note"title="How local connections work">
42
-
pgflow recognizes local Supabase environments by checking for known local dev credentials in environment variables. When running locally, it connects to the Docker pooler at `postgresql://postgres.localhost:postgres@127.0.0.1:54329/postgres`.
44
+
pgflow recognizes local Supabase environments by checking for known local dev
45
+
credentials in environment variables. When running locally, it connects to the
@@ -50,11 +55,18 @@ For production, set the `EDGE_WORKER_DB_URL` secret in your Supabase project:
50
55
npx supabase secrets set EDGE_WORKER_DB_URL="postgresql://postgres.pooler-yourproject:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres"
51
56
```
52
57
58
+
<Asidetype="note"title="Self-hosted Supabase">
59
+
Self-hosted instances do not auto-configure `EDGE_WORKER_DB_URL`. You must set
60
+
it explicitly in your Edge Function environment. See the [Self-Hosted Supabase
61
+
guide](/deploy/supabase/self-hosted/) for the connection string format for
62
+
your pooler.
63
+
</Aside>
64
+
53
65
Your worker code stays the same - pgflow automatically uses the environment variable when not in local development:
For advanced scenarios requiring SSL certificates or other postgres.js settings, create the SQL client yourself and pass it via `config.sql`. Note that `prepare: false` is required when using a transaction pooler:
This guide walks you through deploying pgflow workers to Supabase.com. Workers run as Edge Functions that poll for tasks, execute your flow handlers, and report results back to the database.
11
18
12
19
Before starting, ensure you have completed [Getting Started](/get-started/installation/) and have a Supabase project linked to your local environment.
13
20
21
+
<Asidetype="tip"title="Self-hosted Supabase?">
22
+
Running Supabase on your own infrastructure? See the [Self-Hosted Supabase
23
+
guide](/deploy/supabase/self-hosted/) for specific setup instructions
24
+
including Postgres image upgrades and database connection configuration.
This guide is based on community feedback in [GitHub Issue #616](https://github.com/pgflow-dev/pgflow/issues/616).
12
+
:::
13
+
14
+
This guide covers running pgflow on self-hosted Supabase instances. Self-hosted deployments differ from Supabase.com in several ways this guide addresses.
15
+
16
+
## Requirements
17
+
18
+
Before running pgflow on self-hosted Supabase, ensure you have:
19
+
20
+
-**pgmq 1.5.0+** - Required for pgflow. May require upgrading your Supabase Postgres image.
21
+
-**Connection pooler enabled** - Supavisor must be running and accessible to Edge Functions.
22
+
-**Manual pgflow setup** - Since the Supabase CLI doesn't work with self-hosted, follow the [Manual Installation guide](/reference/manual-installation/) to set up migrations and functions.
23
+
24
+
## Upgrade Postgres Image
25
+
26
+
The default Supabase docker image may ship with an older pgmq version. If you see errors related to missing `pgmq` functions after installing pgflow migrations, upgrade your Postgres image.
27
+
28
+
In your `docker/docker-compose.yml`, update the `db` service image:
29
+
30
+
```yaml
31
+
db:
32
+
image: supabase/postgres:15.14.1.098
33
+
```
34
+
35
+
<Aside type="tip">
36
+
A known working version for the 15.x branch is `15.14.1.098`. PostgreSQL 17 is
37
+
also supported (v17.6.1.100 or later).
38
+
</Aside>
39
+
40
+
After updating, restart your containers:
41
+
42
+
```bash frame="none"
43
+
docker compose down
44
+
docker compose up -d
45
+
```
46
+
47
+
## Database Connection
48
+
49
+
Self-hosted Supabase does not auto-configure `EDGE_WORKER_DB_URL`. You must set this environment variable explicitly on your Edge Functions.
50
+
51
+
The connection string format for self-hosted Supabase:
- `POOLER_TENANT_ID`- Your pooler tenant ID (set in your `.env` file)
60
+
- `POSTGRES_PASSWORD`- Your Postgres password
61
+
- `POOLER_PROXY_PORT_TRANSACTION` - The transaction pooler port (default: `6543`)
62
+
63
+
<Aside type="note">
64
+
The hostname is `supavisor` (not `pooler` which is used by the Supabase CLI
65
+
local development environment).
66
+
</Aside>
67
+
68
+
Set this environment variable in your Edge Function deployment configuration. See [Database Connection](/deploy/database-connection/) for all connection options including SSL configuration.
69
+
70
+
## Function Deployment
71
+
72
+
The Supabase CLI is designed for Supabase.com and local development. For self-hosted deployments, deploy Edge Functions manually:
73
+
74
+
<Steps>
75
+
1. Copy your function directories to `./volumes/functions/` in your Supabase project
76
+
77
+
2. Mount the volumes in your `docker-compose.yml` under the `functions` service
78
+
79
+
3. Ensure your flows are also accessible (either in the functions volume or a separate mounted volume)
80
+
81
+
4. Restart the Edge Functions container
82
+
</Steps>
83
+
84
+
### Docker Compose Changes
85
+
86
+
Apply these changes to your `docker/docker-compose.yml`:
0 commit comments