PostgreSQL

Logs Collected

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.

1862

PostgreSQL Logs Example

Supported Versions

PostgreSQL: 9.0+

Log Collection Setup

Follow these steps to set up log collection from PostgreSQL.

Pre-requisites

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

Configure a PostgreSQL Source

  1. Install the BindPlane Log Agent on the host system.
  2. Login to BindPlane and select the Logs tab.
284

Logs Tab

  1. Select the Sources tab.
249

Sources Tab

  1. In the top-right portion of the screen, click on the Add Source Configuration button
576

Add Source Configuration Button

  1. Choose PostgreSQL
  2. Fill out the PostgreSQL log location
506

PostgreSQL Log Configuration Form

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.