Re: How to log query's from servers ?

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: condor(at)stz-bg(dot)com
Cc: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to log query's from servers ?
Date: 2011-06-06 17:32:57
Message-ID: BANLkTim8MqLBWPJquJbbLmB-b60emuLrXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jun 6, 2011 at 7:26 AM, Condor <condor(at)stz-bg(dot)com> wrote:
> On Mon, 06 Jun 2011 18:53:57 +0800, Craig Ringer wrote:
>>
>> On 6/06/2011 4:14 PM, Condor wrote:
>>>
>>> Hello ppl,
>>> any one can tell me how i make my postgresql server to log commands
>>> coming from another postgres server ? I have one postgresql and give to
>>> 2 other sql server to access my db. I want to log all query's coming
>>> only from one of the servers. Is that possibly ?
>>
>> If the different servers log in with different user accounts or log
>> into different databases you could use database-level or user-level
>> SET commands to set log_statement for only one of them.
>>
>> Otherwise: just grep the logs.
>
> Can you explain little more how i can use database-level or user-level
> SET commands to set log_statement for only one of them ?
> From server that i want to log his query i log in to db on another server
> with: psql -U user -h 192.168.1.1 master_db. Here maybe I should say that I
> wanna
> monitor users that I gave them access to DB.
> Every server use different username to connect. I can't use grep on logs
> because
> other two servers generate around 500 MB to 1 GB log file per day.
>
> Probably, a little filter or patch on postgresql source code file which
> manage logs to write log file
> only if ip is the ip that i want will save me.

What you are looking for are alter statements. On pretty new psql,
they'll be show with \h commands. you'll want something like this:

alter database mydb set log_statement='all';
alter user bubba set log_statement='all';

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-06-06 18:40:18 Re: Non returning Transactions/Many Locks in Postgres 9.0.4 and 9.0.1
Previous Message Alvaro Herrera 2011-06-06 17:04:41 Re: Postmaster holding unlinked files for pg_largeobject table