Skip to content

Logging handler for forwarding PostgreSQL log messages to network.

License

Notifications You must be signed in to change notification settings

tarvip/pg_logforward

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction
============
pg_logforward is a custom logging handler for PostgreSQL. It intercepts
all PostgreSQL log messages by hooking into EmitErrorReport() function
in the backend. The intercepted log messages are forwarded via UDP to
a remote location.

Requires PostgreSQL logging hooks patch - included in the patches directory.
The patch is against 9.2devel but also applies against 9.1 and 8.3. Although
some offsets are expected.

Building
========
USE_PGXS=1 make install

Output formats
==============
The current version supports JSON, netstring and Syslog output formats.

Usage
=====
Modify postgresql.conf to include:

shared_preload_libraries = 'pg_logforward'	# requires restart
#custom_variable_classes = 'logforward'        # needed for 9.1 and older

logforward.target_names = 'syslog,jsonsrv,netstr'

logforward.syslog_format = 'syslog'
logforward.syslog_host = '127.0.0.1'
logforward.syslog_port = 23456
logforward.syslog_min_elevel = 19               # WARNING and above
logforward.syslog_facility = 'local1'

logforward.jsonsrv_format = 'json'
logforward.jsonsrv_host = '127.0.0.1'
logforward.jsonsrv_port = 23457
logforward.jsonsrv_message_filter = 'connect'

logforward.netstr_format = 'netstr'
logforward.netstr_host = '127.0.0.1'
logforward.netstr_port = 23458
logforward.netstr_message_filter = 'foo|bar|baz'        # match any 3
logforward.netstr_funcname_filter = 'exec_simple_query' # filter on the C function
                                                        # that calls ereport()

# By default all fields are logged. Setting logforward.*_log_fields enables to
# omit certain fields or change the order of fields.

#logforward.netstr_log_fields = "username, database, remotehost, debug_query_string,
#                         elevel, funcname, sqlerrcode, message, detail, hint,
#                         context, instance_label, timestamp"

Note that you need to copy the shared library also to $libdir/plugins if you
are planning to use local_preload_libraries instead of shared_preload_libraries.

About

Logging handler for forwarding PostgreSQL log messages to network.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 92.2%
  • Python 7.3%
  • Makefile 0.5%