在同一LAN中通过JDBC连接到Postgres服务器时的PSQLException(PGAdmin工作)

时间:2012-06-26 09:48:27

标签: database postgresql jdbc dbvisualizer

从DBVisualizer(8.0.9)连接到在同一LAN中运行的PostgreSQL服务器时,我遇到了一些严重问题。 DBVis是基于Java的,因此使用JDBC进行连接。从PGAdmin连接就像一个魅力 - 只有通过JDBC的DBVis连接不是。我需要解决这个问题!

Specs:
My PC: Ubuntu 12.04 LTS (64Bit), IP: 192.168.110.193
Server OS: Suse LINUX Enterprise Server 11, IP: 192.168.110.12
Postgresql server version: 9.1
Java VM: Java HotSpot(TM) 64-Bit Server VM
Java Version: 1.6.0_33
Java Vendor: Sun Microsystems Inc.
OS Name: Linux
OS Arch: amd64
OS Version: 3.2.0-25-generic 

开始连接时,我收到“正在连接...”消息,等待约5分钟后,连接窗口中会出现以下错误消息:

"An error occurred while establishing the connection:
Long Message:
The connection attempt failed.
Details:
Type: org.postgresql.util.PSQLException
SQL State: 08001"

调试控制台中,我得到:

12:04:57 [DEBUG pool-2-thread-8 D.ā] RootConnection: Driver.acceptsURL("jdbc:postgresql://192.168.110.12:5432/MYDATABASE")
12:04:57 [DEBUG pool-2-thread-8 D.ā] RootConnection: Driver.connect("jdbc:postgresql://192.168.110.12:5432/MYDATABASE", {user=******, password=******})
12:24:58 [DEBUG pool-2-thread-8 D.ā] RootConnection: EXCEPTION -> org.postgresql.util.PSQLException: The connection attempt failed.

还提供了 JDBC驱动程序的调试信息:

org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:150)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.(AbstractJdbc4Connection.java:30)
at org.postgresql.jdbc4.Jdbc4Connection.(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.onseven.dbvis.d.B.D.ā(Z:1548)
at com.onseven.dbvis.d.B.F$A.call(Z:278)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679) 

为方便起见,服务器的相关部分 pg_hba.conf

#"local" is for Unix domain socket connections only
local all all peer

#IPv4 local connections:
host all all 192.168.110.0/24 md5

#IPv6 local connections:
host all all ::1/128 md5

postgresql.conf 的相关部分:

# - Connection Settings -

listen_addresses = '*'                  # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directory = ''             # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

# - Security and Authentication -

#authentication_timeout = 1min          # 1s-600s
#ssl = off                              # (change requires restart)
#ssl_ciphers = 'ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH'      # allowed SSL ciphers
                                        # (change requires restart)
#ssl_renegotiation_limit = 512MB        # amount of data between renegotiations
#password_encryption = on
#db_user_namespace = off

# Kerberos and GSSAPI
#krb_server_keyfile = ''
#krb_srvname = 'postgres'               # (Kerberos only)
#krb_caseins_users = off

# - TCP Keepalives -
# see "man 7 tcp" for details

#tcp_keepalives_idle = 0                # TCP_KEEPIDLE, in seconds;
                                        # 0 selects the system default
#tcp_keepalives_interval = 0            # TCP_KEEPINTVL, in seconds;
                                        # 0 selects the system default
#tcp_keepalives_count = 0               # TCP_KEEPCNT;
                                        # 0 selects the system default

2 个答案:

答案 0 :(得分:0)

连接现在正在运行,但不幸的是我无法准确地告诉导致解决方案的步骤。无论如何,我会尝试草绘它们:

我安装了旧版本的DBVisualizer(7.1.5),并且能够成功建立与数据库服务器的连接。然后我直接回到8.0.9 版本的DBVis并再次测试连接。出乎意料的是,连接也在这里工作,即使我没有更改配置 - 无论是在我的DBVis 8.0.9安装还是在DB服务器上。而已。也许有人在这个问题上有更多的线索。

答案 1 :(得分:0)

错误代码 08001 是一个通用错误代码,表明 JDBC 驱动程序无法连接到数据库。造成这种情况的原因可能有很多。

您应该输入作为数据库服务器运行数据库的服务器的 IP 地址或 DNS 名称以及它侦听 TCP/IP 连接的数据库端口,默认为 5432。

输入此内容后,请使用 Ping Server 按钮查看是否可以访问该服务器和端口。如果您收到错误消息,则说明您输入了错误的数据库服务器或端口值、防火墙阻止了连接,或者 PostgreSQL 服务器未配置为从您的 PC 访问连接。如果 Ping 服务器显示一切正常但您仍然无法连接,则问题很可能出在您指定的用户帐户的登录凭据上。