The apparent deadlock message issued by c3p0, a connection pool manager of Hibernate, can sometimes be misleading.
Most of the times, it is caused by connection errors.
So, check your firewall, and, for Postgresql try the following command from the command line
psql -h host -U user db
If this works, you should have no problem connecting to Postgresql.
The apparent deadlock error
In my case I had the following error shown in the console under Windows, Java 8, when starting Tomcat under Eclipse Oxygen
2017/11/27 18:21:03 WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@15cc07ce -- <strong>APPARENT DEADLOCK!!!</strong> Creating emergency threads for unassigned pending tasks!
and I was getting the following exception
2017/11/27 18:21:14 WARN com.mchange.v2.resourcepool.BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1e723184 -- <strong>Acquisition Attempt Failed!!!</strong> Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
org.postgresql.util.PSQLException: FATAL: <strong>the remaining connection slots are reserved to non replica superusers connections</strong>
In the postgres log I was seeing many authorized connections opened by c3p0.
I also used Wireshark and RawCap to capture the connections to the db and it seemed they were acquired, as the log said, but after seeing Postgres saying “ready for queries”, they were closed. I used this tutorial to understand how to use Wireshark with RawCap under Windows 10.
After some investigation I discovered I was using the wrong JDBC postgresql driver!
After changing to PostgreSQL JDBC 4.2 Driver, 42.1.4 which is listed as a driver for Java 8, all went fine.