Thread: Can the frontend get notifications from the postgres server?

Can the frontend get notifications from the postgres server?

From
"Anagha Joshi"
Date:

Re: Can the frontend get notifications from the postgres server?

From
weigelt@metux.de
Date:
On Tue, Jun 17, 2003 at 10:09:04AM +0530, Anagha Joshi wrote:
>
(qestion in subject ...)

yes.
simply execute LISTEN <eventname>; on the one side and then
an NOTIFY <eventname> on the other side. on the next query
you'll see the notify. (you can easily try it w/ pgsql)

but i currently dont know, if you can receive notifies in php ...
that's what i'm really interested in ...

cu
--
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481         smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/

Re: Can the frontend get notifications from the postgres

From
"A.Bhuvaneswaran"
Date:
> yes.
> simply execute LISTEN <eventname>; on the one side and then
> an NOTIFY <eventname> on the other side. on the next query
> you'll see the notify. (you can easily try it w/ pgsql)
>
> but i currently dont know, if you can receive notifies in php ...
> that's what i'm really interested in ...

LISTEN/NOTIFY is yet another SQL. We can write a rule on an event and let
it notify. On the other hand, we can have a while(1) process which keeps
listening for that notification ie.. event. Once the event is occured, the
listening process would be notified. The listening process can be any
postgresql client including the one written in C, perl, php, etc.

regards,
bhuvaneswaran


Re: Can the frontend get notifications from the postgres server?

From
weigelt@metux.de
Date:
On Tue, Jun 17, 2003 at 12:07:31PM +0530, A.Bhuvaneswaran wrote:

<snip>
> LISTEN/NOTIFY is yet another SQL. We can write a rule on an event and let
> it notify. On the other hand, we can have a while(1) process which keeps
> listening for that notification ie.. event. Once the event is occured, the
> listening process would be notified. The listening process can be any
> postgresql client including the one written in C, perl, php, etc.
But the problem still is: how to receive the NOTIFY from an php script ?
which function of the c-client lib can be used for this ?

cu
--
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481         smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/

Re: Can the frontend get notifications from the postgres

From
"scott.marlowe"
Date:
On Tue, 17 Jun 2003 weigelt@metux.de wrote:

> On Tue, Jun 17, 2003 at 12:07:31PM +0530, A.Bhuvaneswaran wrote:
>
> <snip>
> > LISTEN/NOTIFY is yet another SQL. We can write a rule on an event and let
> > it notify. On the other hand, we can have a while(1) process which keeps
> > listening for that notification ie.. event. Once the event is occured, the
> > listening process would be notified. The listening process can be any
> > postgresql client including the one written in C, perl, php, etc.
> But the problem still is: how to receive the NOTIFY from an php script ?
> which function of the c-client lib can be used for this ?

If you're talking about a PHP script running under apache as a module or
CGI, then you probably can't (or if you can, you shouldn't due to time out
issues and such.)

Note that PHP really is a "real programming language", and if you write a
program to execute from the command line and detach it can run in the back
ground like any other language, even starting child processes and having
IPC and all that.  Look up the "Process Control Functions" for more on
satrting child processes and all.

Note that the pcntl_* functions are not guaranteed to behave when run
under apache / as a CGI etc...


Re: Can the frontend get notifications from the postgres

From
"A.Bhuvaneswaran"
Date:
> > LISTEN/NOTIFY is yet another SQL. We can write a rule on an event and let
> > it notify. On the other hand, we can have a while(1) process which keeps
> > listening for that notification ie.. event. Once the event is occured, the
> > listening process would be notified. The listening process can be any
> > postgresql client including the one written in C, perl, php, etc.
> But the problem still is: how to receive the NOTIFY from an php script ?
> which function of the c-client lib can be used for this ?

In perl, if i am correct, DBD::Pg does not support it. But, Pg - Perl5
extension for postgresql does it. The functions consumeInput() and
notifies can be used to access the notifyname and pid of backend process.
Refer the man page of Pg module for details.

In C, the functions PQconsumeInput() and PQnotifies can be used to access
the notifyname and pid of backend process. Refer the libpq man page for
details.

In php 4.3.0, the function pg_get_notify() can be used to access the
notifyname and pid of backend process. For details, please refer the below
link:

http://www.science.uva.nl/ict/documentation/php4/function.pg-get-notify.html

Hope it helps.

regards,
bhuvaneswaran


Re: Can the frontend get notifications from the postgres server?

From
weigelt@metux.de
Date:
On Tue, Jun 17, 2003 at 06:08:43AM -0600, scott.marlowe wrote:

<snip>
> > But the problem still is: how to receive the NOTIFY from an php script ?
> > which function of the c-client lib can be used for this ?
>
> If you're talking about a PHP script running under apache as a module or
> CGI, then you probably can't (or if you can, you shouldn't due to time out
> issues and such.)
No. The script is running as an standalone process (works as application server).
The Problem is, how to get the NOTIFY message, which is received from the
RDBMS somewhere in the client lib, to the php script.
When using psql, the NOTIFY is displayed after sending an query. It seems
that it is sent within the server's reply to the query. But i dont know
how the clientlib hands it to the application.

cu
--
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481         smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/

Re: Can the frontend get notifications from the postgres server?

From
weigelt@metux.de
Date:
On Tue, Jun 17, 2003 at 05:57:32PM +0530, A.Bhuvaneswaran wrote:

<snip>
> In php 4.3.0, the function pg_get_notify() can be used to access the
> notifyname and pid of backend process. For details, please refer the below
> link:
aaah. that's what i needed :)

cu
--
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481         smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/

Re: Can the frontend get notifications from the postgres server?

From
"Brent Howard"
Date:


On Tue, Jun 17, 2003 at 08:39:00 AM weigelt@metux.de [mailto:weigelt@metux.de] wrote:

<snip?
<snip>
|>> > But the problem still is: how to receive the NOTIFY from an php script ?
|>> > which function of the c-client lib can be used for this ?
|>>
|>> If you're talking about a PHP script running under apache as a module or
|>> CGI, then you probably can't (or if you can, you shouldn't due to time out
|>> issues and such.)
|>No. The script is running as an standalone process (works as application server).
|>The Problem is, how to get the NOTIFY message, which is received from the
|>RDBMS somewhere in the client lib, to the php script.
|>When using psql, the NOTIFY is displayed after sending an query. It seems
|>that it is sent within the server's reply to the query. But i dont know
|>how the clientlib hands it to the application.
|>
|>cu
|>--

I believe Postgres supports asynchronous notification via the LISTEN and NOTIFY commands. If the backend registers its
interestin a particular relation with the LISTEN command, then all backends listening on a particular relation will be
notifiedasynchronously when a NOTIFY of that relation name is executed by another backend.  

No additional information is passed from the notifier to the listener. Thus, typically, any actual data that needs to
becommunicated is transferred through the relation.  

libpq applications are notified whenever a connected backend has received an asynchronous notification. However, the
communicationfrom the backend to the frontend is not asynchronous. Notification comes piggy-backed on other query
results.Thus, an application must submit queries, even empty ones, in order to receive notice of backend notification.
Ineffect, the libpq application must poll the backend to see if there is any pending notification information. After
theexecution of a query, a frontend may call PQNotifies to see if any notification data is available from the backend.  



---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481         smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@postgresql.org so that your
      message can get through to the mailing list cleanly

psql DBNAME -U USER (how to disable -U option?)

From
"Mel Jamero"
Date:
to get to the psql interface we execute:

psql dbname -U user

is it possible to disable the -U option such that a user cannot invoke the
privileges of a database superuser such as postgres?

tried looking up pg_hba.conf regarding 'password' authentication, the man
pages and the archives but didn't get too lucky.

thanks in advance.

mel


Attachment

Re: psql DBNAME -U USER (how to disable -U option?)

From
"scott.marlowe"
Date:
On Tue, 17 Jun 2003, Mel Jamero wrote:

> to get to the psql interface we execute:
>
> psql dbname -U user
>
> is it possible to disable the -U option such that a user cannot invoke the
> privileges of a database superuser such as postgres?
>
> tried looking up pg_hba.conf regarding 'password' authentication, the man
> pages and the archives but didn't get too lucky.

Did you stop / start postgresql after the changes?  Make sure you don't
have a line for "trust" 127.0.0.1 as well.


Re: psql DBNAME -U USER (how to disable -U option?)

From
"scott.marlowe"
Date:
On Tue, 17 Jun 2003, scott.marlowe wrote:

> On Tue, 17 Jun 2003, Mel Jamero wrote:
>
> > to get to the psql interface we execute:
> >
> > psql dbname -U user
> >
> > is it possible to disable the -U option such that a user cannot invoke the
> > privileges of a database superuser such as postgres?
> >
> > tried looking up pg_hba.conf regarding 'password' authentication, the man
> > pages and the archives but didn't get too lucky.
>
> Did you stop / start postgresql after the changes?  Make sure you don't
> have a line for "trust" 127.0.0.1 as well.

As a followup to that, look into ident method of authentication as well.


Re: Can the frontend get notifications from the postgres server?

From
Jonathan Gardner
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 17 June 2003 01:01, weigelt@metux.de wrote:
> On Tue, Jun 17, 2003 at 12:07:31PM +0530, A.Bhuvaneswaran wrote:
>
> But the problem still is: how to receive the NOTIFY from an php script ?
> which function of the c-client lib can be used for this ?
>

Why in the world would you want to? Think about this for a moment: The script
runs in under a second - why would it want to sit around and wait for a
notification?

- --
Jonathan Gardner <jgardner@jonathangardner.net>
(was jgardn@alumni.washington.edu)
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+73wRWgwF3QvpWNwRAistAJ4osnbDTKNQfg/0e83yR4SGq2eWSQCgy5iQ
8jx/eb09AFe4Kiy9WDhJa+k=
=vilQ
-----END PGP SIGNATURE-----