Skip to content

pg_sqlog

Provide SQL interface to logs

pg_sqlog : Provide SQL interface to logs

Overview

ID Extension Package Version Category License Language
6500 pg_sqlog pg_sqlog 1.7 STAT BSD-3-Clause SQL
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
----d-- No No No Yes no no
CSV logging; daily rotation required.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 1.7 19 18 17 16 15 pg_sqlog file_fdw
RPM PIGSTY 1.7 19 18 17 16 15 pg_sqlog_$v -
DEB PIGSTY 1.7 19 18 17 16 15 postgresql-$v-pg-sqlog -
Linux / PG PG19 PG18 PG17 PG16 PG15
el8.x86_64 N/A PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
el8.aarch64 N/A PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
el9.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
el9.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
el10.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
el10.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
d12.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
d12.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
d13.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
d13.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
u22.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
u22.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
u24.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
u24.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
u26.x86_64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
u26.aarch64 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7 PIGSTY 1.7
Package Version OS ORG SIZE File URL
pg_sqlog_19 1.7 el9.x86_64 pigsty 17.0 KiB pg_sqlog_19-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_19 1.7 el9.aarch64 pigsty 17.0 KiB pg_sqlog_19-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_19 1.7 el10.x86_64 pigsty 17.2 KiB pg_sqlog_19-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
pg_sqlog_19 1.7 el10.aarch64 pigsty 17.2 KiB pg_sqlog_19-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
postgresql-19-pg-sqlog 1.7 d12.x86_64 pigsty 10.8 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-19-pg-sqlog 1.7 d12.aarch64 pigsty 10.8 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-19-pg-sqlog 1.7 d13.x86_64 pigsty 10.8 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-19-pg-sqlog 1.7 d13.aarch64 pigsty 10.8 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-19-pg-sqlog 1.7 u22.x86_64 pigsty 10.4 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-19-pg-sqlog 1.7 u22.aarch64 pigsty 10.4 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-19-pg-sqlog 1.7 u24.x86_64 pigsty 10.4 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-19-pg-sqlog 1.7 u24.aarch64 pigsty 10.4 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-19-pg-sqlog 1.7 u26.x86_64 pigsty 10.4 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
postgresql-19-pg-sqlog 1.7 u26.aarch64 pigsty 10.4 KiB postgresql-19-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
pg_sqlog_18 1.7 el8.x86_64 pigsty 17.2 KiB pg_sqlog_18-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_18 1.7 el8.aarch64 pigsty 17.2 KiB pg_sqlog_18-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_18 1.7 el9.x86_64 pigsty 17.0 KiB pg_sqlog_18-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_18 1.7 el9.aarch64 pigsty 17.0 KiB pg_sqlog_18-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_18 1.7 el10.x86_64 pigsty 17.3 KiB pg_sqlog_18-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
pg_sqlog_18 1.7 el10.aarch64 pigsty 17.3 KiB pg_sqlog_18-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
postgresql-18-pg-sqlog 1.7 d12.x86_64 pigsty 10.8 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-18-pg-sqlog 1.7 d12.aarch64 pigsty 10.8 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-18-pg-sqlog 1.7 d13.x86_64 pigsty 10.8 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-18-pg-sqlog 1.7 d13.aarch64 pigsty 10.8 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-18-pg-sqlog 1.7 u22.x86_64 pigsty 10.4 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-18-pg-sqlog 1.7 u22.aarch64 pigsty 10.4 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-18-pg-sqlog 1.7 u24.x86_64 pigsty 10.3 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-18-pg-sqlog 1.7 u24.aarch64 pigsty 10.3 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-18-pg-sqlog 1.7 u26.x86_64 pigsty 10.4 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
postgresql-18-pg-sqlog 1.7 u26.aarch64 pigsty 10.4 KiB postgresql-18-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
pg_sqlog_17 1.7 el8.x86_64 pigsty 17.2 KiB pg_sqlog_17-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_17 1.7 el8.aarch64 pigsty 17.2 KiB pg_sqlog_17-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_17 1.7 el9.x86_64 pigsty 17.0 KiB pg_sqlog_17-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_17 1.7 el9.aarch64 pigsty 17.0 KiB pg_sqlog_17-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_17 1.7 el10.x86_64 pigsty 17.3 KiB pg_sqlog_17-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
pg_sqlog_17 1.7 el10.aarch64 pigsty 17.3 KiB pg_sqlog_17-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
postgresql-17-pg-sqlog 1.7 d12.x86_64 pigsty 10.8 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-17-pg-sqlog 1.7 d12.aarch64 pigsty 10.8 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-17-pg-sqlog 1.7 d13.x86_64 pigsty 10.8 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-17-pg-sqlog 1.7 d13.aarch64 pigsty 10.8 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-17-pg-sqlog 1.7 u22.x86_64 pigsty 10.4 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-17-pg-sqlog 1.7 u22.aarch64 pigsty 10.4 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-17-pg-sqlog 1.7 u24.x86_64 pigsty 10.4 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-17-pg-sqlog 1.7 u24.aarch64 pigsty 10.4 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-17-pg-sqlog 1.7 u26.x86_64 pigsty 10.4 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
postgresql-17-pg-sqlog 1.7 u26.aarch64 pigsty 10.4 KiB postgresql-17-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
pg_sqlog_16 1.7 el8.x86_64 pigsty 17.2 KiB pg_sqlog_16-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_16 1.7 el8.aarch64 pigsty 17.2 KiB pg_sqlog_16-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_16 1.7 el9.x86_64 pigsty 17.0 KiB pg_sqlog_16-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_16 1.7 el9.aarch64 pigsty 17.0 KiB pg_sqlog_16-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_16 1.7 el10.x86_64 pigsty 17.3 KiB pg_sqlog_16-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
pg_sqlog_16 1.7 el10.aarch64 pigsty 17.3 KiB pg_sqlog_16-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
postgresql-16-pg-sqlog 1.7 d12.x86_64 pigsty 10.8 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-16-pg-sqlog 1.7 d12.aarch64 pigsty 10.8 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-16-pg-sqlog 1.7 d13.x86_64 pigsty 10.8 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-16-pg-sqlog 1.7 d13.aarch64 pigsty 10.8 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-16-pg-sqlog 1.7 u22.x86_64 pigsty 10.4 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-16-pg-sqlog 1.7 u22.aarch64 pigsty 10.4 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-16-pg-sqlog 1.7 u24.x86_64 pigsty 10.4 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-16-pg-sqlog 1.7 u24.aarch64 pigsty 10.4 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-16-pg-sqlog 1.7 u26.x86_64 pigsty 10.4 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
postgresql-16-pg-sqlog 1.7 u26.aarch64 pigsty 10.4 KiB postgresql-16-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
Package Version OS ORG SIZE File URL
pg_sqlog_15 1.7 el8.x86_64 pigsty 17.2 KiB pg_sqlog_15-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_15 1.7 el8.aarch64 pigsty 17.2 KiB pg_sqlog_15-1.7-1.git20241118.b016539PGSTY.el8.noarch.rpm
pg_sqlog_15 1.7 el9.x86_64 pigsty 17.0 KiB pg_sqlog_15-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_15 1.7 el9.aarch64 pigsty 17.0 KiB pg_sqlog_15-1.7-1.git20241118.b016539PGSTY.el9.noarch.rpm
pg_sqlog_15 1.7 el10.x86_64 pigsty 17.3 KiB pg_sqlog_15-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
pg_sqlog_15 1.7 el10.aarch64 pigsty 17.3 KiB pg_sqlog_15-1.7-1.git20241118.b016539PGSTY.el10.noarch.rpm
postgresql-15-pg-sqlog 1.7 d12.x86_64 pigsty 10.8 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-15-pg-sqlog 1.7 d12.aarch64 pigsty 10.8 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~bookworm_all.deb
postgresql-15-pg-sqlog 1.7 d13.x86_64 pigsty 10.8 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-15-pg-sqlog 1.7 d13.aarch64 pigsty 10.8 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~trixie_all.deb
postgresql-15-pg-sqlog 1.7 u22.x86_64 pigsty 10.4 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-15-pg-sqlog 1.7 u22.aarch64 pigsty 10.4 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~jammy_all.deb
postgresql-15-pg-sqlog 1.7 u24.x86_64 pigsty 10.4 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-15-pg-sqlog 1.7 u24.aarch64 pigsty 10.4 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~noble_all.deb
postgresql-15-pg-sqlog 1.7 u26.x86_64 pigsty 10.4 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb
postgresql-15-pg-sqlog 1.7 u26.aarch64 pigsty 10.4 KiB postgresql-15-pg-sqlog_1.7+git20241118.b016539-1PGSTY~resolute_all.deb

Source

pig build pkg pg_sqlog;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_sqlog;		# install via package name, for the active PG version

pig install pg_sqlog -v 19;   # install for PG 19
pig install pg_sqlog -v 18;   # install for PG 18
pig install pg_sqlog -v 17;   # install for PG 17
pig install pg_sqlog -v 16;   # install for PG 16
pig install pg_sqlog -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION pg_sqlog CASCADE; -- requires file_fdw

Usage

pg_sqlog: access PostgreSQL CSV logs via SQL

pg_sqlog provides a SQL interface for querying PostgreSQL CSV log files using a foreign table backed by file_fdw.

Querying Logs

-- Current day's log
SELECT * FROM sqlog.log();

-- Specific day's log
SELECT * FROM sqlog.log('yesterday');
SELECT * FROM sqlog.log('2024-01-15');

-- Error summary
SELECT error_severity, COUNT(*) FROM sqlog.log() GROUP BY 1;

Slow Query Analysis

-- Top 3 slowest query patterns
SELECT
  AVG(sqlog.duration(message)) AS avg_duration,
  COUNT(*) AS count,
  sqlog.preparable_query(message) AS query_pattern
FROM sqlog.log()
WHERE message ~ '^duration'
GROUP BY 3
ORDER BY 1 DESC
LIMIT 3;

-- Query summary with timing
SELECT
  log_time::time,
  sqlog.duration(message),
  sqlog.summary(message)
FROM sqlog.log('yesterday')
WHERE message ~ '^duration';

Functions

Function Description
sqlog.log([timestamp]) Returns log contents for a given day
sqlog.set_date([timestamp]) Set the date for sqlog.log table queries
sqlog.duration(text) Extract query duration from message (ms)
sqlog.preparable_query(text) Replace arguments with ? for grouping
sqlog.summary(text, int, int) Strip metadata, show first/last N chars
sqlog.temporary_file_size(text) Extract temp file size from message
sqlog.autovacuum([timestamp]) Autovacuum report for a given day
sqlog.autoanalyze([timestamp]) Autoanalyze report for a given day

Autovacuum Reports

SELECT * FROM sqlog.autovacuum() LIMIT 5;
SELECT * FROM sqlog.autoanalyze() LIMIT 5;

Prerequisites

Required postgresql.conf settings:

log_destination = 'syslog,csvlog'
log_filename = 'postgresql.%F'
logging_collector = 'on'
log_rotation_age = '1d'
log_rotation_size = 0
log_truncate_on_rotation = 'on'
log_min_duration_statement = 1000

Table reader