pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedlibpq PQstatus problem
4+ messages / 4 participants
[nested] [flat]
* libpq PQstatus problem
@ 2001-03-14 04:45 philip.howell@cit.act.edu.au
0 siblings, 3 replies; 4+ messages in thread
From: philip.howell@cit.act.edu.au @ 2001-03-14 04:45 UTC (permalink / raw)
To: pgsql-interfaces
Hi
I'm having problems with the PQstatus function in the libpq library. It seems
to return CONNECTION_OK when I know that it is not. I used the following test
program and method to test it:
------------------------
#include <stdlib.h>
#include <stdio.h>
#include "pgsql/libpq-fe.h"
PGconn *make_conn();
int main (int argc, char *argv[])
{
PGconn *conn;
conn = make_conn();
while (fgetc(stdin) != 'q')
{
printf("Connection status... ");
if (PQstatus(conn) != CONNECTION_OK) {
printf("BAD\n");
PQreset(conn);
} else {
printf("OK\n");
}
}
return(0);
}
PGconn *make_conn()
{
PGconn *conn;
conn = PQconnectdb("hostaddr = 161.50.16.173 dbname = squid user = squid
password = squid");
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr,"Failed to connect to database\n");
fprintf(stderr,"%s\n",PQerrorMessage(conn));
PQfinish(conn);
exit(1);
}
return(conn);
}
-------------------------
I ran the program (with my postgreSQL server up and running) and hit <return> a
few times, I got the following expected output:
>
> Connection status... OK
>
> Connection status... OK
>
> Connection status... OK
Then I stopped the network (eth0) on the postgreSQL server and hit <return>
again and still got
> Connection status... OK
as the output. However Trying to execute the program with the postgreSQL server
offline resulted in the expected error messages, so it seems that in this case
the status was detected successfully.
SYSTEM INFORMATION:
===================
postgreSQL Server:
Hardware: i386
OS Linux RedHat 6.2
Postgres was installed from RPMs version 7.0.3-2
Client Machine
Hardware: i386
OS: Linux RedHat 6.2 with the following RPMs installed:
postgresql-devel-7.0.3-2
postgresql-7.0.3-2
Regards
Phil
philip.howell@cit.act.edu.au
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: libpq PQstatus problem
@ 2001-03-14 05:16 Joe Conway <jconway2@home.com>
parent: philip.howell@cit.act.edu.au
2 siblings, 0 replies; 4+ messages in thread
From: Joe Conway @ 2001-03-14 05:16 UTC (permalink / raw)
To: philip.howell@cit.act.edu.au; pgsql-interfaces
>
> Then I stopped the network (eth0) on the postgreSQL server and hit
<return>
> again and still got
>
> > Connection status... OK
>
> as the output. However Trying to execute the program with the postgreSQL
server
> offline resulted in the expected error messages, so it seems that in this
case
> the status was detected successfully.
>
I tried stopping the network on my machine, and was still able to connect
when logged on locally via psql. I presume this is because the local unix
sockets connection still works from the local machine. You might test this
by editing your pg_hba.conf file to disallow local sockets. e.g.:
local all reject
Hope this helps,
Joe
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: libpq PQstatus problem
@ 2001-03-14 05:17 Joe Conway <joe.conway@mail.com>
parent: philip.howell@cit.act.edu.au
2 siblings, 0 replies; 4+ messages in thread
From: Joe Conway @ 2001-03-14 05:17 UTC (permalink / raw)
To: philip.howell@cit.act.edu.au; pgsql-interfaces
>
> Then I stopped the network (eth0) on the postgreSQL server and hit
<return>
> again and still got
>
> > Connection status... OK
>
> as the output. However Trying to execute the program with the postgreSQL
server
> offline resulted in the expected error messages, so it seems that in this
case
> the status was detected successfully.
>
I tried stopping the network on my machine, and was still able to connect
when logged on locally via psql. I presume this is because the local unix
sockets connection still works from the local machine. You might test this
by editing your pg_hba.conf file to disallow local sockets. e.g.:
local all reject
Hope this helps,
Joe
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: libpq PQstatus problem
@ 2001-03-14 05:52 Tom Lane <tgl@sss.pgh.pa.us>
parent: philip.howell@cit.act.edu.au
2 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2001-03-14 05:52 UTC (permalink / raw)
To: philip.howell@cit.act.edu.au; +Cc: pgsql-interfaces
<philip.howell@cit.act.edu.au> writes:
> Then I stopped the network (eth0) on the postgreSQL server and hit <return>
> again and still got
>> Connection status... OK
I don't believe this is a bug. PQstatus indicates whether you did make
a successful connection to the database server --- it is not intended to
be an up-to-the-nanosecond report on whether the network is still up or
not. In particular, the status will *not* be updated if you haven't
executed any new operations on the connection lately.
If you have a network that's so unstable that you need to program around
problems like this, consider 'ping'.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-03-14 05:52 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-14 04:45 libpq PQstatus problem philip.howell@cit.act.edu.au
2001-03-14 05:16 ` Joe Conway <jconway2@home.com>
2001-03-14 05:17 ` Joe Conway <joe.conway@mail.com>
2001-03-14 05:52 ` Tom Lane <tgl@sss.pgh.pa.us>
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