#!WARNING! THIS WAS TESTED FOR OLDER RHEL7 AND CENTOS!

# manual editing
vim /var/lib/pgsql/12/data/postgresql.conf; # postgres main config file

# semi-automatic editing via sed
# optional: postgres: enable detailed logging
POSTGRES_MAIN_CONFIG="/var/lib/pgsql/12/data/postgresql.conf"

sed -i 's/#log_statement = [^"]*/log_statement = 'all'/g' $POSTGRES_MAIN_CONFIG

sed -i 's/#logging_collector = [^"]*/logging_collector = on/g' $POSTGRES_MAIN_CONFIG

sed -i 's/#log_connections = [^"]*/log_connections = on/g' $POSTGRES_MAIN_CONFIG

sed -i 's/#log_disconnections = [^"]*/log_disconnections = on/g' $POSTGRES_MAIN_CONFIG

sed -i 's/#log_error_verbosity = [^"]*/log_error_verbosity = default/g' $POSTGRES_MAIN_CONFIG

# even more verbose logging of details
# this is VERY VERY detailed
sed -i 's/#log_error_verbosity = [^"]*/log_error_verbosity = verbose/g' $POSTGRES_MAIN_CONFIG

systemctl restart postgresql-12.service; # restart to make config changes active

# logs should now output here
==> /var/lib/pgsql/12/data/log/postgresql-Mon.log <==
==> /var/lib/pgsql/12/data/log/postgresql-Tue.log <==

# let's monitor those
vim /scripts/monitor.sh

#!/bin/bash
# version: 1.1
# description: this script will allow to see changes on the system in real time, it allows monitoring multiple log files at the same time
# usage: /path/to/script/monitor.sh
# monitoring all files below /var/log
find /var/log/ -type f \( -name "*" \) ! -path *.gz* -exec tail -n0 -f "$file" {} + &
# monitoring postgres logs (please enable logging in /var/lib/pgsql/12/data/postgresql.conf manually
find /var/lib/pgsql/12/data/log/ -type f \( -name "*" \) ! -path *.gz* -exec tail -n0 -f "$file" {} + &
# monitoring all files.log below /var/opt
find /var/opt/ -type f \( -name "*log*" \) ! -path *.gz* -exec tail -n0 -f "$file" {} +

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin