Home > Uncategorized > PostgreSQL Error and Slow Query Log

PostgreSQL Error and Slow Query Log

Set the following variable in postgresql.conf to log all queries that take longer than 100 milliseconds:

logging_collector = on # This parameter allows messages sent to stderr, and CSV-format log output, to be captured and redirected into log files.

log_directory = (string) # When logging_collector is enabled, this parameter determines the directory in which log files will be created.

log_filename = (string) # When logging_collector is enabled, this parameter sets the file names of the created log files.

log_rotation_size = 10M # this parameter determines the maximum size of an individual log file.

log_min_duration_statement = 100 # Causes the duration of each completed statement to be logged if the statement ran for at least the specified number of milliseconds. Setting this to zero prints all statement durations.

log_min_error_statement = error # Controls whether or not the SQL statement that causes an error condition will be recorded in the server log.

They will show up in the main postgresql.log file

Example Settings (on PostgreSQL 8.2):

redirect_stderr = on # Enable capturing of stderr into log

log_directory = ‘pg_log’ # Directory where log files are written

log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’ # Log file name pattern.

log_rotation_size = 2MB # Automatic rotation of logfiles will

log_min_error_statement = warning # Values in order of increasing severity:

log_min_duration_statement = 5000 # -1 is disabled, 0 logs all statements

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.