Database

Customizing Postgres configs


Each Supabase project is a pre-configured Postgres cluster. You can override some configuration settings to suit your needs. This is an advanced topic, and we don't recommend touching these settings unless it is necessary.

Viewing settings

To list all Postgres settings and their descriptions, run:

1
select * from pg_settings;

Configurable settings

User-context settings

The pg_settings table's context column specifies the requirements for changing a setting. By default, those with a user context can be changed at the role or database level with SQL.

To list all user-context settings, run:

1
select * from pg_settings where context = 'user';

As an example, the statement_timeout setting can be altered:

1
alter database "postgres" set "statement_timeout" TO '60s';

To verify the change, execute:

1
show "statement_timeout";

Superuser settings

Some settings can only be modified by a superuser. Supabase pre-enables the supautils extension, which allows the postgres role to retain certain superuser privileges. It enables modification of the below reserved configurations at the role level:

SettingDescription
auto_explain.*Configures the auto_explain module. Can be configured to log execution plans for queries expected to exceed x seconds, including function queries.
log_lock_waitsControls whether a log message is produced when a session waits longer than deadlock_timeout to acquire a lock.
log_min_duration_statementCauses the duration of each completed statement to be logged if the statement ran for at least the specified amount of time.
log_min_messagesMinimum severity level of messages to log.
log_replication_commandsLogs all replication commands
log_statementControls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements).
log_temp_filesControls logging of temporary file names and sizes.
pg_net.ttlSets how long the pg_net extension saves responses
pg_net.batch_sizeSets how many requests the pg_net extension can make per second
pg_stat_statements.*Configures the pg_stat_statements extension.
pgaudit.*Configures the PGAudit extension. The log_parameter is still restricted to protect secrets
pgrst.*PostgREST settings
plan_filter.*Configures the pg_plan_filter extension
session_replication_roleSets the session's behavior for triggers and rewrite rules.
track_io_timingCollects timing statistics for database I/O activity.
wal_compressionThis parameter enables compression of WAL using the specified compression method.

For example, to enable log_nested_statements for the postgres role, execute:

1
alter role "postgres" set "auto_explain.log_nested_statements" to 'on';

To view the change:

1
select
2
rolname,
3
rolconfig
4
from pg_roles
5
where rolname = 'postgres';

CLI configurable settings

While many Postgres parameters are configurable directly, some configurations can be changed with the Supabase CLI at the system level.

CLI supported parameters

The following parameters are available for overrides:

Use the examples below with supabase --experimental --project-ref <project-ref> postgres-config update:

ParameterTypeRestartExample
checkpoint_timeoutCLI onlyNo--config checkpoint_timeout=15min
effective_cache_sizeCLI + SQLNo--config effective_cache_size=8GB
hot_standby_feedbackCLI onlyNo--config hot_standby_feedback=true
logical_decoding_work_memCLI + SQLNo--config logical_decoding_work_mem=128MB
maintenance_work_memCLI + SQLNo--config maintenance_work_mem=512MB
max_connections (Be aware of these considerations)CLI onlyYes--config max_connections=200
max_locks_per_transactionCLI onlyYes--config max_locks_per_transaction=128
max_parallel_maintenance_workersCLI + SQLNo--config max_parallel_maintenance_workers=2
max_parallel_workers_per_gatherCLI + SQLNo--config max_parallel_workers_per_gather=2
max_parallel_workersCLI + SQLNo--config max_parallel_workers=4
max_replication_slotsCLI onlyYes--config max_replication_slots=10
max_slot_wal_keep_sizeCLI onlyNo--config max_slot_wal_keep_size=4GB
max_standby_archive_delayCLI onlyNo--config max_standby_archive_delay=30s
max_standby_streaming_delayCLI onlyNo--config max_standby_streaming_delay=30s
max_wal_sizeCLI onlyNo--config max_wal_size=2GB
max_wal_sendersCLI onlyYes--config max_wal_senders=10
max_worker_processesCLI onlyYes--config max_worker_processes=8
session_replication_roleCLI onlyNo--config session_replication_role=replica
shared_buffersCLI onlyYes--config shared_buffers=256MB
statement_timeoutCLI + SQLNo--config statement_timeout=60s
track_activity_query_sizeCLI onlyYes--config track_activity_query_size=2048B
track_commit_timestampCLI onlyYes--config track_commit_timestamp=true
wal_keep_sizeCLI onlyNo--config wal_keep_size=1GB
wal_sender_timeoutCLI onlyNo--config wal_sender_timeout=60s
work_memCLI + SQLNo--config work_mem=64MB

Managing Postgres configuration with the CLI

To start:

  1. Install Supabase CLI 1.69.0+.
  2. Log in to your Supabase account using the CLI.

To update Postgres configurations, use the postgres config command:

1
supabase --experimental \
2
--project-ref <project-ref> \
3
postgres-config update --config shared_buffers=250MB

By default, the CLI will merge any provided config overrides with any existing ones. The --replace-existing-overrides flag can be used to instead force all existing overrides to be replaced with the ones being provided:

1
supabase --experimental \
2
--project-ref <project-ref> \
3
postgres-config update --config max_parallel_workers=3 \
4
--replace-existing-overrides

To delete specific configuration overrides, use the postgres-config delete command:

1
supabase --experimental \
2
--project-ref <project-ref> \
3
postgres-config delete --config shared_buffers,work_mem

By default, CLI v2 (≥ 2.0.0) checks the parameter’s context and requests the correct action (reload or restart):

  • If the setting can be reloaded (pg_settings.context = 'sighup'), then the Management API will detect this and apply the change with a configuration reload.
  • If the setting requires a restart (pg_settings.context = 'postmaster'), then both the primary and any read replicas will restart to apply the change.

To check whether a parameter can be reloaded without a restart, see the Postgres docs.

You can verify whether changes have been applied with the following checks:

1
supabase --version;
1
-- Check whether the parameters were updated (and if a restart is pending):
2
select name, setting, context, pending_restart
3
from pg_settings
4
where name in ('max_slot_wal_keep_size', 'shared_buffers', 'max_connections');
1
-- If the timestamp hasn’t changed, no restart occurred
2
select pg_postmaster_start_time();

You can also pass the --no-restart flag to attempt a reload-only apply. If the parameter cannot be reloaded, the change stays pending until the next restart.

1
supabase --experimental \
2
--project-ref <project-ref> \
3
postgres-config delete --config shared_buffers --no-restart

Resetting to default config

To reset a setting to its default value at the database level:

1
-- reset a single setting at the database level
2
alter database "postgres" set "<setting_name>" to default;
3
4
-- reset all settings at the database level
5
alter database "postgres" reset all;

For role level configurations, you can run:

1
alter role "<role_name>" set "<setting_name>" to default;

Considerations

  1. Changes through the CLI might restart the database causing momentary disruption to existing database connections; in most cases this should not take more than a few seconds. However, you can use the --no-restart flag to bypass the restart and keep the connections intact. Keep in mind that this depends on the specific configuration changes you're making. if the change requires a restart, using the --no-restart flag will prevent the restart but you won't see those changes take effect until a restart is manually triggered. Additionally, some parameters are required to be the same on Primary and Read Replicas; not restarting in these cases can result in read replica failure if the Primary/Read Replicas restart in isolation.
  2. Custom Postgres Config will always override the default optimizations generated by Supabase. When changing compute add-ons, you should also review and update your custom Postgres Config to ensure they remain compatible and effective with the updated compute.
  3. Some parameters (e.g. wal_keep_size) can increase disk utilization, triggering disk expansion, which in turn can lead to increases in your bill.