Thread: PostgreSQL Log Info

PostgreSQL Log Info

From
Jethish Jethish
Date:
Hi Everyone,

Is it possible to log the rows returned by a query in the PostgreSQL logs?

Re: PostgreSQL Log Info

From
"David G. Johnston"
Date:
On Thursday, November 21, 2024, Jethish Jethish <jethish777@gmail.com> wrote:
Is it possible to log the rows returned by a query in the PostgreSQL logs?

As a practical matter, no.  That said, given one can get row contents into the server log in various ways, what is the use case for why this capability is thought to be needed?

David J. 

Re: PostgreSQL Log Info

From
Jethish Jethish
Date:

Hi David,

If an select query is fired I need the query returned values needs to be logged in my PostgreSQL log file.


For example if a select query returns 5 rows I need the same in the log file 


On Fri, Nov 22, 2024, 10:49 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thursday, November 21, 2024, Jethish Jethish <jethish777@gmail.com> wrote:
Is it possible to log the rows returned by a query in the PostgreSQL logs?

As a practical matter, no.  That said, given one can get row contents into the server log in various ways, what is the use case for why this capability is thought to be needed?

David J. 

Re: PostgreSQL Log Info

From
Ron Johnson
Date:
Isn't "I need the query returned values" the purpose of the client application?

On Fri, Nov 22, 2024 at 2:32 AM Jethish Jethish <jethish777@gmail.com> wrote:

Hi David,

If an select query is fired I need the query returned values needs to be logged in my PostgreSQL log file.


For example if a select query returns 5 rows I need the same in the log file 


On Fri, Nov 22, 2024, 10:49 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thursday, November 21, 2024, Jethish Jethish <jethish777@gmail.com> wrote:
Is it possible to log the rows returned by a query in the PostgreSQL logs?

As a practical matter, no.  That said, given one can get row contents into the server log in various ways, what is the use case for why this capability is thought to be needed?

David J. 


--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!

Re: PostgreSQL Log Info

From
hubert depesz lubaczewski
Date:
On Fri, Nov 22, 2024 at 01:02:27PM +0530, Jethish Jethish wrote:
> Hi David,
> 
> If an select query is fired I need the query returned values needs to be
> logged in my PostgreSQL log file.
> 
> 
> For example if a select query returns 5 rows I need the same in the log
> file

Please note that you wrote what you want to do. And David asked about
use case. Which is different.

Basically the question can be summed into: *why* you think you want
that.

I don't think anything even remotely similar to this exists. You could,
of course, add it to Pg by changing sources (it is open source after
all), but given that such feature would be downright dangerous for huge
majority of situations, I don't expect it to become reality in mainline
Pg.

Best regards,

depesz




Re: PostgreSQL Log Info

From
Karsten Hilbert
Date:
Am Fri, Nov 22, 2024 at 01:02:27PM +0530 schrieb Jethish Jethish:

> If an select query is fired I need the query returned values needs to be
> logged in my PostgreSQL log file.

What do you expect your log file to be in size after, say, a
day of activity ?

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B



Re: PostgreSQL Log Info

From
Adrian Klaver
Date:
On 11/21/24 23:32, Jethish Jethish wrote:
> Hi David,
> 
> If an select query is fired I need the query returned values needs to be 
> logged in my PostgreSQL log file.
> 
> 
> For example if a select query returns 5 rows I need the same in the log 
> file

What if the query returns 500,000 rows?


What is the purpose of retaining this information?

> 
> 
> On Fri, Nov 22, 2024, 10:49 AM David G. Johnston 
> <david.g.johnston@gmail.com <mailto:david.g.johnston@gmail.com>> wrote:
> 
>     On Thursday, November 21, 2024, Jethish Jethish
>     <jethish777@gmail.com <mailto:jethish777@gmail.com>> wrote:
> 
>         Is it possible to log the rows returned by a query in the
>         PostgreSQL logs?
> 
> 
>     As a practical matter, no.  That said, given one can get row
>     contents into the server log in various ways, what is the use case
>     for why this capability is thought to be needed?
> 
>     David J.
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com




Re: PostgreSQL Log Info

From
"David G. Johnston"
Date:
On Fri, Nov 22, 2024 at 12:32 AM Jethish Jethish <jethish777@gmail.com> wrote:

If an select query is fired I need the query returned values needs to be logged in my PostgreSQL log file.

Then the answer is no, and unlikely to become a feature anyone would develop or that we'd accept.

A more innovative solution is going to need to be thought up to satisfy the security people that want to know what data was acquired from their system by either their users or semi-privileged hackers (privileged exploits would likely just disable such logging anyway).  The space of setting up a proxy server in between clients and the PostgreSQL server is under-explored as a means by which to incorporate such functionality externally to the core server.

David J.

Re: PostgreSQL Log Info

From
Jethish Jethish
Date:

Sorry guys, what I meant was to log the tuple returned count not the values to get printed in logs.


On Fri, Nov 22, 2024, 9:46 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Fri, Nov 22, 2024 at 12:32 AM Jethish Jethish <jethish777@gmail.com> wrote:

If an select query is fired I need the query returned values needs to be logged in my PostgreSQL log file.

Then the answer is no, and unlikely to become a feature anyone would develop or that we'd accept.

A more innovative solution is going to need to be thought up to satisfy the security people that want to know what data was acquired from their system by either their users or semi-privileged hackers (privileged exploits would likely just disable such logging anyway).  The space of setting up a proxy server in between clients and the PostgreSQL server is under-explored as a means by which to incorporate such functionality externally to the core server.

David J.

Re: PostgreSQL Log Info

From
Adrian Klaver
Date:
On 11/21/24 21:02, Jethish Jethish wrote:
> Hi Everyone,
> 
> Is it possible to log the rows returned by a query in the PostgreSQL logs?

https://github.com/pgaudit/pgaudit/blob/main/README.md

"pgaudit.log_rows

Specifies that audit logging should include the number of rows retrieved 
or affected by a statement. When enabled the rows field will be included 
after the parameter field.

The default is off."

-- 
Adrian Klaver
adrian.klaver@aklaver.com




Re: PostgreSQL Log Info

From
"David G. Johnston"
Date:
On Fri, Nov 22, 2024 at 9:26 AM Jethish Jethish <jethish777@gmail.com> wrote:

Sorry guys, what I meant was to log the tuple returned count not the values to get printed in logs.

That too is a no.  Though more because is just doesn't seem useful enough to expend effort on designing and implementing something.

There is a work-around in that you could enable auto-explain with analyze and read the actuals from that.

David J.