PostgreSQL Logging Configuration Query via pg_settings
PostgreSQL Logging Configuration Query - Monitor Database Settings
This PostgreSQL query provides database administrators with essential insights into logging configuration parameters by querying the pg_settings system view. The query specifically targets logging-related settings while filtering out WAL (Write-Ahead Logging) configurations to focus purely on database logging parameters.
Query Breakdown
The provided PostgreSQL code queries the system configuration settings:
1SELECT
2 name,
3 setting,
4 -- category,
5 vartype,
6 short_desc,
7 -- enumvals,
8 source,
9 min_val,
10 max_val,
11 boot_val,
12 reset_val,
13 -- not available on PostgreSQL < 9.5
14 pending_restart
15FROM
16 pg_settings
17WHERE
18 -- Reporting and Logging / What to Log
19 -- broader '%Log%' pulls in WAL settings which we don't want here
20 category ILIKE '%Logging%';
Purpose and Functionality
This query serves as a diagnostic tool for PostgreSQL database administrators to examine current logging configurations. It extracts critical information about how the database handles log generation, rotation, and output formatting.
Key Components Explained
Selected Columns:
name- Configuration parameter namesetting- Current parameter valuevartype- Data type of the parameter (boolean, integer, string, etc.)short_desc- Brief description of the parameter's purposesource- How the parameter was set (configuration file, command line, etc.)min_valandmax_val- Acceptable value rangesboot_val- Default value at server startupreset_val- Value to reset to when using RESET commandpending_restart- Indicates if server restart is needed for changes
Filtering Strategy
The WHERE clause uses category ILIKE '%Logging%' to specifically target logging parameters while avoiding WAL-related settings that would appear with a broader '%Log%' pattern.
Practical Applications
Database administrators can use this query to:
- Audit current logging configuration across different environments
- Troubleshoot logging issues by verifying parameter values
- Plan configuration changes by understanding current settings and limits
- Document system configurations for compliance and maintenance
- Identify parameters requiring restart before applying changes
Important Considerations
The pending_restart column requires PostgreSQL version 9.5 or later. For older versions, this column should be removed from the SELECT statement to avoid errors.
Configuration Categories Covered
This query typically returns parameters related to:
- Log destination and formatting
- Log rotation and file management
- Error reporting levels
- Statement logging configuration
- Connection and disconnection logging
- Lock timeout and deadlock detection logging
Performance Impact
The pg_settings view provides a lightweight method to examine configuration without impacting database performance, making it safe for regular monitoring and automated scripts.
References
PostgreSQL Documentation - Server Configuration - Official PostgreSQL documentation covering all configuration parameters and their usage
PostgreSQL pg_settings View Reference - Detailed reference for the pg_settings system view and all available columns
PostgreSQL Logging Configuration Guide - Comprehensive guide to configuring PostgreSQL logging for different environments
Posts in this series
- How Many Connections Can Your PostgreSQL Database Handle?
- PostgreSQL Backend Connections via pg_stat_database
- Identifying Blocking PostgreSQL Queries using pg_stat_activity
- List PostgreSQL Databases by Size with Access Check
- Assess PostgreSQL Database Sizes Quickly and Easily
- Unveiling Your PostgreSQL Server - A Diagnostic Powerhouse
- Keep Your PostgreSQL Database Clean, Identify Idle Connections
- Query the PostgreSQL Configuration
- PostgreSQL Recovery Monitoring: Essential SQL Insights
- Restart All PostgreSQL Sequences with ALTER SEQUENCE
- Monitor Running Queries in PostgreSQL using pg_stat_activity
- Monitor PostgreSQL Active Sessions with pg_stat_activity
- PostgreSQL Error Handling Settings via pg_settings
- PostgreSQL File Location Settings Query via pg_settings
- PostgreSQL Lock Management Settings via pg_settings
- PostgreSQL Logging Configuration Query via pg_settings
- Monitor PostgreSQL Memory Settings with pg_settings
- PostgreSQL Table Row Count Estimates with SQL
- List PostgreSQL Tables by Size with SQL
- PostgreSQL WAL Settings Query Guide
- PostgreSQL SSL Settings Query Guide
- PostgreSQL Statistics Settings Query Guide
- PostgreSQL Resource Settings Query Guide
- PostgreSQL Replication Settings Query Guide
- PostgreSQL Query Planning Settings Query Guide
- PostgreSQL Preset Options Settings Query Guide
- PostgreSQL Miscellaneous Settings Query Guide
- Count PostgreSQL Sessions by State with SQL
- Kill Idle PostgreSQL Sessions with SQL
- Grant SELECT on All Tables in PostgreSQL
- Identify Insert-Only Tables in PostgreSQL
- Detect Soft Delete Patterns in PostgreSQL
- List PostgreSQL Object Comments with SQL
- List Foreign Key Constraints in PostgreSQL
- List PostgreSQL Enum Types and Their Values with SQL
- List All Views in a PostgreSQL Database with SQL
- Find PostgreSQL Tables Without a Primary Key
- List PostgreSQL Partitioned Tables with SQL