4 ``pg_logfebe`` produces detailed Postgres logs framed in the general
5 style of PostgreSQL's FEBE, the basis of the PostgreSQL wire protocol.
7 ``pg_logfebe`` is implemented with a C extension that is to be loaded
8 via PostgreSQL's ``shared_preload_libraries`` configuration and hooks
9 into the logging system to provide sending detailed, structured log
10 output from PostgreSQL to another process via connecting to a unix
11 socket specified in ``postgresql.conf``.
13 This is useful to allow for rapid analysis, filtering, and forwarding
14 of large volumes of logs in another process that may be upgraded or
15 changed without too much difficulty or impact.
20 In ``postgresql.conf``::
22 shared_preload_libraries = 'pg_logfebe'
24 logfebe.unix_socket = '/wherever/log.sock'
26 # The identity string is forwarded during connection start-up so
27 # the receiver of logs can know what Postgres the log records are
29 logfebe.identity = 'a name of your choice'
35 Please contact daniel@fdr.io, daniel@heroku.com, and/or
36 security@heroku.com if you find a security-sensitive bug, such as (but
37 not limited to) denial of service, information disclosure, or remote
40 Otherwise, please file an issue on the `project page on Github`__.
42 __ https://github.com/fdr/pg_logfebe/issues
45 List of Structured Fields Provided
46 ==================================
48 The existing PostgreSQL CSV output code was used to populate this
49 list, and the meanings of the fields are the same and `can be
50 referenced in the PostgreSQL manual`__. A sample parser and
51 human-readable renderer is seen (in the language "Go" in
52 ``pg_logfebe_prototext.go``). It can be useful for debugging.
54 __ http://www.postgresql.org/docs/current/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG
83 FEBE (sometimes rendered FE/BE) is the "Front-end/Back-end" protocol
84 that is the basis of virtually all PostgreSQL wire protocol
87 Each frame in this scheme is called a "Message".
89 The format looks like this::
91 Message Type. One 8-bit clean mnemonic ASCII character by
92 convention, but could be any byte in principle.
95 | Message Length, 4 bytes, including the frame length (but not
96 | the type). Network byte order integer.
99 | | Message payload, (length - 4) bytes long.
104 [-][----][...........]
107 A simple de-framer can be seen in ``pg_logfebe_prototext.go`` in the
108 procedure ``readMessage``.
113 ``pg_logfebe`` is half-duplex: no response from the software receiving
114 ``pg_logfebe`` traffic is required. At connection startup, two
115 special messages are sent, followed by an infinite series of log
118 A concrete implementation can be seen in ``pg_logfebe_prototext.go``,
119 in ``handleConnection``.
121 The protocol is versioned in its startup sequence to allow for gradual
124 A server receiving ``pg_logfebe`` will receive a stream of messages
125 that will occur in this order::
128 ---------------------------
130 (V)ersion "PG-9.2.4/logfebe-1"
132 (I)dentification "Any-string-set-via-logfebe.identity"
134 (L)og Record [many structured fields]
136 ...[Log Records ad-infinitum]...
138 Message Format Reference
139 ========================
143 * Fields are listed in order.
145 * All numerical types are network byte order.
147 * "CStrings" are NUL-terminated strings.
149 * "\*CStrings" are nullable-CStrings. These are formatted like
150 CStrings that always start with one byte: ``N``\(ull) or
151 ``P``\(resent). This is to disambiguate empty strings from C-`NULL`
152 pointers in the PostgreSQL backend.
163 The version is of the format "PG-9.2.4/logfebe-1", where the former
164 part is the Postgres version emitting the logs (as different versions
165 of Postgres may have slightly different ``LogRecord`` fields available
166 at some future time), and the latter part after the ``/`` is the
167 ``pg_logfebe`` protocol version, which is to be incremented if the
168 protocol mechanics unrelated to the Postgres version are changed.
188 DatabaseName *CString
202 InternalQuery *CString
203 InternalQueryPos int32
208 ApplicationName *CString