Files
supabase/apps/docs/content/guides/database/postgres/postgres-log-config.mdx
Miranda Limonczenko 450939ce86 docs: fix the pages the Option 1 nav friction logs got stuck on (#53881)
Part of DOCS-1739

## Problem

People who tried the Option 1 navigation got stuck on these pages:

- **Slow queries:** readers looked for a way to debug a slow query and
didn't find the guide in the nav. Its title, "Log slow and failing
queries", names the mechanism, not the task.
- **JWT:** The Supabase way to build says Auth "issues a signed JWT"
without saying what a JWT is.
- **Docker self-hosting:** the guide opens with its own contents list,
which repeats the table of contents beside it.
- **Launch readiness:** readers who opened Deploy to production to ask
"am I ready to launch?" found a page about branching and environments.
Neither checklist is linked from it.

## Solution

- **Slow-query title.** The title becomes "Find slow and failing
queries", and the nav label in both navigations becomes "Find slow
queries". The description still says "log slow queries", so search keeps
matching. Five inbound links now use the new title.
- **JWT link.** The first mention reads "JSON Web Token (JWT)" and links
to the JWT guide.
- **Launch intro.** Two sentences near the top of Deploy to production
link the production checklist and the production security checklist.
- **Docker contents list.** The in-page list is gone. Nothing linked to
its anchor.


## Manual testing

1. Open [the slow-query guide on the
preview](https://docs-git-docs-nav-friction-content-supabase.vercel.app/docs/guides/observability/log-slow-queries).
The title reads "Find slow and failing queries", and the sidebar entry
reads "Find slow queries".
2. Open [The Supabase way to
build](https://docs-git-docs-nav-friction-content-supabase.vercel.app/docs/guides/getting-started/the-supabase-way-to-build).
Under Auth, "JSON Web Token (JWT)" links to the JWT guide.
3. Open [Deployment and
branching](https://docs-git-docs-nav-friction-content-supabase.vercel.app/docs/guides/deployment).
The third paragraph links both production checklists.

4. Open [Self-hosting with
Docker](https://docs-git-docs-nav-friction-content-supabase.vercel.app/docs/guides/self-hosting/docker).
The page goes from the intro straight to Before you begin, with no
Contents list.
2026-11-30 11:10:20 -08:00

592 lines
22 KiB
Plaintext

---
id: 'postgres-log-configuration'
title: 'Postgres log configurations'
slug: 'postgres-log-configuration'
description: 'Customizing Postgres log configurations'
subtitle: 'Configure database log settings to better suit your observability and compliance requirements'
---
## Available log settings:
The table lists _configurable_ log settings. See each setting's section for details.
| Setting | Category | Default | Set By |
| :------------------------------------------------------------- | :------------------ | :-------: | :------------ |
| [`log_autovacuum_min_duration`](#logautovacuumminduration) | Background Activity | `10min` | `CLI` |
| [`log_checkpoints`](#logcheckpoints) | Background Activity | `true` | `CLI` |
| [`log_lock_waits`](#loglockwaits) | Background Activity | `true` | `CLI` + `SQL` |
| [`log_recovery_conflict_waits`](#logrecoveryconflictwaits) | Background Activity | `false` | `CLI` |
| [`log_startup_progress_interval`](#logstartupprogressinterval) | Background Activity | `10000ms` | `CLI` |
| [`log_temp_files`](#logtempfiles) | Background Activity | `-1` | `CLI` + `SQL` |
| [`log_connections`](#logconnections) | Network Monitoring | `false` | `CLI` |
| [`log_disconnections`](#logdisconnections) | Network Monitoring | `false` | `CLI` |
| [`cron.log_statement`](#cronlogstatement) | Query Activity | `true` | `CLI` |
| [`auto_explain.*`](#autoexplain) | Query Activity | `10000ms` | `SQL` |
| [`log_duration`](#logduration) | Query Activity | `false` | `SQL` |
| [`log_min_duration_statement`](#logmindurationstatement) | Query Activity | `-1` | `SQL` |
| [`log_min_error_statement`](#logminerrorstatement) | Query Activity | `error` | `SQL` |
| [`log_min_messages`](#logminmessages) | Query Activity | `warning` | `SQL` |
| [`log_statement`](#logstatement) | Query Activity | `ddl` | `SQL` |
| [`pgaudit.*`](#pgaudit) | Query Activity | `N/A` | `SQL` |
To view log settings for your project, you can run:
```sql
select
name,
setting,
unit,
short_desc,
extra_desc,
context,
enumvals,
reset_val,
case
when sourcefile = '/etc/postgresql-custom/custom-overrides.conf' then 'set by CLI/API'
else 'platform default'
end as configuration_source
from "pg_settings"
where
category in ('Reporting and Logging / When to Log', 'Reporting and Logging / What to Log')
or (name like 'auto_explain.%' or name like 'pgaudit.%' or name = 'cron.log_statement');
```
To view settings targeting specific database roles, you can run:
```sql
select
rolname,
rolconfig
from pg_roles
where
rolname in (
'anon',
'authenticated',
'postgres',
'service_role'
-- ,<ANY CUSTOM ROLES>
);
```
## Configuring log settings
There are two potential ways to change log settings:
- [Supabase CLI](/docs/guides/local-development/cli/getting-started)
- **SQL commands**
<details>
<summary>Configure with the CLI</summary>
Install the [Supabase CLI](/docs/guides/local-development/cli/getting-started) then update the relevant setting:
```sh
supabase --experimental \
postgres-config update --config log_lock_waits=true \
--remote=<project-ref>
```
To remove overrides, you can run:
```sh
supabase --experimental \
postgres-config delete --config log_lock_waits,log_disconnections,... \
--remote=<project-ref>
```
</details>
<details>
<summary>Configure with SQL</summary>
<Admonition type="caution">
Log settings configured directly with SQL take precedence over values set by the Management API and CLI.
</Admonition>
Supabase projects include the [supautils extension](/blog/roles-postgres-hooks), which grants the postgres role authority over superuser-only log settings.
As a result, you can configure _certain_ log settings directly with SQL at the `role` and `connection` levels:
```sql
-- impacts the role
alter role postgres set log_statement = 'none';
-- impacts just the live connection
set log_statement = 'none';
```
To remove a role level override, you can reset the value with the `default` keyword:
```sql
alter role postgres set log_statement = default;
```
<Admonition type="note">
When updating log settings for Data API roles (anon, authenticator, or service_role), reload PostgREST to apply the changes:
```sql
NOTIFY pgrst, 'reload config';
```
</Admonition>
</details>
## Background activity
Logs the activity of Postgres background processes and utilities. Helps diagnose and detect performance and operational issues.
### `log_autovacuum_min_duration`
`update` and `delete` commands leave behind obsolete row versions to support rollbacks and concurrent queries. A background process called the [Autovacuum](https://www.postgresql.org/docs/current/routine-vacuuming.html#AUTOVACUUM) permanently removes the rows in batch jobs at a later point. The setting logs Autovacuum when they run longer than the limit.
**Useful for:**
- Monitoring vacuum activity
- Identifying resource strain, such as [IO usage](/docs/guides/platform/manage-your-usage/disk-iops), caused by vacuums
**Example logs:**
```sh
# records tables vacuumed
automatic vacuum of table "postgres.public.vac_test": index scans: 0
automatic analyze of table "postgres.public.vac_test"
```
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_autovacuum_min_duration=10ms \
--remote=<project-ref>
```
</details>
### `log_checkpoints`
Checkpoints are background operations that write modified data from memory to disk. It enables Postgres to discard [WAL files](/docs/guides/database/replication#write-ahead-log-wal) that otherwise must be retained for data recovery and replication.
The setting records automatic checkpoint events.
**Useful for:**
- Measuring checkpoint write volume
- Identifying excessive checkpoint-related disk activity
- Detecting read-replica issues
- Deciding whether checkpoint settings should be adjusted
**Example logs:**
```sh
# Monitoring checkpointer activity
checkpoint starting: time
checkpoint complete: wrote 405563 buffers (6.4%); 0 WAL file(s) added, 0 removed, 465 recycled; write=269.656 s, sync=3.570 s, total=274.133 s; sync files=2393, longest=0.375 s, average=0.002 s; distance=6635965 kB, estimate=7953512 kB
```
```sh
# Monitoring replay activity from read replicas
restartpoint starting: time
recovery restart point at 0/B837D6F0
restartpoint complete: wrote 266 buffers (0.4%); 0 WAL file(s) added, 1 removed, 0 recycled; write=25.760 s, sync=0.004 s, total=25.773 s; sync files=20, longest=0.003 s, average=0.001 s; distance=19779 kB, estimate=565114 kB; lsn=0/B837D748, redo lsn=0/B837D6F0
```
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_checkpoints=true \
--remote=<project-ref>
```
</details>
### `log_lock_waits`
Logs when operations are blocked by database locks for more than `1s`. For more information on lock management, reference [postgreslocksexplained.com](https://postgreslocksexplained.com/locks/concept).
**Useful for:**
- Identifying queries that are blocked by locks
- Identifying which queries are blocking
- Measuring how long queries remain blocked
**Example logs:**
```sh
# records when a process is waiting on a lock for 1+s
process 1017208 still waiting for "lock_type" on relation 75874 of database 5 after 1001.872 ms
```
```sh
# records when a process is finally able to claim its lock
process 1007982 acquired "lock_type" on transaction 445264 after 2000.880 ms
```
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_lock_waits=true \
--remote=<project-ref>
```
```sql name=SQL
alter role "postgres" set log_lock_waits to true;
```
</details>
### `log_recovery_conflict_waits`
If a read-replica is acting on data that is being modified/discarded by the primary, then it may wait to determine if the data should be available or not before responding. The setting `log_recovery_conflict_waits` determines if the replica should report waits that last more than `1s`.
**Useful for:**
- Detecting operations that interfere with replica queries
- Detecting operations that may cause replication lag
**Example log:**
```sh
recovery still waiting after 1000.156 ms: recovery conflict on lock
```
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_recovery_conflict_waits=true \
--remote=<project-ref>
```
</details>
### `log_startup_progress_interval`
When a server is recovering from a crash, it has to go through several checks before it becomes operational again. To provide more clarity about a recovery's progress, the setting causes Postgres to log its current startup task if it takes longer than the interval.
**Useful for:**
- Determining if a server is responsive during startup/recovery
**Example log:**
```sh
syncing data directory (pre-fsync), elapsed time: 0.00 s, current path: ./base/4/13456
```
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_startup_progress_interval=1s \
--remote=<project-ref>
```
</details>
### `log_temp_files`
Some queries require sorting, hashing, or other memory-intensive operations. When these operations exceed the memory limits primarily managed by the [work_mem](https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM) and [hash_mem_multiplier](https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-HASH-MEM-MULTIPLIER) settings, Postgres uses temporary files on disk to complete them.
When temp files larger than the `log_temp_files` limit are created, Postgres logs the event, helping identify queries that can benefit from memory tuning.
**Useful for:**
- Determining when the memory constraint settings should be adjusted
- Identifying disk strain caused by temp files
**Example log:**
```sh
# records the creation of a temp file that is 8.33MB in size
temporary file: path "base/pgsql_tmp/pgsql_tmp306918.0", size 8331264
```
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_temp_files=10MB \
--remote=<project-ref>
```
```sql name=SQL
alter role "postgres" set "log_temp_files" to '10kB';
```
</details>
## Network monitoring
Logs information about clients connecting/disconnecting from the database. Some insightful values that can be captured include:
- When a client first authenticated
- How long they were connected for
- Their IP address
### `log_connections`
Logs when a client establishes a new database connection, including connection receipt, authentication, and authorization.
**Useful for:**
- Monitoring successful authentication attempts
- Auditing database access
**Example logs:**
```sh
connection received: host=127.0.0.1
connection authorized: user=postgres database=postgres application_name=Supavisor auth_query
connection authenticated: identity="pgbouncer" method=scram-sha-256
```
<Admonition type="note">
The logged IP address is from the device directly communicating with Postgres. If you connect through the [shared pooler](/docs/guides/database/connecting-to-postgres/pooling-and-limits#shared-pooler), the [dedicated pooler](/docs/guides/database/connecting-to-postgres#dedicated-pooler), or the [Data API](/docs/guides/database/connecting-to-postgres#data-apis-and-client-libraries), those service IPs will appear instead of the original client.
</Admonition>
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_connections=true \
--remote=<project-ref>
```
</details>
### `log_disconnections`
Logs when a database connection gracefully closes.
**Useful for:**
- Monitoring how long connections persist
**Example log:**
```sh
disconnection: session time: 0:00:01.492 user=postgres database=postgres host=127.0.0.1
```
<Admonition type="note">
The logged IP address is from the device directly communicating with Postgres. If you connect through the [shared pooler](/docs/guides/database/connecting-to-postgres/pooling-and-limits#shared-pooler), the [dedicated pooler](/docs/guides/database/connecting-to-postgres#dedicated-pooler), or the [Data API](/docs/guides/database/connecting-to-postgres#data-apis-and-client-libraries), those service IPs will appear instead of the original client.
</Admonition>
<details>
<summary>Configuration examples</summary>
```sh name=CLI
supabase --experimental \
postgres-config update --config log_disconnections=true \
--remote=<project-ref>
```
</details>
## Query activity
<Admonition type="caution">
Logging a large amount of query activity can impact query performance and increase logging costs. Configure them with caution for debugging or mandatory compliance.
</Admonition>
Records queries or metadata about queries.
### `cron.log_statement`
Logs when the [pg_cron extension](/docs/guides/cron/install) starts a cron job.
**Useful for:**
- Monitoring successful cron job executions
**Example log:**
```sh
cron job 1 starting: select 1
```
<Admonition type="note">
Beyond logs, [pg_cron](/docs/guides/cron/install) also records all cron executions in the [`cron.job_run_details`](https://github.com/citusdata/pg_cron#monitoring-jobs) table. Consider disabling `cron.log_statement` to instead monitor cron activity only in `cron.job_run_details` instead.
</Admonition>
<details>
<summary>Configuration examples</summary>
<Admonition type="caution">
`cron.log_statement` requires a server restart to take effect, which results in a few seconds of downtime.
By default, the API and CLI automatically trigger a restart when updating this setting. The examples below use the `--no-restart` flag to defer the change until the server is restarted at a later time.
</Admonition>
```sh name=CLI
supabase --experimental \
postgres-config update --config cron.log_statement=false --no-restart \
--remote=<project-ref>
```
</details>
### `auto_explain.*`
Logs the query plan of each statement that runs longer than a threshold. To set it up, see [Find slow and failing queries](/docs/guides/observability/log-slow-queries).
### `log_duration`
It logs the duration of all queries, but not the queries themselves.
**Useful for:**
- Monitoring query duration
**Example log:**
```sh
duration: 0.599 ms
```
Note, even though the query will not be logged, the primary command associated with the query will be recorded in the `command` subfield:
```sh
...other subfields
command_tag: "SELECT"
```
<details>
<summary>Configuration examples</summary>
```sql name=SQL
alter role "postgres" set "log_duration" to true;
```
</details>
### `log_min_duration_statement`
Logs each statement that runs longer than a threshold. To set it up, see [Find slow and failing queries](/docs/guides/observability/log-slow-queries).
### `log_min_error_statement`
Records the statement behind each error, and is on by default. To find that statement in your logs, see [Find slow and failing queries](/docs/guides/observability/log-slow-queries).
### `log_min_messages`
Determines what _query generated_ logs (not background or networking logs) are recorded based on severity level, as described in the table below.
As an example of how `log_min_messages` works, if the setting were changed to `error`, Postgres would stop recording logs with the severity levels `warning`, `notice`, `info`, and `debug1 ... debug5` events. However, it would continue recording all `error`, `log`, `fatal`, and `panic` occurrences.
| Severity | Description | Example log |
| :-------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **debug1 ... debug5** | Successively detailed debugging and server info, predominantly used by Postgres developers and extension maintainers. | `DEBUG1: rehashing catalog cache id 6...` |
| **info** | Information explicitly requested by the user during an operation. | `INFO: analyzing "public.example..."` <br/><br/> Example returned by the [`analyze verbose`](https://www.postgresql.org/docs/current/sql-analyze.html) command |
| **notice** | Helpful, non-essential information about automatic background actions. | `NOTICE: table "old_logs" does not exist, skipping` <br/><br/> Example returned by the [`drop table if exists`](https://www.postgresql.org/docs/current/sql-droptable.html) commands |
| **warning** | A query completed, but skipped requested actions. | `WARNING: no privileges were granted for "some_user"` <br/><br/> Example returned by the [`grant`](https://www.postgresql.org/docs/current/sql-grant.html) command |
| **error** | A specific query failed, but the overall database connection remains alive. | `ERROR: duplicate key value violates unique constraint "example_pkey"` |
| **log** | Operational events. Usually generated by [background activity log settings](/docs/guides/database/postgres/postgres-log-config#background-activity) or by [database functions](/docs/guides/database/debugging-functions) | `LOG: connection received...` |
| **fatal** | An error that causes a database connection to abruptly terminate. | `FATAL: terminating connection due to administrator command` |
| **panic** | A critical, system-wide failure that forces the database to shut down and crash-recover. | `PANIC: could not locate a valid checkpoint record at 0/61013608` |
<Admonition type="note">
Note: `log` is considered more severe than `warning` and `error`.
</Admonition>
**Useful for:**
- Controlling what _query generated logs_ are recorded overall
<details>
<summary>Configuration examples</summary>
```sql name=SQL
alter role "postgres" set "log_min_messages" to 'log';
```
</details>
### `log_statement`
<Admonition type="caution">
To avoid excessive logging that can impact performance, be mindful of the potential impact when configuring log_statement to `mod` or `all`. Consider using [`pgaudit`](#pgaudit) over `log_statement` for more granular control over query logging.
</Admonition>
Logs queries that match the configured action type:
- `ddl`: Log all `alter`, `drop`, and `create` commands
- `all`: Log all queries
- `mod`: Log `update`, `insert`, `delete`, and `merge` commands
- `none`: Log nothing (disables the setting)
**Useful for:**
- Monitoring queries on your platform
**Example log:**
```sh
# Logging a select query
statement: select * from testing WHERE id = 5 limit 100;
```
<details>
<summary>Configuration examples</summary>
```sql name=SQL
alter role "postgres" set "log_statement" to 'ddl';
```
</details>
### `pgaudit.*`
A suite of log settings enabled by the [pgAudit extension](/docs/guides/database/extensions/pgaudit). Unlike `log_statement`, it allows you to monitor queries against specific tables, with a higher degree of granularity.
**Useful for:**
- Monitoring queries on your platform
**Example log:**
```sh
# Logging a DDL query
AUDIT: SESSION,1,1,DDL,CREATE TABLE,TABLE,public.account,create table account(
id int,
name text,
description text
); <not logged>
```
**Configuration methods:**
Review the [pgAudit docs](/docs/guides/database/extensions/pgaudit) for more configuration details.
## Resources
- [Advanced Log Filtering](/docs/guides/observability/advanced-log-filtering)
- [Database Function Logging](/docs/guides/database/debugging-functions#general-logging)
- [Supabase Logging](/docs/guides/observability/logs)