idle connections

Lists: pgsql-admin
From: Aras Angelo <araskoktas(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: idle connections
Date: 2009-10-05 22:42:50
Message-ID: 5136d4130910051542o38425d0eu1dc1233c530f3a99@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hi,

Im seeing lots of idle connections (not idle in transaction) to my database
server. My front end is written with PHP and i couldnt find anything that
can cause this. If i do a kill proc-id every few minutes on my server via
cron, would this effect anything badly?

Thanks


From: u235sentinel <u235sentinel(at)gmail(dot)com>
To:
Cc: pgsql-admin(at)postgresql(dot)org
Subject: compiling postgres with static libraries?
Date: 2009-10-05 22:58:15
Message-ID: 4ACA7A07.6010301@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Is there a way to compile postgres with static libraries instead of dynamic?

I know it will make the binaries bigger but I have a need to do this.

I've been reading through the make/automake, cc, gcc and ld man pages
AND googling a bit. Not getting it to run properly. When I run the
./configure it says cc cannot create a test object when I try -d n, -B
static or -static.

What am I missing?

I'm thinking this is something I need to do with ld and use LDFLAGS but
that's just a guess.

Thanks!


From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-05 23:12:48
Message-ID: 4ACA7D70.5050405@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Aras Angelo wrote:
> Hi,
>
> Im seeing lots of idle connections (not idle in transaction) to my
> database server. My front end is written with PHP and i couldnt find
> anything that can cause this. If i do a kill proc-id every few minutes
> on my server via cron, would this effect anything badly?
>
> Thanks
Before you go killing things willy-nilly, try diagnosing the problem -
papering over problems is almost never a good "solution". In fact,
depending on your designs and workloads, this might be a good thing (if
intentional and understood).

Use (as root) "lsof -i :5432" or your favorite equivalent for your OS.

First run it on the database server to verify that the connections are
from your webserver. If so, run it on your webserver and verify that the
processes are what you think they are.

If PHP (which will probably show up as an Apache or whatever webserver
you are running process), you may have one or more scripts opening
persistent connections. Or a bug. I've seen PHP scripts hang leaving an
open connection to the database. Or it could be a persistent connection
opened by a Perl/Python/Ruby/whatever-else-you-have program so you may
have to check those as well. Perhaps look at the connection start time
in PG and try to correlate it with a request in your webserver log.

I assume you would have told us if you are running pgbouncer or similar
pooling solution as that would be an obvious cause.

Cheers,
Steve


From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-05 23:48:04
Message-ID: dcc563d10910051648r34fe72e2uaf3f8fa364d7462f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Mon, Oct 5, 2009 at 4:42 PM, Aras Angelo <araskoktas(at)gmail(dot)com> wrote:
> Hi,
>
> Im seeing lots of idle connections (not idle in transaction) to my database
> server. My front end is written with PHP and i couldnt find anything that
> can cause this. If i do a kill proc-id every few minutes on my server via
> cron, would this effect anything badly?

Are you using pg_pconnect?

pg_pconnect is a foot gun waiting to happen. It's an otherwise very
useful foot gun, but a foot gun none-the-less.

The problem is that by default apache is usually set up to have more
max connections / children / threads etc. than postgresql is to have
backends available. This just gets worse if you run < 1 apache server
machine.

The simple solution is to turn off pg_pconnect.

If things are then too slow then you can start planning for
connection pooling / pg_pconnect otherwise don't sweat it. For low
level intranet servers, regular pg_connect will work just fine.


From: Aras Angelo <araskoktas(at)gmail(dot)com>
To: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-05 23:50:55
Message-ID: 5136d4130910051650y775c6bb4odbdd759e3952eb32@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Its a regular pg_connect()

When i kill the earliest idle process the others stop too. So i dont know
whats wrong really. All our apps use the same footer, with pg_close() at the
end.

I have done most of the things you guys suggested, so it seems to me that
something between php-apache-postgresql is not doing good, and it only
effects us at peak times, so just wondering if killing processes every 2-3
minutes, would do harm on our setup.

I have 3 apache servers reading from one single db server.

On Mon, Oct 5, 2009 at 4:48 PM, Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>wrote:

> On Mon, Oct 5, 2009 at 4:42 PM, Aras Angelo <araskoktas(at)gmail(dot)com> wrote:
> > Hi,
> >
> > Im seeing lots of idle connections (not idle in transaction) to my
> database
> > server. My front end is written with PHP and i couldnt find anything that
> > can cause this. If i do a kill proc-id every few minutes on my server via
> > cron, would this effect anything badly?
>
> Are you using pg_pconnect?
>
> pg_pconnect is a foot gun waiting to happen. It's an otherwise very
> useful foot gun, but a foot gun none-the-less.
>
> The problem is that by default apache is usually set up to have more
> max connections / children / threads etc. than postgresql is to have
> backends available. This just gets worse if you run < 1 apache server
> machine.
>
> The simple solution is to turn off pg_pconnect.
>
> If things are then too slow then you can start planning for
> connection pooling / pg_pconnect otherwise don't sweat it. For low
> level intranet servers, regular pg_connect will work just fine.
>


From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-06 00:50:02
Message-ID: dcc563d10910051750i22f433a5k9b9c85b7fdc58ae1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Mon, Oct 5, 2009 at 5:50 PM, Aras Angelo <araskoktas(at)gmail(dot)com> wrote:
> Its a regular pg_connect()
>
> When i kill the earliest idle process the others stop too. So i dont know
> whats wrong really. All our apps use the same footer, with pg_close() at the
> end.
>
> I have done most of the things you guys suggested, so it seems to me that
> something between php-apache-postgresql is not doing good, and it only
> effects us at peak times, so just wondering if killing processes every 2-3
> minutes, would do harm on our setup.
>
> I have 3 apache servers reading from one single db server.

php automagically cleans up old connections etc upon script exit, so
either your scripts aren't exiting, or they're crashing before they
can exit I'd guess. Or you've got a REALLY busy apache server that
has that many connections open at once.

Anything in your apache or php logs that offers a clue?


From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-06 00:51:22
Message-ID: dcc563d10910051751l3603440xd040b73f3b89f88a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Mon, Oct 5, 2009 at 5:50 PM, Aras Angelo <araskoktas(at)gmail(dot)com> wrote:
> Its a regular pg_connect()
>
> When i kill the earliest idle process the others stop too. So i dont know
> whats wrong really. All our apps use the same footer, with pg_close() at the
> end.
>
> I have done most of the things you guys suggested, so it seems to me that
> something between php-apache-postgresql is not doing good, and it only
> effects us at peak times, so just wondering if killing processes every 2-3
> minutes, would do harm on our setup.
>
> I have 3 apache servers reading from one single db server.

So what's your max apache children / threads and what's your max pgsql
connections allowed? You may need to crank up pgsql connection limit
to keep up.


From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-06 16:28:31
Message-ID: 4ACB702F.2040505@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Aras Angelo wrote:
> ...
> When i kill the earliest idle process the others stop too. So i dont
> know whats wrong really. All our apps use the same footer, with
> pg_close() at the end....
> ...
> I have done most of the things you guys suggested, so it seems to me
> that something between php-apache-postgresql is not doing good, and it
> only effects us at peak times, so just wondering if killing processes
> every 2-3 minutes, would do harm on our setup....

Are you killing web processes or postgresql processes? If web, you will
probably end up impacting at least some of you users directly. If
PostgreSQL, then you will undoubtedly end up yanking the rug out from
under a process that expected a working database connection. So yes,
you might cause harm. Worse still, you may not solve the problem.

When I hear symptoms like this, especially when they tend to happen
under load, I start looking for a process that is slowing/blocking the
other processes.

Consider a fairly typical PHP script. It might start out opening a
database connection and then do various queries interspersed with
processing. If one process hogs sufficient resources or is holding some
resource or lock that slows or blocks the other PHP processes then you
could easily see numerous idle PG processes. Kill the "offending"
process and the others will often rapidly complete thus releasing their
connections.

If you have enough traffic to justify three webservers then you probably
have enough traffic to deplete your available pg connections in seconds,
not minutes so keep digging.

Cheers,
Steve


From: Aras Angelo <araskoktas(at)gmail(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-06 16:42:58
Message-ID: 5136d4130910060942w212c2ed0oc2ab19af4b57d683@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Thank you for the informative post.

We believe this was caused by a network issue yesterday after checking our
network speeds. We were maxing our ethernet port at 100 mbps, i believe some
apache processes were hanging because of this issue, having no available
bandwidth left. Considering an upgrade to a gbps port and we will see how
this will effect.

On Tue, Oct 6, 2009 at 9:28 AM, Steve Crawford <
scrawford(at)pinpointresearch(dot)com> wrote:

> Aras Angelo wrote:
>
>> ...
>> When i kill the earliest idle process the others stop too. So i dont know
>> whats wrong really. All our apps use the same footer, with pg_close() at the
>> end....
>> ...
>> I have done most of the things you guys suggested, so it seems to me that
>> something between php-apache-postgresql is not doing good, and it only
>> effects us at peak times, so just wondering if killing processes every 2-3
>> minutes, would do harm on our setup....
>>
>
> Are you killing web processes or postgresql processes? If web, you will
> probably end up impacting at least some of you users directly. If
> PostgreSQL, then you will undoubtedly end up yanking the rug out from under
> a process that expected a working database connection. So yes, you might
> cause harm. Worse still, you may not solve the problem.
>
> When I hear symptoms like this, especially when they tend to happen under
> load, I start looking for a process that is slowing/blocking the other
> processes.
>
> Consider a fairly typical PHP script. It might start out opening a database
> connection and then do various queries interspersed with processing. If one
> process hogs sufficient resources or is holding some resource or lock that
> slows or blocks the other PHP processes then you could easily see numerous
> idle PG processes. Kill the "offending" process and the others will often
> rapidly complete thus releasing their connections.
>
> If you have enough traffic to justify three webservers then you probably
> have enough traffic to deplete your available pg connections in seconds, not
> minutes so keep digging.
>
> Cheers,
> Steve
>
>


From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: idle connections
Date: 2009-10-06 17:22:06
Message-ID: 4ACB7CBE.5090304@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Aras Angelo wrote:
> Thank you for the informative post.
>
> We believe this was caused by a network issue yesterday after checking
> our network speeds. We were maxing our ethernet port at 100 mbps....
Ah, yes. In a previous life we once had a very successful internal
load-test turn into a rapid and complete meltdown in real life because
all the modem users kept processes occupied for long periods while the
data dribbled back and the server maxed out on available threads/processes.

Cheers,
Steve


From: u235sentinel <u235sentinel(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: postgres 8.3.8 and Solaris 10 problems?
Date: 2009-10-06 18:16:29
Message-ID: 4ACB897D.8090500@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

So I compiled postgres with Solaris 10 and have problems running it.

# ./pg_ctl
ld.so.1: pg_ctl: fatal: relocation error: R_AMD64_32: file
/usr/local/postgres64/lib/libpq.so.5: symbol (unknown): value
0xfffffd7fff1cf210 does not fit
Killed

# ldd pg_ctl
libpq.so.5 => /usr/local/postgres64/lib/libpq.so.5
libm.so.2 => /usr/lib/64/libm.so.2
libxml2.so.2 => /usr/lib/64/libxml2.so.2
libz.so.1 => /usr/lib/64/libz.so.1
libreadline.so.6 => /usr/local/lib/libreadline.so.6
libcurses.so.1 => /usr/lib/64/libcurses.so.1
librt.so.1 => /usr/lib/64/librt.so.1
libsocket.so.1 => /usr/lib/64/libsocket.so.1
libc.so.1 => /usr/lib/64/libc.so.1
libpthread.so.1 => /usr/lib/64/libpthread.so.1
libnsl.so.1 => /lib/64/libnsl.so.1
libgcc_s.so.1 => /usr/sfw/lib/amd64/libgcc_s.so.1
libaio.so.1 => /lib/64/libaio.so.1
libmd.so.1 => /lib/64/libmd.so.1
libmp.so.2 => /lib/64/libmp.so.2
libscf.so.1 => /lib/64/libscf.so.1
libdoor.so.1 => /lib/64/libdoor.so.1
libuutil.so.1 => /lib/64/libuutil.so.1
libgen.so.1 => /lib/64/libgen.so.1

# file /usr/local/postgres64/lib/libpq.so.5
/usr/local/postgres64/lib/libpq.so.5: ELF 64-bit LSB dynamic lib AMD64
Version 1 [SSE CMOV], dynamically linked, not stripped


What am I missing???

Here's my environment.

Solaris 10 x86_64 with postgres 8.3.8 and openssl 98k using gcc version
3.4.3 (csl-sol210-3_4-branch+sol_rpath)
, sunstudio12.1 and GNU Make 3.80

Thanks!


From: raghu ram <raghuchennuru(at)gmail(dot)com>
To: u235sentinel(at)gmail(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: postgres 8.3.8 and Solaris 10 problems?
Date: 2009-10-08 20:32:19
Message-ID: d331f2ee0910081332y4b80c8d5m91b32c8737384911@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Tue, Oct 6, 2009 at 11:46 PM, u235sentinel <u235sentinel(at)gmail(dot)com>wrote:

> So I compiled postgres with Solaris 10 and have problems running it.
>
> # ./pg_ctl
> ld.so.1: pg_ctl: fatal: relocation error: R_AMD64_32: file
> /usr/local/postgres64/lib/libpq.so.5: symbol (unknown): value
> 0xfffffd7fff1cf210 does not fit
> Killed
>
> # ldd pg_ctl
> libpq.so.5 => /usr/local/postgres64/lib/libpq.so.5
> libm.so.2 => /usr/lib/64/libm.so.2
> libxml2.so.2 => /usr/lib/64/libxml2.so.2
> libz.so.1 => /usr/lib/64/libz.so.1
> libreadline.so.6 => /usr/local/lib/libreadline.so.6
> libcurses.so.1 => /usr/lib/64/libcurses.so.1
> librt.so.1 => /usr/lib/64/librt.so.1
> libsocket.so.1 => /usr/lib/64/libsocket.so.1
> libc.so.1 => /usr/lib/64/libc.so.1
> libpthread.so.1 => /usr/lib/64/libpthread.so.1
> libnsl.so.1 => /lib/64/libnsl.so.1
> libgcc_s.so.1 => /usr/sfw/lib/amd64/libgcc_s.so.1
> libaio.so.1 => /lib/64/libaio.so.1
> libmd.so.1 => /lib/64/libmd.so.1
> libmp.so.2 => /lib/64/libmp.so.2
> libscf.so.1 => /lib/64/libscf.so.1
> libdoor.so.1 => /lib/64/libdoor.so.1
> libuutil.so.1 => /lib/64/libuutil.so.1
> libgen.so.1 => /lib/64/libgen.so.1
>
> # file /usr/local/postgres64/lib/libpq.so.5
> /usr/local/postgres64/lib/libpq.so.5: ELF 64-bit LSB dynamic lib AMD64
> Version 1 [SSE CMOV], dynamically linked, not stripped
>
>
> What am I missing???
>
> Here's my environment.
>
> Solaris 10 x86_64 with postgres 8.3.8 and openssl 98k using gcc version
> 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
> , sunstudio12.1 and GNU Make 3.80
>
> Thanks!
>
>

could you please try to start the Postgres service using below steps

cd <installed postgres directory>/bin

./pg_ctl -D < data directory path> start

Thanks & Regards
Raghu


From: u235sentinel <u235sentinel(at)gmail(dot)com>
To: raghu ram <raghuchennuru(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: postgres 8.3.8 and Solaris 10 problems?
Date: 2009-10-09 01:57:48
Message-ID: 4ACE989C.300@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

raghu ram wrote:
>
>
>
>
> could you please try to start the Postgres service using below steps
>
> cd <installed postgres directory>/bin
>
> ./pg_ctl -D < data directory path> start
>
>
> Thanks & Regards
> Raghu

I've tried to initially start it and am getting the same results with
the above command :/