PostgreSQL Logging Configuration Query pg_settings - Monitor Database 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 name
  • setting - Current parameter value
  • vartype - Data type of the parameter (boolean, integer, string, etc.)
  • short_desc - Brief description of the parameter's purpose
  • source - How the parameter was set (configuration file, command line, etc.)
  • min_val and max_val - Acceptable value ranges
  • boot_val - Default value at server startup
  • reset_val - Value to reset to when using RESET command
  • pending_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