pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
debug a mess
9+ messages / 4 participants
[nested] [flat]

* debug a mess
@ 2003-02-25 18:41  Wei Weng <wweng@kencast.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Wei Weng @ 2003-02-25 18:41 UTC (permalink / raw)
  To: pgsql-interfaces

I am trying to figure out where the "NOTICE:  current transaction is aborted,
queries ignored until end of transaction block" comes from in my code.
Basically, this is what it does:

CString strQuery 
= "SELECT datname FROM pg_database WHERE name = 'mydatabase'";

if (NULL == (res = PQexec(pgconn, (CSTR) strQuery)))
{
    ErrorQuit(PQerrorMessage(pgconn));
}

It is really very simple code, but each time I try to run it, the postgresql
backend gives me the "transaction aborted" error message. I checked the
mailing list archive, and Tom once explained that the reason for this error
message is the backend had quitted for some reason. Is there anyway to see
why the backend aborted the transaction?? It could be really helpful.


Thanks


Wei




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-25 20:29  Matthew Vanecek <mevanecek@yahoo.com>
  parent: Wei Weng <wweng@kencast.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Matthew Vanecek @ 2003-02-25 20:29 UTC (permalink / raw)
  To: pgsql-interfaces

On Tue, 2003-02-25 at 12:41, Wei Weng wrote:
> I am trying to figure out where the "NOTICE:  current transaction is aborted,
> queries ignored until end of transaction block" comes from in my code.
> Basically, this is what it does:
> 
> CString strQuery 
> = "SELECT datname FROM pg_database WHERE name = 'mydatabase'";
> 
> if (NULL == (res = PQexec(pgconn, (CSTR) strQuery)))
> {
>     ErrorQuit(PQerrorMessage(pgconn));
> }
> 
> It is really very simple code, but each time I try to run it, the postgresql
> backend gives me the "transaction aborted" error message. I checked the
> mailing list archive, and Tom once explained that the reason for this error
> message is the backend had quitted for some reason. Is there anyway to see
> why the backend aborted the transaction?? It could be really helpful.
> 

It sounds like you've executed a query or command, and have not called
PQclear(result) on the results.  Whenever I've gottten that error, not
clearing the results has always been the root cause.  Make sure result
is not NULL first, of course...


-- 
Matthew Vanecek
perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
********************************************************************************
For 93 million miles, there is nothing between the sun and my shadow except me.
I'm always getting in the way of something...

Attachments:

  signature.asc (application/pgp-signature, 231B) download

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-25 20:58  Wei Weng <wweng@kencast.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Wei Weng @ 2003-02-25 20:58 UTC (permalink / raw)
  To: Matthew Vanecek <mevanecek@yahoo.com>; +Cc: pgsql-interfaces

On 25/02/03 14:29 -0600, Matthew Vanecek wrote:
> It sounds like you've executed a query or command, and have not called
> PQclear(result) on the results.  Whenever I've gottten that error, not
> clearing the results has always been the root cause.  Make sure result
> is not NULL first, of course...
> 
>
The entire code from PQconnect until PQfinish goes like this:

    pgconn = PQconnect(init_string);

    res = PQexec(pgconn, my_query);

    if (res == NULL)
        quit;

    switch( PQresultStatus(res) )
    {
        case ... goto _end;
        case ... goto _end;
        ...
        default ... goto _end;
    }

    PQclear(res);
    res = NULL;

_end:
    if (res)
        PQclear(res);

    PQfinish(pgconn);


This is pretty much the skeleton of the code, as you can see, I treat res
pretty carefully, PQclear it whenever necessary.

Thanks


Wei






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-25 21:24  Jeroen T. Vermeulen <jtv@xs4all.nl>
  parent: Wei Weng <wweng@kencast.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Jeroen T. Vermeulen @ 2003-02-25 21:24 UTC (permalink / raw)
  To: Wei Weng <wweng@kencast.com>; +Cc: Matthew Vanecek <mevanecek@yahoo.com>; pgsql-interfaces

On Tue, Feb 25, 2003 at 03:58:20PM -0500, Wei Weng wrote:
> 
>     switch( PQresultStatus(res) )
>     {
>         case ... goto _end;
>         case ... goto _end;
>         ...
>         default ... goto _end;
>     }
 
Why do you call that label "_end"?  AFAIK names starting with
underscores are reserved for use by the compiler, the standard
library, etc.  Never start your identifiers and such with underscores.
A name like _end in particular could mean something special to the
compiler or linker and screw things up that way.  Why not call it
bailout or something?

 
> This is pretty much the skeleton of the code, as you can see, I treat res
> pretty carefully, PQclear it whenever necessary.

And what are the queries you issue?  Do you "begin" a transaction?
Are there any errors before the one you're looking at?


Jeroen




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-25 21:27  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Wei Weng <wweng@kencast.com>
  1 sibling, 1 reply; 9+ messages in thread

From: Tom Lane @ 2003-02-25 21:27 UTC (permalink / raw)
  To: Wei Weng <wweng@kencast.com>; +Cc: Matthew Vanecek <mevanecek@yahoo.com>; pgsql-interfaces

Wei Weng <wweng@kencast.com> writes:
> The entire code from PQconnect until PQfinish goes like this:

That sure looks harmless.  I wonder if there is something failing in the
PQconnect() step (like the queries that libpq sends on its own)?

I'd suggest enabling query logging --- see postgresql.conf, or just do
	export PGOPTIONS="--log_statement=1"
before starting your program.  (Check Admin Guide first, as this
parameter got renamed recently.)  Then look in the postmaster log to get
a better idea of what's really going on.

BTW, I'm pretty sure that PQclear, and most other libpq functions,
behave sanely when handed a null pointer.  So the test in
>     if (res)
>         PQclear(res);
is unnecessary.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-26 21:10  Wei Weng <wweng@kencast.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 9+ messages in thread

From: Wei Weng @ 2003-02-26 21:10 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Matthew Vanecek <mevanecek@yahoo.com>; pgsql-interfaces

On 25/02/03 16:27 -0500, Tom Lane wrote:
> Wei Weng <wweng@kencast.com> writes:
> > The entire code from PQconnect until PQfinish goes like this:
> 
> That sure looks harmless.  I wonder if there is something failing in the
> PQconnect() step (like the queries that libpq sends on its own)?
> 
> I'd suggest enabling query logging --- see postgresql.conf, or just do
> 	export PGOPTIONS="--log_statement=1"
> before starting your program.  (Check Admin Guide first, as this
> parameter got renamed recently.)  Then look in the postmaster log to get
> a better idea of what's really going on.
 <snip>

Where is postmaster log? I found a new file in /var/log/pgsql. I put
log_connections = yes and syslog = 2 into my postgresql.conf file and expect
something to happen. Restarted postgresql service on my redhat 7.3 box and
tried a couple of queries with psql utility. Nothing seemed to have been
logged in /var/log/pgsql.

Under /var/lib/pgsql/data, there isn't any new files appearing. 

By the way, how do I check to see what kind of options had been used in my
postgresql build?


Thanks

Wei




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-26 21:34  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Wei Weng <wweng@kencast.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Tom Lane @ 2003-02-26 21:34 UTC (permalink / raw)
  To: Wei Weng <wweng@kencast.com>; +Cc: Matthew Vanecek <mevanecek@yahoo.com>; pgsql-interfaces

Wei Weng <wweng@kencast.com> writes:
> Where is postmaster log? I found a new file in /var/log/pgsql. I put
> log_connections = yes and syslog = 2 into my postgresql.conf file and expect
> something to happen. Restarted postgresql service on my redhat 7.3 box and
> tried a couple of queries with psql utility. Nothing seemed to have been
> logged in /var/log/pgsql.

If you want to use syslog then you'd better be sure that syslogd is
configured to do something useful with Postgres messages, and not just
drop 'em on the floor.

If you want to use stderr, look at the start script.  Some distros
provide Postgres start scripts that route the postmaster's stderr to
/dev/null --- either explicitly, or by using the infamous -S switch.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-27 17:18  Wei Weng <wweng@kencast.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 9+ messages in thread

From: Wei Weng @ 2003-02-27 17:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

On 26/02/03 16:34 -0500, Tom Lane wrote:
> Wei Weng <wweng@kencast.com> writes:
> > Where is postmaster log? I found a new file in /var/log/pgsql. I put
> > log_connections = yes and syslog = 2 into my postgresql.conf file and expect
> > something to happen. Restarted postgresql service on my redhat 7.3 box and
> > tried a couple of queries with psql utility. Nothing seemed to have been
> > logged in /var/log/pgsql.
> 
> If you want to use syslog then you'd better be sure that syslogd is
> configured to do something useful with Postgres messages, and not just
> drop 'em on the floor.
> 
> If you want to use stderr, look at the start script.  Some distros
> provide Postgres start scripts that route the postmaster's stderr to
> /dev/null --- either explicitly, or by using the infamous -S switch.
> 
Tom:

I checked pg_config's output, in my redhat build, syslog is already enabled.
So that clears some of my doubt.

This is how I started my postmaster.

su postgres

/usr/bin/pg_ctl  -D $PGDATA -l /var/log/pgsql -p /usr/bin/postmaster start >
/var/log/pgsql 2>&1

I am trying my best to force the postmaster to write to the /var/log/pgsql
file. But it didn't seem to work at all. All there in /var/log/pgsql is a
oneline "postmaster successfully started". I checked the manpages, and all
they say about log is use -l switch (which I used).

Can you provide a little more hints?

Thanks!

Wei




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: debug a mess
@ 2003-02-27 18:05  Wei Weng <wweng@kencast.com>
  parent: Wei Weng <wweng@kencast.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Wei Weng @ 2003-02-27 18:05 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces

> Tom:
> 
> I checked pg_config's output, in my redhat build, syslog is already enabled.
> So that clears some of my doubt.
> 
> This is how I started my postmaster.
> 
> su postgres
> 
> /usr/bin/pg_ctl  -D $PGDATA -l /var/log/pgsql -p /usr/bin/postmaster start >
> /var/log/pgsql 2>&1
> 
> I am trying my best to force the postmaster to write to the /var/log/pgsql
> file. But it didn't seem to work at all. All there in /var/log/pgsql is a
> oneline "postmaster successfully started". I checked the manpages, and all
> they say about log is use -l switch (which I used).
> 
> Can you provide a little more hints?
> 
> Thanks!
> 
Actually, never mind that. :)

I changed the setting in postgresql.conf to syslog = 1 and everything now
spills out of both standard out (which directs to /var/log/pgsql) and syslog
(which I still don't know where it is being stored).

Wei




^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2003-02-27 18:05 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-25 18:41 debug a mess Wei Weng <wweng@kencast.com>
2003-02-25 20:29 ` Matthew Vanecek <mevanecek@yahoo.com>
2003-02-25 20:58 Re: debug a mess Wei Weng <wweng@kencast.com>
2003-02-25 21:24 ` Jeroen T. Vermeulen <jtv@xs4all.nl>
2003-02-25 21:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-26 21:10   ` Wei Weng <wweng@kencast.com>
2003-02-26 21:34     ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-27 17:18       ` Wei Weng <wweng@kencast.com>
2003-02-27 18:05         ` Wei Weng <wweng@kencast.com>

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