1

从 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
4

2 回答 2

0

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

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

于 2012-07-05T14:08:44.050 回答
0

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

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

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

于 2021-07-21T19:39:12.313 回答