pg_diag_setup#

pg_diag_setup

pg_diag_setup

pg_diag_setup — Configuration manage tool for PostgreSQL

Introduction

A tool for managing Tantor BE configuration with profile support and rollback capability.

System Requirements

  • Python 3.x (tested on CentOS 7)

  • Tantor BE accessible via Unix Domain Socket

  • psql utility available in PATH

Installation

  1. Copy the pg_diag_setup.py file to the server.

  2. Create a profiles directory and place profile files inside (e.g., default.yaml).

  3. Make the script executable:

    chmod +x pg_diag_setup.py
    

Usage

Basic run (configuration check)

sudo ./pg_diag_setup.py --port 5432 --unix-socket-dir /tmp

Apply a configuration profile

sudo ./pg_diag_setup.py --port 5432 --unix-socket-dir /tmp --profile default.yaml --bin-dir /opt/path_to_binaries

View available backups

sudo ./pg_diag_setup.py --port 5432 --unix-socket-dir /tmp --list-backups

Roll back changes

sudo ./pg_diag_setup.py --port 5432 --unix-socket-dir /tmp --undo 20240529_143022 --bin-dir /opt/path_to_binaries

Command Line Options

  • --port - Tantor BE port (default: 5432)

  • --unix-socket-dir - Unix socket directory (default: /tmp)

  • --profile - YAML profile file to apply

  • --undo - timestamp for rollback

  • --list-backups - show available backup list

  • --bin-dir - directory where the Tantor BE distribution is installed

  • -V - show utility version

  • -v - enable verbose mode

What the Program Does

Tasks 1-2: Connection and Configuration Discovery

  • Connects to Tantor BE via Unix Domain Socket

  • Locates the postgresql.conf file

Task 3: Checking postgresql.auto.conf

  • Verifies existence of the postgresql.auto.conf file

Task 4: Parameter Analysis

  • Parses all configuration files

  • Compiles a parameter list with source info

  • Handles include directives

Task 5: Profile Application

  • Reads YAML profile with extension settings

  • Checks available extensions via pg_available_extensions

  • Creates configuration backups

  • Appends to shared_preload_libraries without overwriting existing entries

  • Adds new parameters to the end of postgresql.conf

  • Tags added parameters with Added by pg_diag_setup comment

Task 6: Rollback System

  • Creates timestamped backups

  • Allows rollback to any previous backup

Profile File Format

extension_name:
  shared_preload_lib: library_name
  create_cmd: CREATE EXTENSION command
  params:
    parameter1: value1
    parameter2: value2

Safety

  • All changes are accompanied by backups

  • Existing parameters are preserved

  • Extensions are checked before installation

  • New parameters are added to the end of the file

Backup Examples

After changes are applied, the following files are created:

  • postgresql.conf_backup_pds_20240529_143022

  • postgresql.auto.conf_backup_pds_20240529_143022

Logging

The program provides detailed output for all operations:

  • Located configuration files

  • Detected parameters

  • Backup creation

  • Applied changes

  • Operation results

Limitations

  • Requires psql utility

  • Only works with Unix Domain Socket connections

  • Simple YAML parser (doesn’t support full YAML spec)

  • Does not perform automatic Tantor BE restart

Troubleshooting

  1. Tantor BE connection error

    • Check the --unix-socket-dir path

    • Ensure Tantor BE is running

    • Verify socket file permissions

  2. Configuration read error

    • Check configuration file permissions

    • Ensure the user has read/write access

  3. YAML parsing error

    • Check profile file syntax

    • Validate indentation (use 2 or 4 spaces)

Recommendations

  • Always create full backups before applying changes

  • Test changes in a staging environment

  • Tantor BE restart may be required after applying a profile

  • Track applied profiles and their timestamps

Support

If issues arise, check:

  1. Tantor BE logs

  2. File access permissions

  3. YAML profile syntax

  4. Extension availability in the system