Play 2.0 PostgreSQL Cannot connect to database [default] only on wireless

My Play 2.0 database is set up to use a PostgreSQL connection and it works fine on my wired internet connection. However, when I try to connect from a wireless internet connection i receive the Cannot connect to database [default] error. Can anyone please help me figure out why this is?

Settings:

db.default.driver=org.postgresql.Driver
db.default.url=${DATABASE_URL}
db.default.partitionCount=1

Database URL variable set up in .bashrc file:

postgres://myusername:test123@localhost:5432/projectname

EDITED:

pg_hba.conf file:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     tvonehwegen                                md5
#host    replication     tvonehwegen        127.0.0.1/32            md5
#host    replication     tvonehwegen        ::1/128                 md5

postgresql.conf file:

# - Connection Settings -

#listen_addresses = 'localhost'     # what IP address(es) to listen on;
                # comma-separated list of addresses;
                # defaults to 'localhost'; use '*' for all
                # (change requires restart)
#port = 5432                # (change requires restart)
max_connections = 100           # (change requires restart)

Turns out the only problem here is that I can not connect to my local postgreSQL database when I am connected to a wireless network. Does anyone know why that may be? Thanks!

Answers


Check your WiFi/Internet settings for IPv6. On some networks your machine gets an IPv6 address in addition to the traditional IPv4 one. In such cases, usually, localhost gets mapped to ::1 instead of 127.0.0.1; which means things will go wrong if you have setup pg_hba.conf to grant access based on IPv4 addresses.

Assuming firewall is off, e.g. on Redhat based systems service iptables stop, and the following snippets exists in relevant files:

pg_hba.conf:

host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

postgresql.conf:

listen_addresses = '*'

You should be able to connect to the desired database as follows:

$ psql -h ::1 -U USERNAME -d DATABASE
Password for user USERNAME: 
psql (9.1.11)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

DATABASE=> 

And

$ psql -h 127.0.0.1 -U USERNAME -d DATABASE
Password for user USERNAME: 
psql (9.1.11)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

DATABASE=> 

Finally Play's JDBC connection settings should be of the following form:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://127.0.0.1:5432/DATABASE"
db.default.user=USERNAME
db.default.password=PASSWORD

NOTE: I'd strongly suggest you never use localhost in a connection string. 99.99% of the time what you need is 127.0.0.1.


Need Your Help

You tube videos are not playing

android youtube-api

I am using OpenYoutubeActivity.jar to play youtube videos like this

Flask 405 Method Error

python html sqlite flask

Hi i'm trying to add a contact to my sqlite db although I keep getting a 405 method error. Any ideas??