Postgres 数据源定义 - 连接被拒绝
Postgres Datasource Definition - connection refused
我正在尝试设置一个用于集成测试的快速数据源,因此与其在应用程序服务器上配置它 - Wildfly 10 - 我更愿意动态部署它。
我是这样配置的:
@DataSourceDefinitions({
@DataSourceDefinition(
name = "java:/datasources/testdb",
className = "org.postgresql.xa.PGXADataSource",
user = "testdb",
password = "testdb",
serverName = "localhost",
portNumber = 5432,
databaseName = "testdb",
minPoolSize = 10,
maxPoolSize = 50)
})
public class DatasourceDefinitions {}
我尝试使用 localhost
、127.0.0.1
并使用参数 url
而不是三元组 serverName
、port
和 databaseName
,但我总是运行变成Connection Refused
错误
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
... 41 more
我已经检查了 user
和 password
,如果我尝试使用 pgAdmin
登录,它们工作正常。
这是 Postgres 配置:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
我也启用了线路
listen_addresses = 'localhost' # what IP address(es) to listen on;
在配置文件中postgresql.conf
谁能告诉我我错过了什么and/or做错了什么?
已解决。
问题出在 Postgres
配置中,即文件 /etc/postgresql/9.4/main/postgresql.conf
.
我改了这个
listen_addresses = 'localhost'
进入这个
listen_addresses = '127.0.0.1'
现在它完美运行了。
我正在尝试设置一个用于集成测试的快速数据源,因此与其在应用程序服务器上配置它 - Wildfly 10 - 我更愿意动态部署它。
我是这样配置的:
@DataSourceDefinitions({
@DataSourceDefinition(
name = "java:/datasources/testdb",
className = "org.postgresql.xa.PGXADataSource",
user = "testdb",
password = "testdb",
serverName = "localhost",
portNumber = 5432,
databaseName = "testdb",
minPoolSize = 10,
maxPoolSize = 50)
})
public class DatasourceDefinitions {}
我尝试使用 localhost
、127.0.0.1
并使用参数 url
而不是三元组 serverName
、port
和 databaseName
,但我总是运行变成Connection Refused
错误
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
... 41 more
我已经检查了 user
和 password
,如果我尝试使用 pgAdmin
登录,它们工作正常。
这是 Postgres 配置:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
我也启用了线路
listen_addresses = 'localhost' # what IP address(es) to listen on;
在配置文件中postgresql.conf
谁能告诉我我错过了什么and/or做错了什么?
已解决。
问题出在 Postgres
配置中,即文件 /etc/postgresql/9.4/main/postgresql.conf
.
我改了这个
listen_addresses = 'localhost'
进入这个
listen_addresses = '127.0.0.1'
现在它完美运行了。