From 7feff8f45c9191fe27101e520719531574f6d049 Mon Sep 17 00:00:00 2001 From: Andrew Valleteau Date: Thu, 17 Oct 2024 16:34:24 +0200 Subject: [PATCH] fix(docs): self hosting db connection update (#29948) * fix(docs): update self-hosting docs Follow up: https://github.com/supabase/supabase/pull/29596 * chore: add env configurable tenant id --- .../content/guides/self-hosting/docker.mdx | 18 +++++++++++++++--- docker/.env.example | 1 + docker/docker-compose.yml | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/docs/content/guides/self-hosting/docker.mdx b/apps/docs/content/guides/self-hosting/docker.mdx index 026fc05db9f..d45e1886573 100644 --- a/apps/docs/content/guides/self-hosting/docker.mdx +++ b/apps/docs/content/guides/self-hosting/docker.mdx @@ -107,14 +107,25 @@ You can add new Functions as `volumes/functions//index.ts`. Resta ### Accessing Postgres -You can connect to the Postgres database locally on port `5432`. For example, if you have `psql` on your local machine you can run: +By default, the Supabase stack runs the [Supavisor](https://supabase.github.io/supavisor/development/docs/) connection pooler. Supavisor provides efficient management of database connections. + +You can connect to the Postgres database using the following methods: + +1. For session-based connections (equivalent to direct PostgreSQL connections): ```bash -psql -h 127.0.0.1 -p 5432 -d postgres -U postgres +psql 'postgres://postgres.your-tenant-id:your-super-secret-and-long-postgres-password@localhost:5432/postgres' ``` -The default password is `your-super-secret-and-long-postgres-password`. You should change this as soon as possible using the [instructions below](#update-secrets). By default the database is not accessible from outside the local machine. You can [change this](#exposing-your-postgres-database) by updating the `docker-compose.yml` file. +2. For pooled transactional connections: +```bash +psql 'postgres://postgres.your-tenant-id:your-super-secret-and-long-postgres-password@localhost:6543/postgres' +``` + +The default tenant ID is `your-tenant-id`, and the default password is `your-super-secret-and-long-postgres-password`. You should change these as soon as possible using the [instructions below](#update-secrets). + +By default, the database is not accessible from outside the local machine but the pooler is. You can [change this](#exposing-your-postgres-database) by updating the `docker-compose.yml` file. ## Securing your services @@ -145,6 +156,7 @@ Update the `.env` file with your own secrets. In particular, these are required: - `JWT_SECRET`: used by PostgREST and GoTrue, among others. - `SITE_URL`: the base URL of your site. - `SMTP_*`: mail server credentials. You can use any SMTP server. +- `POOLER_TENANT_ID`: the tenant-id that will be used by supavisor pooler for your connection string You will need to [restart](#restarting-all-services) the services for the changes to take effect. diff --git a/docker/.env.example b/docker/.env.example index fb00d7de1b1..f3c5ad067d4 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -25,6 +25,7 @@ POSTGRES_PORT=5432 POOLER_PROXY_PORT_TRANSACTION=6543 POOLER_DEFAULT_POOL_SIZE=20 POOLER_MAX_CLIENT_CONN=100 +POOLER_TENANT_ID=your-tenant-id ############ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 69e61a70a58..6cca5cb04bd 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -470,7 +470,7 @@ services: - METRICS_JWT_SECRET=${JWT_SECRET} - REGION=local - ERL_AFLAGS=-proto_dist inet_tcp - - POOLER_TENANT_ID=your-tenant-id + - POOLER_TENANT_ID=${POOLER_TENANT_ID} - POOLER_DEFAULT_POOL_SIZE=${POOLER_DEFAULT_POOL_SIZE} - POOLER_MAX_CLIENT_CONN=${POOLER_MAX_CLIENT_CONN} - POOLER_POOL_MODE=transaction