Monitoring Postgres - Get the SQL queries which are sent to postgres

Started by Nico Grubertover 19 years ago4 messagesgeneral
Jump to latest
#1Nico Grubert
nicogrubert@gmail.com

Dear list members,

I have a web application running that is connected to my postgres
database. This web application builds dynamically SQL queries and
queries the postgres database. I would like to see these SQL queries.
How can I do this? Is there a way to monitor the SQL queries which are
sent to my postgres database?

Thanks in advance,
Nico

#2Merlin Moncure
mmoncure@gmail.com
In reply to: Nico Grubert (#1)
Re: Monitoring Postgres - Get the SQL queries which are sent to postgres

On 10/25/06, Nico Grubert <nicogrubert@gmail.com> wrote:

Dear list members,

I have a web application running that is connected to my postgres
database. This web application builds dynamically SQL queries and
queries the postgres database. I would like to see these SQL queries.
How can I do this? Is there a way to monitor the SQL queries which are
sent to my postgres database?

see logging features in postgresql.conf. I suggest redirecting stderr
to pg_log and playing with rotation features.

merlin

#3A. Kretschmer
andreas.kretschmer@schollglas.com
In reply to: Nico Grubert (#1)
Re: Monitoring Postgres - Get the SQL queries which are sent to postgres

am Wed, dem 25.10.2006, um 15:56:17 +0200 mailte Nico Grubert folgendes:

Dear list members,

I have a web application running that is connected to my postgres
database. This web application builds dynamically SQL queries and
queries the postgres database. I would like to see these SQL queries.
How can I do this? Is there a way to monitor the SQL queries which are
sent to my postgres database?

Set this in your postgresql.conf:

log_statement = all

Reload the server, and then you can find all your statements in the log.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

#4Vick Khera
vivek@khera.org
In reply to: A. Kretschmer (#3)
Re: Monitoring Postgres - Get the SQL queries which are sent to postgres

On Oct 25, 2006, at 10:11 AM, A. Kretschmer wrote:

Set this in your postgresql.conf:

log_statement = all

Reload the server, and then you can find all your statements in the
log.

or, preferably, on a per-connection basis, execute this SQL statement:

set log_min_duration_statement = 0

then only those queries for that connection will be logged.
otherwise you get *way* too much stuff to sort out.

Another useful setting which I always enable (in my postgresql.conf
file) is

log_min_error_statement = error

so that any statement that generates an error will be appended to the
error log entry. otherwise you just see the error notice and have no
clue what caused it.

Attachments:

smime.p7sapplication/pkcs7-signature; name=smime.p7sDownload