Re: Where I find examples of pqtrace? - Mailing list pgsql-general

From Volkan YAZICI
Subject Re: Where I find examples of pqtrace?
Date
Msg-id 20060518090606.GB223@alamut
Whole thread Raw
In response to Re: Where I find examples of pqtrace ???  ("Jim C. Nasby" <jnasby@pervasive.com>)
List pgsql-general
On Sat, May 06, 2006 at 12:08:32AM -0300, Marcelo Fabiano da Silveira wrote:
> I Have some questions of use PQtrace in Windows' systens....
>
> 1- The implementation of PQtrace, is possible ONLY with non bloking
> connections ???
> 2- Please, I need same samples of implementation of PQtrace.

PQtrace(PGconn *conn, FILE *fp) enables logging of sent/received data
(appears on PGconn *conn), to the file pointed by FILE *fp. It achieves
this by making simple fprintf(fp, ...) calls using the file pointed by fp.
(I hope above explanation also answers to your 1st question.)

Here's a simple use case:

PGconn *conn = PQconnectdb("...");
FILE   *fp;

fp = fopen(...);
if (!fp)
{
    /*
     * It's programmer's responsibility to take care of the file
     * pointer. Moreover, a blocking socket (on the FILE *fp) will
     * cause fprintf(fp, ...) calls to block too, which is an undesired
     * behaviour for an API. So you should take the care of consistency
     * of this part too.
     */
}

/*
 * File is opened with success and we're sure it won't block for
 * writing.
 */
PQtrace(conn, fp);

...

/*
 * We won't need a connection anymore. Thus, droping connection and its
 * tracing.
 */
PQuntrace(conn);
PQfinish(conn);


Regards.

pgsql-general by date:

Previous
From: Florian Weimer
Date:
Subject: Re: Announce: GPL Framework centered on Postgres
Next
From: Sim Zacks
Date:
Subject: table variables