pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedlog_statement GUC parameter
9+ messages / 4 participants
[nested] [flat]
* log_statement GUC parameter
@ 2021-08-12 20:19 Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:23 ` Re: log_statement GUC parameter Bruce Momjian <bruce@momjian.us>
2021-08-12 20:28 ` Re: log_statement GUC parameter Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-12 20:30 ` Re: log_statement GUC parameter Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 3 replies; 9+ messages in thread
From: Mladen Gogala @ 2021-08-12 20:19 UTC (permalink / raw)
To: pgsql-general <pgsql-general@lists.postgresql.org>
Hi!
Unfortunately, only a superuser can set log_statement='all'; Would it be
possible to execute set session log_statement='all'; as an ordinary
user? I am trying to execute it from login.sql, a part of login_hook
extension which implements on-login triggers in PostgreSQL. I will
create a procedure with security definer, owned by the role "postgres",
and grant it to public. That should do the trick. However, it would be
much nicer if PostgreSQL allowed me to set the parameter as a part of
the normal session.
The idea is to log all statements by the particular user, not by
everybody. The user in question uses Weblogic 12.2.1.4 and creates a
connection pool so I need to find out which statements are the longest
running ones and make them perform.
Regards
--
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
@ 2021-08-12 20:23 ` Bruce Momjian <bruce@momjian.us>
2021-08-12 20:49 ` Re: log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2 siblings, 1 reply; 9+ messages in thread
From: Bruce Momjian @ 2021-08-12 20:23 UTC (permalink / raw)
To: Mladen Gogala <gogala.mladen@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
On Thu, Aug 12, 2021 at 04:19:18PM -0400, Mladen Gogala wrote:
> Hi!
>
> Unfortunately, only a superuser can set log_statement='all'; Would it be
> possible to execute set session log_statement='all'; as an ordinary user? I
> am trying to execute it from login.sql, a part of login_hook extension which
> implements on-login triggers in PostgreSQL. I will create a procedure with
> security definer, owned by the role "postgres", and grant it to public. That
> should do the trick. However, it would be much nicer if PostgreSQL allowed
> me to set the parameter as a part of the normal session.
>
> The idea is to log all statements by the particular user, not by everybody.
> The user in question uses Weblogic 12.2.1.4 and creates a connection pool
> so I need to find out which statements are the longest running ones and make
> them perform.
I think you can write a SECURITY DEFINER function that calls SET, call
that function at login.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:23 ` Re: log_statement GUC parameter Bruce Momjian <bruce@momjian.us>
@ 2021-08-12 20:49 ` Mladen Gogala <gogala.mladen@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Mladen Gogala @ 2021-08-12 20:49 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Hi Bruce
Yes, I can. I have already done so and it works. I wrote a procedure
because of my Oracle background, but it doesn't really matter. This was
just a suggestion for the session settable parameters.
Regards
On 8/12/21 4:23 PM, Bruce Momjian wrote:
> I think you can write a SECURITY DEFINER function that calls SET, call
> that function at login.
--
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
@ 2021-08-12 20:28 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-12 20:37 ` Re: log_statement GUC parameter Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 1 reply; 9+ messages in thread
From: Adrian Klaver @ 2021-08-12 20:28 UTC (permalink / raw)
To: Mladen Gogala <gogala.mladen@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>
On 8/12/21 1:19 PM, Mladen Gogala wrote:
> Hi!
>
> The idea is to log all statements by the particular user, not by
> everybody. The user in question uses Weblogic 12.2.1.4 and creates a
> connection pool so I need to find out which statements are the longest
> running ones and make them perform.
Would pg_stat_statements work for you?:
https://www.postgresql.org/docs/current/pgstatstatements.html
>
> Regards
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:28 ` Re: log_statement GUC parameter Adrian Klaver <adrian.klaver@aklaver.com>
@ 2021-08-12 20:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-12 20:40 ` Re: log_statement GUC parameter Bruce Momjian <bruce@momjian.us>
2021-08-12 20:51 ` Re: log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
0 siblings, 2 replies; 9+ messages in thread
From: Tom Lane @ 2021-08-12 20:37 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Mladen Gogala <gogala.mladen@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>
[ dept. of second thoughts ]
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 8/12/21 1:19 PM, Mladen Gogala wrote:
>> The idea is to log all statements by the particular user, not by
>> everybody.
> Would pg_stat_statements work for you?:
> https://www.postgresql.org/docs/current/pgstatstatements.html
Actually, for that specific requirement, there's an easier way:
ALTER USER target_user SET log_statement = 'all';
While the target_user can't do that for himself, a superuser
can.
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:28 ` Re: log_statement GUC parameter Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-12 20:37 ` Re: log_statement GUC parameter Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-08-12 20:40 ` Bruce Momjian <bruce@momjian.us>
1 sibling, 0 replies; 9+ messages in thread
From: Bruce Momjian @ 2021-08-12 20:40 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Mladen Gogala <gogala.mladen@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>
On Thu, Aug 12, 2021 at 04:37:16PM -0400, Tom Lane wrote:
> [ dept. of second thoughts ]
>
> Adrian Klaver <adrian.klaver@aklaver.com> writes:
> > On 8/12/21 1:19 PM, Mladen Gogala wrote:
> >> The idea is to log all statements by the particular user, not by
> >> everybody.
>
> > Would pg_stat_statements work for you?:
> > https://www.postgresql.org/docs/current/pgstatstatements.html
>
> Actually, for that specific requirement, there's an easier way:
>
> ALTER USER target_user SET log_statement = 'all';
>
> While the target_user can't do that for himself, a superuser
> can.
Ah, yes, I hadn't considered that ALTER USER bypasses those user checks.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:28 ` Re: log_statement GUC parameter Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-12 20:37 ` Re: log_statement GUC parameter Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-08-12 20:51 ` Mladen Gogala <gogala.mladen@gmail.com>
1 sibling, 0 replies; 9+ messages in thread
From: Mladen Gogala @ 2021-08-12 20:51 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Thank you Tom! It turns out that the Oracle way of doing things
(SECURITY DEFINER) was the wrong way here. Thanks a bunch.
On 8/12/21 4:37 PM, Tom Lane wrote:
> ctually, for that specific requirement, there's an easier way:
>
> ALTER USER target_user SET log_statement = 'all';
>
> While the target_user can't do that for himself, a superuser
> can.
--
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
@ 2021-08-12 20:30 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-12 20:31 ` Re: log_statement GUC parameter Bruce Momjian <bruce@momjian.us>
2 siblings, 1 reply; 9+ messages in thread
From: Tom Lane @ 2021-08-12 20:30 UTC (permalink / raw)
To: Mladen Gogala <gogala.mladen@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Mladen Gogala <gogala.mladen@gmail.com> writes:
> Unfortunately, only a superuser can set log_statement='all'; Would it be
> possible to execute set session log_statement='all'; as an ordinary
> user? I am trying to execute it from login.sql, a part of login_hook
> extension which implements on-login triggers in PostgreSQL. I will
> create a procedure with security definer, owned by the role "postgres",
> and grant it to public. That should do the trick. However, it would be
> much nicer if PostgreSQL allowed me to set the parameter as a part of
> the normal session.
If an ordinary user could manipulate that parameter, he could equally
well hide his activities from the system log. Conversely, if the
postmaster log setup is such that not a lot of volume is expected,
then flooding it with extra traffic could create its own set of
problems. Thus, basically all parameters that affect what is logged
are superuser-only, and it'd be a hard sell to weaken that. The
SECURITY DEFINER function approach is your best bet for poking local
exceptions into that policy.
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: log_statement GUC parameter
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:30 ` Re: log_statement GUC parameter Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-08-12 20:31 ` Bruce Momjian <bruce@momjian.us>
0 siblings, 0 replies; 9+ messages in thread
From: Bruce Momjian @ 2021-08-12 20:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Mladen Gogala <gogala.mladen@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>
On Thu, Aug 12, 2021 at 04:30:12PM -0400, Tom Lane wrote:
> Mladen Gogala <gogala.mladen@gmail.com> writes:
> > Unfortunately, only a superuser can set log_statement='all'; Would it be
> > possible to execute set session log_statement='all'; as an ordinary
> > user? I am trying to execute it from login.sql, a part of login_hook
> > extension which implements on-login triggers in PostgreSQL. I will
> > create a procedure with security definer, owned by the role "postgres",
> > and grant it to public. That should do the trick. However, it would be
> > much nicer if PostgreSQL allowed me to set the parameter as a part of
> > the normal session.
>
> If an ordinary user could manipulate that parameter, he could equally
> well hide his activities from the system log. Conversely, if the
> postmaster log setup is such that not a lot of volume is expected,
> then flooding it with extra traffic could create its own set of
> problems. Thus, basically all parameters that affect what is logged
> are superuser-only, and it'd be a hard sell to weaken that. The
> SECURITY DEFINER function approach is your best bet for poking local
> exceptions into that policy.
The nice thing about SECURITY DEFINER is that the super user controls
what values it can be set to.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
If only the physical world exists, free will is an illusion.
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2021-08-12 20:51 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 20:19 log_statement GUC parameter Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:23 ` Bruce Momjian <bruce@momjian.us>
2021-08-12 20:49 ` Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:28 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-08-12 20:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-12 20:40 ` Bruce Momjian <bruce@momjian.us>
2021-08-12 20:51 ` Mladen Gogala <gogala.mladen@gmail.com>
2021-08-12 20:30 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-08-12 20:31 ` Bruce Momjian <bruce@momjian.us>
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