pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Exclude logging certain connections?
3+ messages / 2 participants
[nested] [flat]

* Exclude logging certain connections?
@ 2020-03-15 10:09  Paul Förster <paul.foerster@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Paul Förster @ 2020-03-15 10:09 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Hi,

is there a way to exclude certain connections, for example recurring monitoring connections, from the postgres.log?

I found this from in old post on stackexchange.com:

postgres=# create role mon login;
CREATE ROLE
postgres=# alter role mon set log_connections=off;
ERROR:  parameter "log_connections" cannot be set after connection start

(source: https://dba.stackexchange.com/questions/118018/is-it-possible-to-exclude-specific-users-in-log-activ...)

There is no connection at the time. So why do I get the error? And what can I do about it?

Cheers,
Paul




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Exclude logging certain connections?
@ 2020-03-15 16:28  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Paul Förster <paul.foerster@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Adrian Klaver @ 2020-03-15 16:28 UTC (permalink / raw)
  To: Paul Förster <paul.foerster@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

On 3/15/20 3:09 AM, Paul Förster wrote:
> Hi,
> 
> is there a way to exclude certain connections, for example recurring monitoring connections, from the postgres.log?
> 
> I found this from in old post on stackexchange.com:
> 
> postgres=# create role mon login;
> CREATE ROLE
> postgres=# alter role mon set log_connections=off;
> ERROR:  parameter "log_connections" cannot be set after connection start
> 
> (source: https://dba.stackexchange.com/questions/118018/is-it-possible-to-exclude-specific-users-in-log-activ...)
> 
> There is no connection at the time. So why do I get the error? And what can I do about it?

Nothing from what I see:

 From here:

https://www.postgresql.org/docs/12/config-setting.html#id-1.6.6.4.5

env PGOPTIONS="-c log_connections=off" psql -d test -U aklaver

psql: error: could not connect to server: FATAL:  permission denied to 
set parameter "log_connections"

First problem is you need to be superuser. Alright so be superuser:

date
Sun Mar 15 09:24:20 PDT 2020

aklaver@maura:~> env PGOPTIONS="-c log_connections=off" psql -d test -U 
postgres

psql (12.1)
Type "help" for help.

test=# \x
Expanded display is on.
test=# select * from pg_settings where name = 'log_connections';
-[ RECORD 1 ]---+------------------------------------
name            | log_connections
setting         | off
unit            |
category        | Reporting and Logging / What to Log
short_desc      | Logs each successful connection.
extra_desc      |
context         | superuser-backend
vartype         | bool
source          | client
min_val         |
max_val         |
enumvals        |
boot_val        | off
reset_val       | off
sourcefile      |
sourceline      |
pending_restart | f


The connection is still recorded:

[unknown]-[unknown]-2020-03-15 09:24:23.460 PDT-0LOG:  connection 
received: host=[local]
[unknown]-postgres-2020-03-15 09:24:23.460 PDT-0LOG:  connection 
authorized: user=postgres database=test application_name=psql


To me it looks like log_connections is all or none.


> 
> Cheers,
> Paul
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Exclude logging certain connections?
@ 2020-03-15 16:40  Paul Förster <paul.foerster@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Paul Förster @ 2020-03-15 16:40 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Hi Adrian,

> Nothing from what I see:
> 
> From here:
> 
> https://www.postgresql.org/docs/12/config-setting.html#id-1.6.6.4.5
> 
> env PGOPTIONS="-c log_connections=off" psql -d test -U aklaver
> 
> psql: error: could not connect to server: FATAL:  permission denied to set parameter "log_connections"
> 
> First problem is you need to be superuser. Alright so be superuser:
> 
> date
> Sun Mar 15 09:24:20 PDT 2020
> 
> aklaver@maura:~> env PGOPTIONS="-c log_connections=off" psql -d test -U postgres
> 
> psql (12.1)
> Type "help" for help.
> 
> test=# \x
> Expanded display is on.
> test=# select * from pg_settings where name = 'log_connections';
> -[ RECORD 1 ]---+------------------------------------
> name            | log_connections
> setting         | off
> unit            |
> category        | Reporting and Logging / What to Log
> short_desc      | Logs each successful connection.
> extra_desc      |
> context         | superuser-backend
> vartype         | bool
> source          | client
> min_val         |
> max_val         |
> enumvals        |
> boot_val        | off
> reset_val       | off
> sourcefile      |
> sourceline      |
> pending_restart | f
> 
> 
> The connection is still recorded:
> 
> [unknown]-[unknown]-2020-03-15 09:24:23.460 PDT-0LOG:  connection received: host=[local]
> [unknown]-postgres-2020-03-15 09:24:23.460 PDT-0LOG:  connection authorized: user=postgres database=test application_name=psql
> 
> 
> To me it looks like log_connections is all or none.

that's what I suspected. This is also what I found out so far. This is ugly because unwanted monitoring connections like those of pgwatch2 keep spamming the logfiles this way. It would be great if there was an option to specify a list of users whose connections would not be logged, even with logging connect/disconnect enabled.

Something like this:

log_exclude_user_connect = 'pgwatch2,myself,...'

in postgresql.conf

Thanks very much.

Cheers,
Paul




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2020-03-15 16:40 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-15 10:09 Exclude logging certain connections? Paul Förster <paul.foerster@gmail.com>
2020-03-15 16:28 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-03-15 16:40   ` Paul Förster <paul.foerster@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox