The logs sent to Google Stackdriver are events that are collected from the PostgreSQL log files. The image below depicts several different examples of events collected and sent to Stackdriver Logging.
Follow these steps to set up log collection from PostgreSQL.
Locate the local PostgreSQL postgresql.conf configuration file.
Finding postgresql.conf file
This file is typically located in the database data_directory. For more information see the PostgreSQL documentation.
Modify the postgresql.conf file with the following logging parameters. Changes should go under the ERROR REPORTING AND LOGGING section of the file.
log_destination = 'stderr' logging_collector = on log_directory = 'pg_log' log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' log_truncate_on_rotation = off log_rotation_age = 1d log_min_duration_statement = 0 log_connections = on log_duration = on log_hostname = on log_timezone = 'UTC' log_line_prefix = 't=%t p=%p s=%c l=%l u=%u db=%d r=%r '
PostgreSQL Configuration File
For more details on the log parameters, Click here
After editing the postgresql.conf file, you will need to restart the postgres server:
sudo service postgresql restart
- Install the BindPlane Log Agent on the host system.
- Login to BindPlane and select the Logs tab.
- Select the Sources tab.
- In the top-right portion of the screen, click on the Add Source Configuration button
- Choose PostgreSQL
- Fill out the PostgreSQL log location
Fill out the relevant log location path for your PostgreSQL server.
PostgreSQL Log locations
If no parameters were changed from the above postgresql.conf file, the logs location will be located under the PostgreSQL servers [data_directory]/pg_log.
For more information, Click here.
Updated almost 4 years ago