Обсуждение: PGconn and fork

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

PGconn and fork

От
Rodrigo Barboza
Дата:
<div dir="ltr">Hi, guys.<div style="style">I have a program in C, the createas a connection, do stuff, fork, exit child
andcontinues life.</div><div style="style">Supose that when I create de PGconn, I have 1 active connection in
postgres.</div><divstyle="style">When I fork, does it count as a second connection? I mean, will postrges interpretate
2active connections or they only share the same connection?</div><div style="style">I know that if the child process
executesome query, I can get unexpected results, but it doesn't, so I am safe about that.</div><div style="style">I'm
onlyworried that this can increase the number of connections and reach the limit of max_connections.</div></div> 

Re: PGconn and fork

От
Tom Lane
Дата:
Rodrigo Barboza <rodrigombufrj@gmail.com> writes:
> I have a program in C, the createas a connection, do stuff, fork, exit
> child and continues life.
> Supose that when I create de PGconn, I have 1 active connection in postgres.
> When I fork, does it count as a second connection? I mean, will postrges
> interpretate 2 active connections or they only share the same connection?
> I know that if the child process execute some query, I can get unexpected
> results, but it doesn't, so I am safe about that.
> I'm only worried that this can increase the number of connections and reach
> the limit of max_connections.

No, the child process will just have another reference to the open
socket that connects to the server.  The reason why it's dangerous
to send queries from such a process is exactly that, to the server,
it looks like the same connection as the parent process.
        regards, tom lane



Re: PGconn and fork

От
Rodrigo Barboza
Дата:



On Wed, May 8, 2013 at 11:03 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Rodrigo Barboza <rodrigombufrj@gmail.com> writes:
> I have a program in C, the createas a connection, do stuff, fork, exit
> child and continues life.
> Supose that when I create de PGconn, I have 1 active connection in postgres.
> When I fork, does it count as a second connection? I mean, will postrges
> interpretate 2 active connections or they only share the same connection?
> I know that if the child process execute some query, I can get unexpected
> results, but it doesn't, so I am safe about that.
> I'm only worried that this can increase the number of connections and reach
> the limit of max_connections.

No, the child process will just have another reference to the open
socket that connects to the server.  The reason why it's dangerous
to send queries from such a process is exactly that, to the server,
it looks like the same connection as the parent process.

                        regards, tom lane

Perfect.
Thanks, Tom!