Understanding PostgreSQL Logging Levels and How They Impact Your Project #29877
monicakh
announced in
Troubleshooting
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is a copy of a troubleshooting article on Supabase's docs site. It may be missing some details from the original. View the original article.
Since each Supabase project uses Postgres as its underlying database engine, it’s common to adjust logging settings for various reasons—whether for debugging issues, monitoring database performance, or auditing actions. However, modifying logging levels improperly can lead to an excessive amount of log data being generated, which can fill up your disk space and cause significant performance degradation or even system failure.
1. Overview of Postgres logging levels
Postgres provides multiple logging levels that allow you to control how much information gets logged. These include:
Each of these log levels is useful in specific situations. Here's an example of what messages tagged with each severity level look like:
The default log level is set to WARNING through the log_min_messages setting, and we recommend keeping it that way.
2. How high log levels can affect your database
When users alter a high level of log settings, the database can start generating an overwhelming number of log entries. This can escalate to issues such as:
Disk Space Exhaustion: Log files can grow exponentially if verbose levels like DEBUG, INFO, or NOTICE are enabled for long periods. And running out of disk space due to log bloat can cause your database to stop accepting writes and slow down query performance.
I/O Overload: Writing too many logs increases input/output (I/O) operations, which can negatively impact database speed. A database bogged down by heavy logging will take longer to process requests, leading to slower application performance.
Database Lockups: In extreme cases, if the disk is filled to capacity with logs, your database could lock up, leading to downtime or severe performance degradation.
3. Common scenarios that cause log overload
Here are a few common scenarios where excessive logging can become a problem:
Extended Use of DEBUG Logging: While useful for troubleshooting, leaving DEBUG logging enabled for a long period can lead to the accumulation of massive amounts of logs.
Setting INFO for Monitoring: Logging INFO can be helpful for tracking general database activity, but if left on indefinitely, it can still result in a lot of noise and unnecessary log growth.
Frequent Write Operations: If your database processes a lot of write operations (such as inserts, updates, or deletes), even low-level logs (like NOTICE or INFO) can lead to significant log accumulation.
4. How to manage Postgres log levels effectively
a. Choose the Right Log Level
For most users, setting Postgres logs to WARNING or ERROR is sufficient for regular operations. Here’s a general guideline:
WARNING: Use this level for general logging during normal operations. It captures issues that may not be critical but are worth paying attention to.
ERROR: This level is ideal for production environments. It logs only failures that prevent queries from being executed, reducing log noise significantly.
DEBUG, INFO, or NOTICE: Use these levels sparingly and only for short-term debugging or diagnostics. Always remember to revert the setting once you've collected the necessary information.
b. How to Adjust Log Levels
You can adjust log levels using SQL commands in the SQL Editor or any connected Postgres client:
5. Conclusion
Postgres logs provide a powerful way to gain valuable insights into your database activity and performance when properly configured, but the key lies in finding the right balance. When set up properly, they can be incredibly useful.
6. Other resources
a. What Events Are Logged in Postgres
For a detailed explanation of the types of events logged in your database (such as connection events, checkpoint events, long-running queries, cron jobs, and severity-based logging), you can refer to the official documentation here:
What Events Are Logged in Supabase
b. PGAudit: Postgres Auditing for Compliance and Security
We support PGAudit extension, which extends Postgres’s built-in logging capabilities to track database activities for auditing purposes.
How to Enable the PGAudit Extension
For detailed configuration instructions and logging options, refer to the complete documentation: PGAudit Configuration Guide
c. Debugging Functions
For more information on how to debug functions in Supabase, refer to the official guide: Debugging Functions.
Beta Was this translation helpful? Give feedback.
All reactions