Обсуждение: implementing a psql daemon

Поиск
Список
Период
Сортировка

implementing a psql daemon

От
Marc Tardif
Дата:
I have come to like postgresql and I have written many utilities for
internal usage, mostly related to my mailing list manager. The actual
mailinst list program is written in c and opens and closes only a single
connection for each email received. The problem is mostly with the
utilities which are shell scripts using psql between 1 and 5 times per
script. Needless to say, I can expect to waste many resources if/when
traffic becomes more important.

The solution to this problem could be to write a daemon which would leave
a connection open to a postgresql database. Then, when data is needed, I
could pass the query using shared memory and perhaps semaphores to avoid
concurrent access to the daemon therefore avoiding the overhead of
creating a connection each time. I could then use this same method for my
mailing list manager and each utility (which would have to be re-written
in c) all of which would use the same connection provided by the daemon.

Unfortunately, my understanding of the subject is somewhat limited. I can
manage to write the daemon using books and sample source code, but I'm not
in a position to weigh the pros and cons of such a solution. Therefore, I
would like to sollicit your feedback to gain a better understanding of the
problem at hand.

Looking forward to your insight,
Marc


Re: [GENERAL] implementing a psql daemon

От
Adriaan Joubert
Дата:
Marc Tardif wrote:

>
> The solution to this problem could be to write a daemon which would leave
> a connection open to a postgresql database. Then, when data is needed, I
> could pass the query using shared memory and perhaps semaphores to avoid
> concurrent access to the daemon therefore avoiding the overhead of
> creating a connection each time. I could then use this same method for my
> mailing list manager and each utility (which would have to be re-written
> in c) all of which would use the same connection provided by the daemon.

A lot of this type of code has been written before. I found in similar
situations that the easiest way to do this is to use an Apache web server
with mod_perl or fastcgi (mod_perl is a more robust when it comes to database
links, or rather, it requires less work on your part). Using DBI and DBD-Pg
you get your database access quite easily, and as it is a web server it is
trivial to knock up an interface with perl and CGI. You immediately have an
interface to the thing and all the hard work is available for free.

Adriaan