PSQLException通过同一局域网中的JDBC连接到Postgres服务器(PGAdmin工作)



我在从DBVisualizer(8.0.9)连接到在同一局域网中运行的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

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

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

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

应输入作为数据库服务器运行数据库的服务器的 IP 地址或 DNS 名称,以及它侦听 TCP/IP 连接的数据库端口(缺省值为 5432)。

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

相关内容

  • 没有找到相关文章

最新更新