Solved

PostGresql - non superuser connection limit exceeded

Posted on 2003-12-01
3
2,319 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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
stoneman earned 75 total points
Comment Utility
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
Comment Utility
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
Comment Utility
It ended up being a problem on the host's side. Thanks for answering.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now