java - Cannot connect to PostgreSQL database as 'localhost' -
i developing android application , i'm using postgresql bundled postgis. want use local database connecting via 'localhost' doesn't work, have tried alternative use '127.0.0.1' instead not working, getting following error:
org.postgresql.util.psqlexception: connection refused. check hostname , port correct , postmaster accepting tcp/ip connections.
using network's ipv4 adress works, cannot connect via localhost. how can fix that? pg_hba.conf looks like:
... # put actual configuration here # ---------------------------------- # # if want allow non-local connections, need add more # "host" records. in case need make postgresql # listen on non-local interface via listen_addresses # configuration parameter, or via -i or -h command line switches. # type database user address method # ipv4 local connections: host 127.0.0.1/32 trust host 192.168.1.1/24 trust host 0.0.0.0/0 trust # ipv6 local connections: host ::1/128 trust # allow replication connections localhost, user # replication privilege. #host replication postgres 127.0.0.1/32 trust #host replication postgres ::1/128 trust
and postgresql.conf looks like:
# - connection settings - listen_addresses = '*' # ip address(es) listen on; # comma-separated list of addresses; # defaults 'localhost'; use '*' # (change requires restart) port = 5123 # (change requires restart) max_connections = 100 # (change requires restart)
my code in eclipse looks
private string db_url = "jdbc:postgresql://" + server.getdbserver() + ":" + server.getdbport() + "/postgis";
and variables inside server class like.
private static string dbserver = "localhost"; private static int dbport = 5123;
as summary, connecting via network ipv4 (for example 192.168.1.199) works, connecting via 'localhost' or '127.0.0.1' generates me error posted above.
why using 192.168.1.1/24 , trust? try maybe this:
host all 192.168.1.1/32 md5
and implement connection username / password.
Comments
Post a Comment