Thread: how to PG close session

how to PG close session

From
"Little, Douglas"
Date:

Hi,

 

We have a number of long running java/jdbc applications that wait for events and then extract data from PG.

During the time the apps are running,   The app is maintaining active connections to PG.

Is there a way that we can close/terminate the pg session so that the connections don’t consume resource unnecessarily.

 

Thanks

 

 

Doug Little

 

Sr. Data Warehouse Architect | Enterprise Data Management | Orbitz Worldwide

500 W. Madison, Suite 1000  Chicago IL 60661| Office 312.260.2588 | Fax 312.894.5164 | Cell 847-997-5741

Douglas.Little@orbitz.com

 cid:image001.jpg@01CABEC8.D4980670  orbitz.com | ebookers.com | hotelclub.com | cheaptickets.com | ratestogo.com | asiahotels.com

 

Attachment

Re: how to PG close session

From
"Kevin Grittner"
Date:
"Little, Douglas" <DOUGLAS.LITTLE@orbitz.com> wrote:

> We have a number of long running java/jdbc applications that wait
> for events and then extract data from PG.
> During the time the apps are running,   The app is maintaining
> active connections to PG.
> Is there a way that we can close/terminate the pg session so that
> the connections don't consume resource unnecessarily.

A relatively small number of such connections shouldn't be a
problem.  It's hard to make concrete suggestions on so little
information, but I would point out that you can write and install
your own functions which can do just about anything you want,
including making network connections.  So, hypothetically, you could
register to receive certain information on a certain event in some
"requests" table, with a URL to signal when the event occurs, and
disconnect.  Some trigger could recognize that an event has
occurred, and call a function to signal the given URL.

Just about anything is possible, it's just a Simple Matter Of
Programming....

-Kevin

Re: how to PG close session

From
"Little, Douglas"
Date:
Hey Kevin,

Thanks for the response.
Currently it's keeping 16 open connections and it isn't even running.   I believe that they(finance) can run 5
concurrentjava apps and each opens a number of sessions.   Currently all 16 sessions are owned by 1 datid.  So
potentiallyit's 80 connections,   this is on top of all our cognos (which also leaves connections open).   We're
typicallyhave 80 - 300 connections open. 

I'm really looking for the PG command to close a session.


-----Original Message-----
From: Kevin Grittner [mailto:Kevin.Grittner@wicourts.gov]
Sent: Friday, October 01, 2010 9:01 AM
To: Little, Douglas; pgsql-admin@postgresql.org
Subject: Re: [ADMIN] how to PG close session

"Little, Douglas" <DOUGLAS.LITTLE@orbitz.com> wrote:

> We have a number of long running java/jdbc applications that wait
> for events and then extract data from PG.
> During the time the apps are running,   The app is maintaining
> active connections to PG.
> Is there a way that we can close/terminate the pg session so that
> the connections don't consume resource unnecessarily.

A relatively small number of such connections shouldn't be a
problem.  It's hard to make concrete suggestions on so little
information, but I would point out that you can write and install
your own functions which can do just about anything you want,
including making network connections.  So, hypothetically, you could
register to receive certain information on a certain event in some
"requests" table, with a URL to signal when the event occurs, and
disconnect.  Some trigger could recognize that an event has
occurred, and call a function to signal the given URL.

Just about anything is possible, it's just a Simple Matter Of
Programming....

-Kevin

Re: how to PG close session

From
"Kevin Grittner"
Date:
"Little, Douglas" <DOUGLAS.LITTLE@orbitz.com> wrote:
> Kevin Grittner [mailto:Kevin.Grittner@wicourts.gov] wrote:
>> "Little, Douglas" <DOUGLAS.LITTLE@orbitz.com> wrote:
>>
>>> We have a number of long running java/jdbc applications that
>>> wait for events and then extract data from PG.
>>> During the time the apps are running,   The app is maintaining
>>> active connections to PG.
>>> Is there a way that we can close/terminate the pg session so
>>> that the connections don't consume resource unnecessarily.

>> Some trigger could recognize that an event has occurred, and call
>> a function to signal

> Currently it's keeping 16 open connections and it isn't even
> running.   I believe that they(finance) can run 5 concurrent java
> apps and each opens a number of sessions.   Currently all 16
> sessions are owned by 1 datid.  So potentially it's 80
> connections,   this is on top of all our cognos (which also leaves
> connections open).   We're typically have 80 - 300 connections
> open.

Oh, these connections aren't waiting for *database* events?  Then
you should either restructure the apps or use a connection pool.
Two popular "drop in" connection poolers are pgbouncer and pgpool.

> I'm really looking for the PG command to close a session.

http://www.postgresql.org/docs/current/interactive/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE

-Kevin

Re: how to PG close session

From
"Little, Douglas"
Date:
Thanks

The only admin function that look close is

pg_terminate_backend(pid int)    boolean    Terminate a backend

I tried it and it couldn't be found.  It is newist.  We're running PG8.2.13/GP3.3.7


>Oh, these connections aren't waiting for *database* events?  Then
>you should either restructure the apps or use a connection pool.
>Two popular "drop in" connection poolers are pgbouncer and pgpool.

We tried pgpool for awhile,   but I think I'll have a look at the code first.
I did find in the JDBC doc  connections.close  which should do the trick I suspect.

Thanks

> I'm really looking for the PG command to close a session.

http://www.postgresql.org/docs/current/interactive/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE

-Kevin

Re: how to PG close session

From
Greg Smith
Date:
Little, Douglas wrote:
> The only admin function that look close is
> pg_terminate_backend(pid int)    boolean    Terminate a backend
> I tried it and it couldn't be found.  It is newist.  We're running PG8.2.13/GP3.3.7
>

Yes, that's an 8.4 function.


> We tried pgpool for awhile,   but I think I'll have a look at the code first.
> I did find in the JDBC doc  connections.close  which should do the trick I suspect.
>

Does your Java app have an application server like Tomcat in it?  Those
can be setup to work about as well as a PostgreSQL specific pooler, and
you get tighter integration with the application itself normally in the
process.

--
Greg Smith, 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD
PostgreSQL Training, Services and Support  www.2ndQuadrant.us
Author, "PostgreSQL 9.0 High Performance"    Pre-ordering at:
https://www.packtpub.com/postgresql-9-0-high-performance/book