Solved

PostGresql - non superuser connection limit exceeded

Posted on 2003-12-01
3
2,362 Views
Last Modified: 2012-06-27
I am running a JSP application on Tomcat that refreshes every minute. When it refreshes, it opens a connection to the DB, executes a few queries/updates, and then closes all the connections. I have similar pages in my app that do similar things.

One page though consistently blows up after about 20 minutes. It gives me a Fatal exception that says the "non superuser connection limit is exceeded". I have tried to figure out what is going wrong, especially since I know that I am closing the connections each time, and I know it is specific to PostGresql because the same pages run fine with an MS SQL db in the backend.

Does anybody have any ideas? I have checked the Postgresql site and there was nothing really helpful there that I could find.
0
Comment
Question by:Arawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
stoneman earned 75 total points
ID: 9852475
The number of superuser connections is set in the postgresql.conf file with the following line:

#superuser_reserved_connections = 2

It sounds like you are using the superuser account (usually postgres or pgsql) to login in from php. This is bad. It's like launching your webserver under root or something - potential security risk. Usually you create a user account and let the webapp use that to login.

The reason for the running out of connections could be something simple like you have a couple of pgsql shells open, that would prevent the webapp from getting a valid connection.

There is also another param in that file:

max_connections = 200

I think this is the default value. The max_connections comes into play whenever you use the user accounts to login.

Finally, why does the one page blow up and not the others? I'd like to see the jsp to make sure exactly what you are doing. If you are indeed closing the connection then that should prevent this. But perhaps there is something else. Please post snippets if you can.

Hope this helps,

Gregory

0
 
LVL 4

Author Comment

by:Arawn
ID: 9852583
stoneman

I don't think I am using the superuser account, because this is actually a hosted database. And I can't see any hosting company giving away the superuser password.

The pertinent info from the page is below. I have truncated a whole bunch of things that aren't important. The main thing is that it is clear that the page is refreshing, and that the connection is being closed.

<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setIntHeader("Refresh", 60 );

String sql="select aucID from auctionAuctions where aucEnded=0 and aucCloseDate<'"+currSQLDate+"' and aucNumBid>0";
java.util.ArrayList openAuctions=new java.util.ArrayList();
Class.forName(jdbc_driver);  
Connection con =       DriverManager.getConnection(jdbc_databaseURL,jdbc_username,jdbc_password);  
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){      
      openAuctions.add(""+rs.getInt("aucID"));
}
for(int x=0; x<openAuctions.size(); x++){
      sql="select auctionItems.itemTitle, auctionAuctions.aucCurrentBid, auctionUsers.userEmail from auctionItems, auctionAuctions, auctionUsers  where aucID="+openAuctions.get(x)+" and auctionUsers.UserID=auctionAuctions.aucCurrentBidder and auctionAuctions.aucItemID=auctionItems.itemID";
      rs= stmt.executeQuery(sql);
      if(rs.next()){      
                      // do stuff
      rs.close();      
      }      
}
sql="update auctionAuctions set aucEnded=1 where aucCloseDate<'"+currSQLDate+"' and aucNumBid=0";
stmt.executeUpdate(sql);
stmt.close();
con.close();
%>
0
 
LVL 4

Author Comment

by:Arawn
ID: 9949384
It ended up being a problem on the host's side. Thanks for answering.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question