The default installation of Postgresql does not allow TCP/IP connections, which also means JDBC connections wont’ work.
Enable TCP/IP Connections
Let’s make a backup of the original config file.
sudo cp postgresql.conf postgresql.conf.org
sudo vi postgresql.conf
Find the line that contains
#listen_addresses = 'localhost'
and change it to:
listen_addresses = 'localhost'
If you want to allow remote connections, then you need to set listen_address to something like (assuming your machine’s IP Address is 192.168.1.2):
listen_addresses = ‘127.0.0.1 192.168.1.2’
You will also need to update the firewall to allow connections to this machine.
Restart the Postgresql Server
sudo service postgresql restart
Test the TCP/IP Connection
psql -h 127.0.0.1 -p 5433 -U postgres -W