By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

notify problem

P: n/a
Hi to all

I have problem with NOTIFY/LISTEN ...
I'm writing a C++ application with libpqxx, I thought was a problem of
the lib but I try also with a C program using libpq with the same
result, so maybe there is something else of wrong.

Using the example 2 in the libpq chapter on "Postgres Programmer's
Guide" as template i write :

!---------->
#include <unistd.h>
#include <libpq-fe.h>

int main() {

PGconn *conn;
PGresult *res;
PGnotify *notify;

int i;

conn = PQconnectdb ("host=localhost user=test dbname=test");

if (PQstatus(conn) == CONNECTION_BAD) {
fprintf(stderr,"failed connecting.\n");
PQfinish(conn);
exit(1);
}

res = PQexec(conn, "LISTEN alert");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
fprintf(stderr,"failed listening.\n");
PQclear(res);
PQfinish(conn);
exit(1);
}

PQclear(res);

for(i = 0; i < 80 ; ++i) {
sleep(1);
PQconsumeInput(conn);
while ((notify = PQnotifies(conn)) != NULL) {
fprintf(stderr,"\nGOT NOTIFY!!!\n");
free(notify);
}
fprintf(stderr,".");
}

PQfinish(conn);

return 0;
}
<----------!
On a console with psql I issue some notify with
NOTIFY alert; COMMIT;

but nothing are catched !!!

if in another console with psql i do a "LISTEN alert;" all work
correctly.

I'm using Linux, RedHat 9, so PostgreSQL 7.3.2.
user and database are created with :
createuser -h localhost -U postgres -D -A -P test
createdb -O test -h localhost -U postgres test

and nothing alse, the database are empty.

what's wrong ???

Thanks.
--
Alessandro GARDICH <gr*****@gremlin.it>
gremlin.it

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Alessandro GARDICH <gr*****@gremlin.it> writes:
res = PQexec(conn, "LISTEN alert"); for(i = 0; i < 80 ; ++i) {
sleep(1);
PQconsumeInput(conn);
while ((notify = PQnotifies(conn)) != NULL) {
fprintf(stderr,"\nGOT NOTIFY!!!\n");
free(notify);
}
fprintf(stderr,".");
} On a console with psql I issue some notify with
NOTIFY alert; COMMIT;
but nothing are catched !!!


Hm. Should I guess from the above that you've set autocommit off in
postgresql.conf? If so, your problem is you didn't commit the LISTEN.
Notifications are not sent to clients that are in open transactions.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.