mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Docs update. Restructure, mostly moved lines, plus inbound anchor fixes. ## What is the current behavior? The page states the same routing decision four times and never states an answer: - Intro bullets - A matrix table - A "How to choose the right connection method?" section - A Mermaid flowchart An agent asked "I'm deploying to Vercel serverless functions, set up the database connection" has to synthesize an answer from four partial, inconsistent restatements. Context, procedure, and reference material are interleaved throughout, so background reading interrupts the action path. The page is also too long at 2,883 words, and grouping alone doesn't fix that. Explainer and reference material need their own page, and the troubleshooting group belongs in troubleshooting entries. 16 of the 19 inbound anchor links to this page are already broken on `master`, before any restructure: `#direct-connections`, `#shared-pooler`, `#connection-pooler`, `#how-connection-pooling-works`, `#quick-summary`, `#connection-pool`, and `#connecting-with-drizzle`. Groundwork for [DOCS-1312](https://linear.app/supabase/issue/DOCS-1312). The issue stays open until the paired eval is re-run. ## What is the new behavior? Group the guide into a decision, a procedure, context, reference, and troubleshooting, per CONTRIBUTING § Guides on mixed information types. Review with `git diff --color-moved=zebra`. - Lead with "Which connection method do you use?", a decision table keyed on where your code runs. Section navigation sits directly below the intro. - Collect every connection string under "Get your connection string", with the shared Connect dialog steps stated once as a procedure. - Move the endpoint, port, pool size, and connection limit material into "Connection reference". These were FAQ questions. - Split the page. The guide keeps the decision, the connection strings, and the quickstarts, at 1,180 words and three paths. A new child page, Connection pooling and limits, carries how pooling works, pool size, connection limits, and monitoring. - Move the endpoint and IP version table up beside the connection strings it explains. - Replace the troubleshooting group with two new troubleshooting entries, `tenant-or-user-not-found` and `fatal-password-authentication-failed`, plus links to the existing entries. The existing connection-refused entry is stronger than what was here: it names the IP ban and gives the unban procedure. - Cut the pool size worked example. It said a pool size of 30 is a shared ceiling across session and transaction mode, while the Supavisor FAQ and the terminology entry both say pool size is per user, database, and mode combination. That text came from `master`, so the contradiction is pre-existing. Link the FAQ as the authority rather than picking a side. - Drop the duplicate `pg_stat_ssl` query, which already exists in `connection-management.mdx` and `monitor-supavisor-postgres-connections.mdx`, both with column tables this page lacked. - Add the subsection to the navigation, which also adopts `connecting-to-postgres/serverless-drivers`. That page existed on disk and was referenced nowhere in the navigation constants. - Delete the decision flowchart. It was the fourth restatement of the decision table, and its logic was broken: `Persistent Backend` had two unconditional edges into decision nodes that each had one unlabeled output, so neither node decided anything. - Fix every broken inbound anchor, and pin stable anchors on the headings they target. This now includes six files in `apps/www` that no earlier pass in this stack checked, most of which were already broken on `master`. - Repoint the Studio Connect sheet's Drizzle link at the Drizzle guide. It pointed at a heading this page hasn't had for some time. - Serverless drivers: state the guide's intent, give the three runtimes parallel structure, and link the transaction mode prepared statements constraint. That page never mentioned the constraint that most affects serverless connections. ## Additional context PR 2 of 2. Base is #49868, rebased on its review feedback commit. Three of the 13 files are in `apps/studio`, so this runs the Studio unit tests, build, and lint ratchet. They are link string changes only. The ESLint warning count is unchanged at 1 on the touched files, so the ratchet holds. ## Manual testing 1. Open [Connect to your database](https://docs-git-docs-connecting-to-postgres-structure-supabase.vercel.app/docs/guides/database/connecting-to-postgres) on the deploy preview. 2. Check the table of contents. The top level reads: Which connection method do you use?, Get your connection string, Quickstarts, Related. The intro lists three paths. 3. Open [Reports](https://docs-git-docs-connecting-to-postgres-structure-supabase.vercel.app/docs/guides/monitoring-and-debugging/reports) and follow "Implement connection pooling" under Disk IO. It lands on the decision table. 4. Open [Serverless drivers](https://docs-git-docs-connecting-to-postgres-structure-supabase.vercel.app/docs/guides/database/connecting-to-postgres/serverless-drivers). The intro links the transaction mode prepared statements constraint. 5. Check the sidebar. Connecting to your database expands to Connection pooling and limits and Serverless drivers. 6. Open [Connection pooling and limits](https://docs-git-docs-connecting-to-postgres-structure-supabase.vercel.app/docs/guides/database/connecting-to-postgres/pooling-and-limits). Pool size states the setting and links the Supavisor FAQ, with no worked example. 7. Open [Tenant or user not found](https://docs-git-docs-connecting-to-postgres-structure-supabase.vercel.app/docs/guides/troubleshooting/tenant-or-user-not-found). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a dedicated guide covering connection pooling, limits, configuration, and monitoring. * Added troubleshooting guides for password authentication failures and shared pooler tenant or user errors. * Expanded connection guidance with method selection, endpoints, IP versions, and serverless driver configuration. * **Documentation** * Reorganized database connection documentation and navigation. * Updated related links throughout the documentation to current connection and pooling guidance. * Improved guidance for pooler modes, connection strings, and supported deployment environments. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
181 lines
5.8 KiB
Plaintext
181 lines
5.8 KiB
Plaintext
---
|
|
title: Timeouts
|
|
subtitle: Extend database timeouts to execute longer transactions
|
|
---
|
|
|
|
<Admonition type="note">
|
|
|
|
Dashboard and [Client](/docs/guides/api/rest/client-libs) queries have a max-configurable timeout of 60 seconds. For longer transactions, use [Supavisor or direct connections](/docs/guides/database/connecting-to-postgres#choose-a-connection-method).
|
|
|
|
</Admonition>
|
|
|
|
## Change Postgres timeout
|
|
|
|
You can change the Postgres timeout at the:
|
|
|
|
1. [Session level](#session-level)
|
|
1. [Function level](#function-level)
|
|
1. [Global level](#global-level)
|
|
1. [Role level](#role-level)
|
|
|
|
### Session level
|
|
|
|
Session level settings persist only for the duration of the connection.
|
|
|
|
Set the session timeout by running:
|
|
|
|
```sql
|
|
set statement_timeout = '10min';
|
|
```
|
|
|
|
Because it applies to sessions only, it can only be used with connections through Supavisor in session mode (port 5432) or a direct connection. It cannot be used in the Dashboard, with the Supabase Client API, nor with Supavisor in Transaction mode (port 6543).
|
|
|
|
This is most often used for single, long running, administrative tasks, such as creating an HSNW index. Once the setting is implemented, you can view it by executing:
|
|
|
|
```sql
|
|
SHOW statement_timeout;
|
|
```
|
|
|
|
See the full guide on [changing session timeouts](https://github.com/orgs/supabase/discussions/21133).
|
|
|
|
### Function level
|
|
|
|
This works with the Database REST API when called from the Supabase client libraries:
|
|
|
|
```sql
|
|
create or replace function myfunc()
|
|
returns void as $$
|
|
select pg_sleep(3); -- simulating some long-running process
|
|
$$
|
|
language sql
|
|
set statement_timeout TO '4s'; -- set custom timeout
|
|
```
|
|
|
|
This is mostly for recurring functions that need a special exemption for runtimes.
|
|
|
|
### Role level
|
|
|
|
This sets the timeout for a specific role.
|
|
|
|
The default role timeouts are:
|
|
|
|
- `anon`: 3s
|
|
- `authenticated`: 8s
|
|
- `service_role`: none (defaults to the `authenticator` role's 8s timeout if unset)
|
|
- `postgres`: none (capped by default global timeout to be 2min)
|
|
|
|
Run the following query to change a role's timeout:
|
|
|
|
```sql
|
|
alter role example_role set statement_timeout = '10min'; -- could also use seconds '10s'
|
|
```
|
|
|
|
<Admonition type="note">
|
|
|
|
If you are changing the timeout for the Supabase Client API calls, you will need to reload PostgREST to reflect the timeout changes by running the following script:
|
|
|
|
```sql
|
|
NOTIFY pgrst, 'reload config';
|
|
```
|
|
|
|
</Admonition>
|
|
|
|
Unlike global settings, the result cannot be checked with `SHOW
|
|
statement_timeout`. Instead, run:
|
|
|
|
```sql
|
|
select
|
|
rolname,
|
|
rolconfig
|
|
from pg_roles
|
|
where
|
|
rolname in (
|
|
'anon',
|
|
'authenticated',
|
|
'postgres',
|
|
'service_role'
|
|
-- ,<ANY CUSTOM ROLES>
|
|
);
|
|
```
|
|
|
|
### Global level
|
|
|
|
This changes the statement timeout for all roles and sessions without an explicit timeout already set.
|
|
|
|
```sql
|
|
alter database postgres set statement_timeout TO '4s';
|
|
```
|
|
|
|
Check if your changes took effect:
|
|
|
|
```sql
|
|
show statement_timeout;
|
|
```
|
|
|
|
Although not necessary, if you are uncertain if a timeout has been applied, you can run a quick test:
|
|
|
|
```sql
|
|
create or replace function myfunc()
|
|
returns void as $$
|
|
select pg_sleep(601); -- simulating some long-running process
|
|
$$
|
|
language sql;
|
|
```
|
|
|
|
## Identifying timeouts
|
|
|
|
The Supabase Dashboard contains tools to help you identify timed-out and long-running queries.
|
|
|
|
### Using the SQL Editor
|
|
|
|
Go to the [SQL Editor](/dashboard/project/_/sql/new?skip=true&source=logs), set the query source to **Logs**, and run the following query to identify timed-out events (`statement timeout`) and queries that successfully run for longer than 10 seconds (`duration`).
|
|
|
|
```sql
|
|
select
|
|
timestamp,
|
|
event_message,
|
|
log_attributes['parsed.error_severity'] as error_severity,
|
|
log_attributes['parsed.user_name'] as user_name,
|
|
log_attributes['parsed.query'] as query,
|
|
log_attributes['parsed.detail'] as detail,
|
|
log_attributes['parsed.hint'] as hint,
|
|
log_attributes['parsed.sql_state_code'] as sql_state_code,
|
|
log_attributes['parsed.backend_type'] as backend_type
|
|
from logs
|
|
where
|
|
source = 'postgres_logs'
|
|
and match(event_message, 'duration|statement timeout')
|
|
-- (OPTIONAL) MODIFY OR REMOVE
|
|
and log_attributes['parsed.user_name'] = 'authenticator' -- <--------CHANGE
|
|
order by timestamp desc
|
|
limit 100;
|
|
```
|
|
|
|
### Using the Query Performance page
|
|
|
|
Go to the [Query Performance page](/dashboard/project/_/advisors/query-performance?preset=slowest_execution) and filter by relevant role and query speeds. This only identifies slow-running but successful queries. Unlike the logs, it does not show you timed-out queries.
|
|
|
|
### Understanding roles in logs
|
|
|
|
Each API server uses a designated user for connecting to the database:
|
|
|
|
| Role | API/Tool |
|
|
| ---------------------------- | ------------------------------------------------------------------------- |
|
|
| `supabase_admin` | Used by Realtime and for project configuration |
|
|
| `authenticator` | PostgREST |
|
|
| `supabase_auth_admin` | Auth |
|
|
| `supabase_storage_admin` | Storage |
|
|
| `supabase_replication_admin` | Synchronizes Read Replicas |
|
|
| `postgres` | Supabase Dashboard and External Tools (e.g., Prisma, SQLAlchemy, PSQL...) |
|
|
| Custom roles | External Tools (e.g., Prisma, SQLAlchemy, PSQL...) |
|
|
|
|
Filter by the `parsed.user_name` field to only retrieve logs made by specific users:
|
|
|
|
```sql
|
|
-- find events based on role/server
|
|
... query
|
|
where
|
|
-- find events from the relevant role
|
|
log_attributes['parsed.user_name'] = '<ROLE>'
|
|
```
|