我正在开发一个Android应用程序,并且我正在使用与PostGIS捆绑在一起的PostgreSQL。我想使用本地数据库,但通过'本地主机'连接不起作用,我试过替代使用'127.0.0.1',而不是它的工作,我得到以下错误:无法连接到PostgreSQL数据库作为'localhost'
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
使用我的网络的ipv4地址工程,但我无法通过本地主机连接。我该如何解决这个问题? 我pg_hba.conf的样子:
...
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.1.1/24 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust
和我的postgresql.conf样子:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5123 # (change requires restart)
max_connections = 100 # (change requires restart)
我在Eclipse代码看起来我的服务器类中像
private String DB_URL = "jdbc:postgresql://" + Server.getDbserver() + ":" + Server.getDbport() + "/postgis";
我的变量看起来像。
private static String dbserver = "localhost";
private static int dbport = 5123;
作为总结,通过我的网络的IPv4(例如192.168.1.199)的作品连接,而是通过“本地主机”或“127.0.0.1”生成我,我上面贴的错误连接。
那么,PostgreSQL实际上在Android OS *内运行*? – 2014-12-02 09:57:38
我不知道我明白你想说什么。 – MrSilent 2014-12-02 10:19:02
这是http://dba.stackexchange.com/questions/83851的转贴。在Android上安装postgresql **服务器**是个不小的功夫,请参阅[将Postgresql服务器移植到Android](https://groups.google.com/forum/#!topic/pgandroid/STg8xObGFlo)并且它不能在不知道你在做什么的情况下完成。 – 2014-12-02 10:22:09