Skip to content

Instantly share code, notes, and snippets.

@TheOtherBrian1
Last active May 11, 2024 08:28
Show Gist options
  • Save TheOtherBrian1/991d32c2b00dbc75d29b80d4cdf41aa7 to your computer and use it in GitHub Desktop.
Save TheOtherBrian1/991d32c2b00dbc75d29b80d4cdf41aa7 to your computer and use it in GitHub Desktop.

What Events are Logged:

connection authorized/authenticated/recieved events:

Screenshot 2024-05-04 at 8 53 34 PM
Postgres Setting:
SHOW log_connections; -- 'on'

In standard circumstances, when a client initiates a new connection—like when PostgREST or Supavisor establishes a direct link with the database—the successful connection gets logged as an authorized/authenticated/received event.

These events occur frequently, sometimes dozens or hundreds of times per minute, and typically include details like the server's IP, application_name (if provided), and the connecting database user. While abundant, most of these can be disregarded as background noise.

checkpoint complete/starting events:

Screenshot 2024-05-04 at 8 53 34 PM
Postgres Setting:
SHOW log_checkpoints; -- 'on'

PostgreSQL will temporarily store recent changes to a special file called a Write-Ahead-Log (WAL). When the database transfers the the data into a different format, a checkpoint event is logged. This is normal and these logs can be disregarded as noise for the vast majority of users.

Long running queries:

Screenshot 2024-05-04 at 10 36 00 PM
Postgres Setting:
SHOW auto_explain.log_min_duration; -- '10s'

Queries that run for more than 10 seconds EXPLAIN plan will be logged. Unless you intend to run long transactions, if several are showing up in your database, it is a sign that your queries need to be optomized or your database is struggling.

To correct, consider inspecting your Dashboard's Query Performance Page and setting up a Supabase Grafana Board to increase visibility of your database metrics.

PG_Cron job start times:

cron
Postgres Setting:
SHOW cron.log_statement; -- 'on'

log the id of a pg_cron job when it is initiated. Unless you suspect your custom cron jobs are failing, this can be ignored.

Severity events:

Screenshot 2024-05-06 at 12 00 57 AM
Postgres Setting:
SHOW log_min_messages; -- 'warning'

Some events are logged based on severity. The log_min_messages variable determines what is severe enough to log. Here are the severity thresholds from the Postgres docs.

Severity Usage
DEBUG1 .. DEBUG5 Provides successively-more-detailed information for use by developers.
INFO Provides information implicitly requested by the user, e.g., output from VACUUM VERBOSE.
NOTICE Provides information that might be helpful to users, e.g., notice of truncation of long identifiers.
WARNING Provides warnings of likely problems, e.g., COMMIT outside a transaction block.
ERROR Reports an error that caused the current command to abort.
LOG Reports information of interest to administrators, e.g., checkpoint activity.
FATAL Reports an error that caused the current session to abort.
PANIC Reports an error that caused all database sessions to abort.

By default WARNING, ERROR, LOG, FATAL, and PANIC events are recorded. Unless you create custom logs, all events you'll encounter, apart from routine events, will be related to failures or warnings like query timeouts, foreign key constraint violations, and improper disconnects.

Boot up events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment