log_connections
log_connections
is a configuration parameter determining whether to log connections.
log_connections
was added in PostgreSQL 7.1.
Default value
The default value for log_connections
is: off
.
Usage
By default, PostgreSQL only logs the errors generated by unsuccessful connections.
If log_connections
is set to on
, details of successful and unsuccessful connections are also logged.
Change history
- PostgreSQL 14
- authenticated identify details will also be logged (commit 9afffcb8)
- PostgreSQL 9.5
- context changed to
superuser-backend
(commit fe550b2a)
- context changed to
- PostgreSQL 9.4
- PostgreSQL 7.1
- added (commit 6a68f426)
Examples
Sample log output for a successful connection when log_connections
is on
(PostgreSQL 13 and earlier):
[2020-12-07 12:54:20 CET 192.168.1.2 [unknown]/[unknown] ] LOG: connection received: host=192.168.1.2 port=56974 [2020-12-07 12:54:20 CET 192.168.1.2 postgres/postgres authentication] LOG: connection authorized: user=postgres database=postgres application_name=psql
In PostgreSQL 14 and later, an additional line will be logged containing details about the authenticated identity will be added (except if the connection is via trust
authentication):
[2021-04-06 20:15:24 UTC] [unknown] [unknown] [unknown] LOG: 00000: connection received: host=::1 port=59774 [2021-04-06 20:15:24 UTC] [unknown] dbuser appsdb LOG: 00000: connection authenticated: identity="dbuser" method=md5 (/var/lib/postgres/data/pg_hba.conf:12) [2021-04-06 20:15:24 UTC] [unknown] dbuser appsdb LOG: 00000: connection authorized: user=dbuser database=appsdb application_name=psql
Sample log output for an unsuccessful connection when log_connections
is off
:
[2020-12-07 13:38:22 CET 192.168.1.2 postgres/postgree startup] FATAL: database "postgree" does not exist
Sample log output for an unsuccessful connection when log_connections
is on
:
[2020-12-07 13:39:10 CET 192.168.1.2 [unknown]/[unknown] ] LOG: connection received: host=192.168.1.2 port=59480 [2020-12-07 13:39:10 CET 192.168.1.2 postgres/postgree authentication] LOG: connection authorized: user=postgres database=postgree application_name=psql [2020-12-07 13:39:10 CET 192.168.1.2 postgres/postgree startup] FATAL: database "postgree" does not exist
References
- PostgreSQL documentation: log_connections