Solved

PostGresql - non superuser connection limit exceeded

Posted on 2003-12-01
3
2,341 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle report printing 2 pages in one page 2 70
Cassandra Select Query 1 77
Has anyone used domo? 1 57
dbcc checkdb datawarehouse 2 56
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…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

803 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