c3p0 pool cannot establish a connection. How to debug this? - postgresql

I have a Tomcat and PostgreSQL installed on a server. I'm having a connection problem trying to connect from my servlet to PostgreSQL database using c3p0 pool.
I can reach DB if I'm running Tomcat locally on my laptop. Also I can connect from server to DB using psql (i.e. command line sql utility). But when I'm trying to deploy my servlet to server and establish a connection I'm getting the following error:
java.sql.SQLException: Connections could not be acquired from the underlying database!
com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
What should I check to locate a problem? It should be a trivial issue but may be due to 4 a.m. I'm missing something :) Thanks in advance!
PS: Connection from all network interfaces are allowed to database. PostgreSQL JDBC driver and c3p0 pool are distributed in WAR. Tomcat configuration is very default. JNDI is not used.

You need to check a few things:
java.policy which tomcat is using
(e.g.
/etc/tomcat5.5/policy.d/02debian.policy)
db server settings (e.g.
/etc/postgresql/pg_hba.conf)
try connecting without pool first as
in my case c3p0 was hiding important information from me

Adding to #Alexey's answer, I had this issue with Tomcat and PostgreSQL 9.4. In my case, the md5 authentication method in postgres was causing the issue.
If you are using Windows server or RHEL server, make sure you update the authentication method in pg_hba.conf file. Modify it to trust and restart postgresql.

Related

Failed PostgreSQL database connection in Pentaho Data Integration PDI

Objective: Set up a connection with PostgreSQL db in PDI. I'm a noob in all this stuff, so each step forward requires long resolution time.
I'm trying to set up the connection to a PostgreSQL database in order to prepare some queries for an ETL process in PDI. But there's no way to succeed with the connection.
I've tried with PostgreSQL connection type and with Generic database connection type and the error is always related with the drivers.
The version of the PostgreSQL db I'm trying to connect is 9.5.25 and I'm working in Ubuntu 20.04 and Java 8 as demands Pentaho Data Integration.
Below the error message after failed connection:
"Connection failed. Verify all connection parameters and confirm that the appropriate driver is installed. Connection to [IP]:[Port] refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."
I am literally in despair, don't know what I'm doing wrong. Will be very grateful with anyone who can help me.
You need to add the jdbc driver to connect to postgresql DB in the pdi-installation/lib directory, you just put the *.jar file there and restart spoon to have the library available.
That driver can be downloaded from postgresql downloads. The Community Edition of PDI only comes with a small number of jdbc drivers, for each type of database you need to connect to, you should check if the jdbc driver is available in that directory, and if it's up to date or if you need a more recent version of the driver.
This is a link for the official Pentaho documentation, looking for information in Hitachi Vantara documentation is becoming more and more difficult, they don't always clarify what steps apply only for the Enterprise Edition and are not available for the Community Edition: https://help.hitachivantara.com/Documentation/Pentaho/9.2/Setup/JDBC_Drivers_Reference

Troubleshoot org.postgresql.util.PSQLException: Connection attempt timed out that only occasionally happens

I have several applications running on tomcat with a local PostgresSQL database. And tomcat occasionally reports the following errors:
org.postgresql.util.PSQLException: Connection attempt timed out.
I am able to connect to the database using other tools such as DBeaver. And this problem looks only happens when several applications are connecting to the database. So I want to know how to troubleshoot this issue. Is there any log in PostgresSQL that I can check?
PostgreSQL does have logging. It is very configurable, and we can't tell you how you have it configured. Common locations are /var/log/postgresql/, and in PGDATA/log/. However, a connection timeout will probably not be in the postgresql log as it probably never achieved contact with the postgresql server to start with.

After restarting DB2 service, the application server gets ERRORCODE=-4499, SQLSTATE=58009 in database connections

We have an application on IBM WebSphere Application Server 7.x and it connects to a remote database on z/os DB2 10.x. For annual operation, DB2 shut down and restarted. After starting the database, we first get
com.ibm.websphere.ce.cm.StaleConnectionException
and then we get
The database manager is not able to accept new requests, has terminated all requests in progress, or has terminated this particular request due to unexpected error conditions detected at the target system. ERRORCODE=-4499, SQLSTATE=58009
The connection between WebSphere and DB2 tested by 'test Connection' in WAS datasource. Both systems are up and running but there is no correct connection between them! There was no change in DB2, WAS, and JDBC driver.
Update: The JDBC driver version is 4.15.134, connection properties is IBM WebSphere default setting and the connection is direct to DB2. Another problem later showed that while the connection still has the problem, executing the query directly on z/OS's DB2 gets the same the error. The query consist of a select with a join on two different tables, selecting on each table is ok, but the final query does not work and gets ERRORCODE=-4499, SQLSTATE=58009.
Update 2
The detail of environment is: IBM WebSphere Application Server 7.0.0.45, DB2 10.1, Java version 1.6 SR16 and z/OS 1.13.
This specific query gets the error in all environments, on all application server, z/os SPUFI, database viewer, such as DBeaver.
Any help is greatly appreciated.
Finally, we found the solution, ran REORG and RUNSTATS on both tables and on all their partitions, and the error vanished both on the application and SPUFI. I guess something went wrong during restart and tables corrupted. Now everything is ok.
If I got you correctly, you complain on inability of the driver to reestablish the database connections after the DB2 for Z/OS restart.
If yes, then have you tried to set the corresponding connection properties described at the following link?
Configuration of Sysplex workload balancing and automatic client reroute for Java clients

Protocol issue connecting Derby by db2 ODBC

This is a problem when I tried to connect Derby Database by DB2 ODBC
I started the Derby Network Server and created a database named "mydb"
but,after I did as the steps described in an article on IBM's site,I countered a problem on the server side.
Step 1->db2 catalog tcpip node MYDERBY remote localhost server 1527
Step 2->db2 catalog db mydb at node MYDERBY authentication server
Step 3->db2 connect to mydb user abc using abc
Problem:
Execution failed because of a Distributed Protocol error:DRDA_Proto_SYNTAXRM;
CODPNT arg=112e;error code value=14;Plaintext connection attempt from an SSL enabled client?
What can I do to accomplish or it is unworkable??
db2_v10.12_winx64_expc
db-derby-10.11.1.1-bin
Current versions of the Derby Network Server do not communicate with the DB2 ODBC client, as far as I know. You might look here: http://apache-database.10148.n7.nabble.com/ODBC-Driver-for-Derby-td102587.html or here: http://www.easysoft.com/products/data_access/odbc-derby-driver/index.html#section=tab-1 or here: Derby Database ODBC Connection for some more ideas.
Note: I gave a relatively similar answer to a relatively similar question here: Derby Database ODBC Connection and it was deleted, so for all I know this answer may be deleted as well.

Migrate from JavaDB to PostgreSQL and cant access database any longer

I have an application on Glassfish v2 ( on Mac OS 10.5.8 and Java 1.6 ) that uses JavaDB and Toplinks that comes with the Glassfish bundle. Everything works fine.
I have installed PostgreSQL 8.4 and the JDBC v4 driver. Both Glassfish and Postgres server run on localhost. From Netbeans, I create a connection to a database on the Postgres server, and it works fine, I can manually create and delete tables.
I create a connection pool, resource and persistence unit for this connection to the Posgres server. When I deploy I have the following error :
ADM1041:Sent the event to instance:
[ResourceDeployEvent -- reference-added jdbc/jdbc/MyDatasource]
CORE5004: Resource Deployed: [jdbc:jdbc/MyDatasource].
TopLink, version: Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))
Server: unknown
RAR5038:Unexpected exception while creating resource for pool MyConnectionPool.
Exception : Connection could not be allocated because:
FATAL: database "null" does not exist
I read that with Postgres 8.4, localhost request are accepted by default, so I haven't changed anything in postgres.conf.
I am missing something, but I cant see what.
Thanks in advance for any hint.
Tart
First ensure that MacOSX/GlassFish really uses the specified Java version (test with: java -version). Then try the following:
asadmin create-jdbc-connection-pool
--datasourceclassname org.postgresql.ds.PGSimpleDataSource
--restype javax.sql.DataSource --property portNumber=5432:password=secret:user=postgres:serverName=localhost:databaseName=postgres
test-pool
and
asadmin create-jdbc-resource --connectionpoolid test-pool jdbc/Postgres
remember to change the username, password, server, port and database to reflect your setup. Then test the datasource using:
asadmin ping-connection-pool test-pool
if this does not work then you have miss-configured your data source.
I don't know the stack, but it sounds like you haven't specified the database name in the connection. See http://jdbc.postgresql.org/documentation/84/connect.html for a list of parameters you can/should set on the connection.