java org.postgresql.util.PSQLException:致命错误:在Windows上工作的主机Linux错误没有pg_hba.conf条目

fnvucqvd  于 2023-01-11  发布在  Java
关注(0)|答案(1)|浏览(331)

我已经看了很多(太多)类似的问题在这里,并试图一遍又一遍地解决这一个,但我不能完全得到它解决。
我有一个java代码,它连接到RHEL 8.2机器上的PostGreSQL服务器来查询和返回一个值。它工作起来没有任何问题。但是,当我在Linux机器上本地运行它时,它失败了,并出现可怕的org. postgresql. util. pSQLException:致命错误:没有主机的pg_hba. conf条目。
Java代码由ETL软件Talend编写;代码由RunDeck在Linux上运行。
更令人困惑的是,我可以以postgres用户身份登录Linux,并使用psql接口连接到数据库,使用的主机、端口、数据库和用户与在Java中使用的主机、端口、数据库和用户相同,而且不会出错-
psql -h [server ip] -p 5432 -d my_special_db -U my_db_user
我已经检查了服务器设置、pg_hba. conf文件、用户权限、日志文件,并尝试更改以上所有内容以获得某种返回;都无济于事。
我在pg_hba. conf中添加了:

host    my_special_db        my_db_user        [server ip]/32      md5
host    my_special_db        my_db_user        [server ip with .0 as the last quatraine]/24      md5

host    my_special_db        root        ::1/128      trust
host    all        all        [server ip]/32      trust

我已经尝试了多种连接修饰符,如:

sslfactory=org.postgresql.ssl.NonValidatingFactory&sslmode=prefer
or
sslmode=prefer
or
sslmode=Require
or
no modifier at all

请指示。
详情:
操作系统名称:Linux RHEL 8.2
版本号:4.18.0 - 372.16.1.el8_6.x86_64
虚拟机
实施版本:2015年11月15日+9日-左侧
名称:OpenJDK 64位服务器虚拟机
VENDOR : Amazon.com Inc.
版本号:2015年11月05日
PostGreSQL语言
后处理器
邮政编码
postgresql11-server-11.7-1PGDG.rhel8.x86_64.rpm
在服务器〉属性〉SSL下
所有默认值:
SSL模式:首选
客户证书:[空白]
客户端证书密钥:[空白]
根证书:[空白]
证书版本列表:[空白]
SSL压缩?:没有
一个一个二个一个一个一个三个一个一个一个一个一个一个四个一个一个一个一个一个五个一个
更新:这里是我可以分享的Java错误消息的大部分;考虑到我可以发布的内容的一些限制;

error message :: FATAL: no pg_hba.conf entry for host "[my_server_ip]", user "my_db_user", database "my_db", SSL off|4
Exception in component tDBConnection_2 (Generic_Talend_Job)
org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "[my_server_ip]", user "my_db_user", database "my_db", SSL off
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:613)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:161)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
    at org.postgresql.Driver.makeConnection(Driver.java:465)
    at org.postgresql.Driver.connect(Driver.java:264)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tDBConnection_2Process(Generic_Talend_Job.java:5752)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tSystem_1Process(Generic_Talend_Job.java:5614)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tJava_3Process(Generic_Talend_Job.java:5342)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tWarn_1Process(Generic_Talend_Job.java:5094)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tFileInputDelimited_1Process(Generic_Talend_Job.java:4851)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tLibraryLoad_1Process(Generic_Talend_Job.java:4089)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.tPrejob_1Process(Generic_Talend_Job.java:3856)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.runJobInTOS(Generic_Talend_Job.java:11916)
    at local_project.generic_talend_job_0_1.Generic_Talend_Job.main(Generic_Talend_Job.java:11245)
    Suppressed: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "[my_server_ip]", user "my_db_user", database "my_db", SSL off
        at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:613)
        at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:161)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
        ... 15 more
sec db connection failure, error message :: FATAL: no pg_hba.conf entry for host "[my_server_ip]", user "my_db_user", database "my_db", SSL off

更新2:在再次尝试并获得相同错误后,今天上午的条目记录在/data_folder/log

[postgres@my_server_name log]$ vim postgresql-Wed.log
2022-08-24 10:00:17.714 EDT [79801] LOG:  received fast shutdown request
2022-08-24 10:00:17.717 EDT [79801] LOG:  aborting any active transactions
2022-08-24 10:00:17.717 EDT [508177] FATAL:  terminating connection due to administrator command
2022-08-24 10:00:17.717 EDT [508176] FATAL:  terminating connection due to administrator command
2022-08-24 10:00:17.718 EDT [79801] LOG:  background worker "logical replication launcher" (PID 79809) exited with exit code 1
2022-08-24 10:00:17.718 EDT [79804] LOG:  shutting down
2022-08-24 10:00:17.740 EDT [79801] LOG:  database system is shut down
2022-08-24 10:00:35.780 EDT [513920] LOG:  database system was shut down at 2022-08-24 10:00:17 EDT
2022-08-24 10:00:35.788 EDT [513918] LOG:  database system is ready to accept connections

更新3:
从postgresql.conf文件中:

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - 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 = 5432             # (change requires restart)
max_connections = 100           # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp'  # comma-separated list of directories
                    # (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)

# - 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

# - Authentication -

#authentication_timeout = 1min      # 1s-600s
#password_encryption = md5      # md5 or scram-sha-256
#db_user_namespace = off

# GSSAPI using Kerberos
#krb_server_keyfile = ''
#krb_caseins_users = off

# - SSL -

#ssl = off
#ssl_ca_file = ''
#ssl_cert_file = 'server.crt'
#ssl_crl_file = ''
#ssl_key_file = 'server.key'
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = 'prime256v1'
#ssl_dh_params_file = ''
#ssl_passphrase_command = ''
#ssl_passphrase_command_supports_reload = off

更新4:
在做了更多的搜索之后,我发现postgres日志记录的默认设置并不冗长;这是比较冗长的部分

[636130] [630676b4.9b4e2] [2022-08-24 15:06:28.850 EDT] [] [F0000] [] [] [] [] [] [7] [0]:  LOG:  hostssl record cannot match because SSL is disabled
[636130] [630676b4.9b4e2] [2022-08-24 15:06:28.850 EDT] [] [F0000] [] [] [] [] [] [8] [0]:  HINT:  Set ssl = on in postgresql.conf.
[636130] [630676b4.9b4e2] [2022-08-24 15:06:28.850 EDT] [] [F0000] [] [] [] [] [] [9] [0]:  CONTEXT:  line 103 of configuration file "[data folder path]/pg_hba.conf"
[636132] [630676b4.9b4e4] [2022-08-24 15:06:28.854 EDT] [] [00000] [] [] [] [] [] [1] [0]:  LOG:  database system was shut down at 2022-08-24 15:06:18 EDT
[636130] [630676b4.9b4e2] [2022-08-24 15:06:28.859 EDT] [] [00000] [] [] [] [] [] [10] [0]:  LOG:  database system is ready to accept connections

我已经得到了这个错误,即使在以下更新-
更新postgresql.conf文件:

edit 1
ssl = off
edit 2
ssl = on
edit 3
#ssl = off

更新了postgresql.conf文件中的日志级别

log_line_prefix = '[%p] [%c] [%m] [%v] [%e] [%i] [%d] [%u] [%a] [%r] [%l] [%x]:  '  
...
log_statement = 'all'

更新了pg_hba. conf文件,以从以下内容开始:

# Allow any user on the local system to connect to any database with
# any database user name using Unix-domain sockets (the default for local
# connections).
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     trust

# The same using local loopback TCP/IP connections.
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             127.0.0.1/32            trust

# The same as the previous line, but using a separate netmask column
#
# TYPE  DATABASE        USER            IP-ADDRESS      IP-MASK             METHOD
host    all             all             127.0.0.1       255.255.255.255     trust

# The same over IPv6.
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             ::1/128                 trust

# The same using a host name (would typically cover both IPv4 and IPv6).
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             localhost               trust
hostssl    all        all        0.0.0.0/0      md5

还将连接参数更新为-

sslfactory=org.postgresql.ssl.NonValidatingFactory

根据postgres的说法,这应该可以阻止任何和所有的SSL问题,只是让连接通过-
https://jdbc.postgresql.org/documentation/head/ssl-client.html
"通过驱动程序提供的自定义SSLSocketFactory类建立非验证连接。设置连接URL参数sslfactory = org. postgresql. ssl. NonValidatingFactory将关闭所有SSL验证。"
更新5:
postgresql.conf文件中的日志记录设置:

#------------------------------------------------------------------------------
# REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

log_destination = 'stderr'      # Valid values are combinations of
                    # stderr, csvlog, syslog, and eventlog,
                    # depending on platform.  csvlog
                    # requires logging_collector to be on.

# This is used when logging to stderr:
logging_collector = on          # Enable capturing of stderr and csvlog
                    # into log files. Required to be on for
                    # csvlogs.
                    # (change requires restart)

# These are only used if logging_collector is on:
log_directory = 'log'           # directory where log files are written,
                    # can be absolute or relative to PGDATA
log_filename = 'postgresql-%a.log'  # log file name pattern,
                    # can include strftime() escapes
#log_file_mode = 0600           # creation mode for log files,
                    # begin with 0 to use octal notation
log_truncate_on_rotation = on       # If on, an existing log file with the
                    # same name as the new log file will be
                    # truncated rather than appended to.
                    # But such truncation only occurs on
                    # time-driven rotation, not on restarts
                    # or size-driven rotation.  Default is
                    # off, meaning append to existing files
                    # in all cases.
log_rotation_age = 1d           # Automatic rotation of logfiles will
                    # happen after that time.  0 disables.
log_rotation_size = 0           # Automatic rotation of logfiles will
                    # happen after that much log output.
                    # 0 disables.

# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'
#syslog_sequence_numbers = on
#syslog_split_messages = on

# This is only relevant when logging to eventlog (win32):
# (change requires restart)
#event_source = 'PostgreSQL'

# - When to Log -

#log_min_messages = warning     # values in order of decreasing detail:
                    #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                    #   info
                    #   notice
                    #   warning
                    #   error
                    #   log
                    #   fatal
                    #   panic

#log_min_error_statement = error    # values in order of decreasing detail:
                    #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                    #   info
                    #   notice
                    #   warning
                    #   error
                    #   log
                    #   fatal
                    #   panic (effectively off)

#log_min_duration_statement = -1    # -1 is disabled, 0 logs all statements
                    # and their durations, > 0 logs only
                    # statements running at least this number
                    # of milliseconds

# - What to Log -

#debug_print_parse = off
#debug_print_rewritten = off
#debug_print_plan = off
#debug_pretty_print = on
#log_checkpoints = off
#log_connections = off
#log_disconnections = off
#log_duration = off
#log_error_verbosity = default      # terse, default, or verbose messages
#log_hostname = off
log_line_prefix = '[%p] [%c] [%m] [%v] [%e] [%i] [%d] [%u] [%a] [%r] [%l] [%x]:  '      # special values:
                    #   %a = application name
                    #   %u = user name
                    #   %d = database name
                    #   %r = remote host and port
                    #   %h = remote host
                    #   %p = process ID
                    #   %t = timestamp without milliseconds
                    #   %m = timestamp with milliseconds
                    #   %n = timestamp with milliseconds (as a Unix epoch)
                    #   %i = command tag
                    #   %e = SQL state
                    #   %c = session ID
                    #   %l = session line number
                    #   %s = session start timestamp
                    #   %v = virtual transaction ID
                    #   %x = transaction ID (0 if none)
                    #   %q = stop here in non-session
                    #        processes
                    #   %% = '%'
                    # e.g. '<%u%%%d> '
#log_lock_waits = off           # log lock waits >= deadlock_timeout
log_statement = 'all'           # none, ddl, mod, all
#log_replication_commands = off
#log_temp_files = -1            # log temporary files equal or larger
                    # than the specified size in kilobytes;
                    # -1 disables, 0 logs all temp files
log_timezone = 'America/New_York'

更新6:
我对配置的日志记录部分进行了编辑,现在日志中有很多输出
新的日志记录设置:

#------------------------------------------------------------------------------
# REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

log_destination = 'stderr'      # Valid values are combinations of
                    # stderr, csvlog, syslog, and eventlog,
                    # depending on platform.  csvlog
                    # requires logging_collector to be on.

# This is used when logging to stderr:
logging_collector = on          # Enable capturing of stderr and csvlog
                    # into log files. Required to be on for
                    # csvlogs.
                    # (change requires restart)

# These are only used if logging_collector is on:
log_directory = 'log'           # directory where log files are written,
                    # can be absolute or relative to PGDATA
log_filename = 'postgresql-%a.log'  # log file name pattern,
                    # can include strftime() escapes
#log_file_mode = 0600           # creation mode for log files,
                    # begin with 0 to use octal notation
log_truncate_on_rotation = on       # If on, an existing log file with the
                    # same name as the new log file will be
                    # truncated rather than appended to.
                    # But such truncation only occurs on
                    # time-driven rotation, not on restarts
                    # or size-driven rotation.  Default is
                    # off, meaning append to existing files
                    # in all cases.
log_rotation_age = 1d           # Automatic rotation of logfiles will
                    # happen after that time.  0 disables.
log_rotation_size = 0           # Automatic rotation of logfiles will
                    # happen after that much log output.
                    # 0 disables.

# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'
#syslog_sequence_numbers = on
#syslog_split_messages = on

# This is only relevant when logging to eventlog (win32):
# (change requires restart)
#event_source = 'PostgreSQL'

# - When to Log -

log_min_messages = debug5       # values in order of decreasing detail:
                    #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                    #   info
                    #   notice
                    #   warning
                    #   error
                    #   log
                    #   fatal
                    #   panic

log_min_error_statement = debug5    # values in order of decreasing detail:
                    #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                    #   info
                    #   notice
                    #   warning
                    #   error
                    #   log
                    #   fatal
                    #   panic (effectively off)

log_min_duration_statement = 0  # -1 is disabled, 0 logs all statements
                    # and their durations, > 0 logs only
                    # statements running at least this number
                    # of milliseconds

# - What to Log -

#debug_print_parse = off
#debug_print_rewritten = off
#debug_print_plan = off
#debug_pretty_print = on
#log_checkpoints = off
log_connections = on
log_disconnections = on
#log_duration = off
log_error_verbosity = verbose       # terse, default, or verbose messages
log_hostname = on
log_line_prefix = '[%p] [%c] [%m] [%v] [%e] [%i] [%d] [%u] [%a] [%r] [%l] [%x]:  '      # special values:
                    #   %a = application name
                    #   %u = user name
                    #   %d = database name
                    #   %r = remote host and port
                    #   %h = remote host
                    #   %p = process ID
                    #   %t = timestamp without milliseconds
                    #   %m = timestamp with milliseconds
                    #   %n = timestamp with milliseconds (as a Unix epoch)
                    #   %i = command tag
                    #   %e = SQL state
                    #   %c = session ID
                    #   %l = session line number
                    #   %s = session start timestamp
                    #   %v = virtual transaction ID
                    #   %x = transaction ID (0 if none)
                    #   %q = stop here in non-session
                    #        processes
                    #   %% = '%'
                    # e.g. '<%u%%%d> '
#log_lock_waits = off           # log lock waits >= deadlock_timeout
log_statement = 'all'           # none, ddl, mod, all
#log_replication_commands = off
#log_temp_files = -1            # log temporary files equal or larger
                    # than the specified size in kilobytes;
                    # -1 disables, 0 logs all temp files
log_timezone = 'America/New_York'

我不能在这里粘贴错误日志,因为在使它冗长之后,它非常长-所以我做了一个要点
最后更新日期:
我删除了要点,因为这里的偷窥者帮助我找到了我的错误:
好吧,问题是三件事第一件事,我们有一个'properties'文件,我认为它被设置为这个服务器这个数据库;并且它不是//thing 2,默认日志记录设置为"warning",没有足够的信息,因此在将其设置为调试级别5(最多数据)和"all"事件后;我终于看到了一个错误消息,让我意识到它是指向错误的db//thing 3,在我的pg_hba. conf文件的许多(太多)迭代,我已经添加,然后删除IP地址.所以现在它的工作,哈哈有时你太接近轨道看到火车,哈哈

zd287kbt

zd287kbt1#

我删除了要点,因为这里的偷窥者帮助我找到了我的错误:
好吧,问题是三件事第一件事,我们有一个'properties'文件,我认为它被设置为这个服务器这个数据库;并且它不是// thing 2,默认日志记录设置为“warning”,没有足够的信息,因此在将其设置为调试级别5(最多数据)和“all”事件后;我终于看到了一个错误消息,让我意识到它是指向错误的db // thing 3,在我的pg_hba.conf文件的许多(太多)迭代,我已经添加,然后删除IP地址.所以现在它的工作,哈哈有时你太接近轨道看到火车,哈哈

相关问题