pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPGconn and fork
3+ messages / 2 participants
[nested] [flat]
* PGconn and fork
@ 2013-05-08 13:29 Rodrigo Barboza <rodrigombufrj@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Barboza @ 2013-05-08 13:29 UTC (permalink / raw)
To: pgsql-interfaces
Hi, guys.
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: PGconn and fork
@ 2013-05-08 14:03 Tom Lane <tgl@sss.pgh.pa.us>
parent: Rodrigo Barboza <rodrigombufrj@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2013-05-08 14:03 UTC (permalink / raw)
To: Rodrigo Barboza <rodrigombufrj@gmail.com>; +Cc: pgsql-interfaces
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
--
Sent via pgsql-interfaces mailing list (pgsql-interfaces@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: PGconn and fork
@ 2013-05-08 14:06 Rodrigo Barboza <rodrigombufrj@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Rodrigo Barboza @ 2013-05-08 14:06 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-interfaces
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!
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-05-08 14:06 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-05-08 13:29 PGconn and fork Rodrigo Barboza <rodrigombufrj@gmail.com>
2013-05-08 14:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-05-08 14:06 ` Rodrigo Barboza <rodrigombufrj@gmail.com>
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