org.postgresql.util。PSQLException:致命的:没有pg_hba。配置主机条目

时间:2022-08-11 23:04:30

I am trying to connect to PostgreSQL database which is in remote location using Spring JDBC template. I am getting

我正在尝试连接到使用Spring JDBC模板在远程位置的PostgreSQL数据库。我得到

org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "139.126.243.71", user "guest", database "masterdb", SSL off error

org.postgresql.util。PSQLException:致命的:没有pg_hba。conf进入主机“139.126.243.71”,用户“guest”,数据库“masterdb”,SSL关闭错误。

I don't have access to pg_hba.conf file of the remote location.

我无法访问pg_hba。conf文件的远程位置。

This is the configuration I gave in my spring servlet.xml

这是我在spring servlet.xml中给出的配置。

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://100.64.35.52":5432/masterdb"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</bean>

Can we solve the issue by giving any properties?

我们可以通过提供任何属性来解决这个问题吗?

3 个解决方案

#1


34  

It seems that DB server does not allow SSL off connection, You will have to enable it. Change URL from jdbc:postgresql://100.64.35.52":5432/masterdb to jdbc:postgresql://100.64.35.52":5432/masterdb?sslmode=require

似乎DB服务器不允许SSL断开连接,您将不得不启用它。更改URL从jdbc:postgresql://100.64.35.52“:5432/masterdb到jdbc:postgresql://100.64.35.52”:5432/masterdb?sslmode=require。

Check mode details about ssl mode at http://www.postgresql.org/docs/9.1/static/libpq-ssl.html

在http://www.postgresql.org/docs/9.1/static/libpq-ssl.html查看ssl模式的模式细节。

#2


18  

You must apply blow changes to connect:

你必须应用吹气变化来连接:

in "C:\Program Files (maby x86)\PostgreSQL(your version)\data"

在“C:\程序文件(maby x86)\PostgreSQL(您的版本)\数据”中

in "postgresql.conf" file:

在“postgresql。conf”文件:

check the "listen_addresses" be = ' * ' ( by default its localhost in some postgres versions) if it isn't you must change it to ' * '. it's cause to listen all addresses.

如果不是你必须把它改成' * ',那么请检查"listen_address " = ' * '(默认情况下它的localhost在一些postgres版本中)。所有的地址都要听。

in "pg_hba.conf" file:

在“pg_hba。conf”文件:

add a new row :

添加一个新行:

host all all 0.0.0.0/0 md5

( use of above row is better) or

(使用以上行较好)或。

host guest masterdb 139.126.243.71 md5

And filnally it's very important that the ssl mode be on. for this add blow command in the end of your url:

而且,ssl模式是非常重要的。在您的url末尾添加blow命令:

?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

In Terms of Bean as

就豆子而言。

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://100.64.35.52":5432/masterdb?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</bean>

#3


0  

See my answer here, basically had to put user/pwd in url property

在这里看到我的答案,基本上是把user/pwd放在url属性中。

url="jdbc:postgresql://server:port/mydb?user=fred&amp;password=secret"

#1


34  

It seems that DB server does not allow SSL off connection, You will have to enable it. Change URL from jdbc:postgresql://100.64.35.52":5432/masterdb to jdbc:postgresql://100.64.35.52":5432/masterdb?sslmode=require

似乎DB服务器不允许SSL断开连接,您将不得不启用它。更改URL从jdbc:postgresql://100.64.35.52“:5432/masterdb到jdbc:postgresql://100.64.35.52”:5432/masterdb?sslmode=require。

Check mode details about ssl mode at http://www.postgresql.org/docs/9.1/static/libpq-ssl.html

在http://www.postgresql.org/docs/9.1/static/libpq-ssl.html查看ssl模式的模式细节。

#2


18  

You must apply blow changes to connect:

你必须应用吹气变化来连接:

in "C:\Program Files (maby x86)\PostgreSQL(your version)\data"

在“C:\程序文件(maby x86)\PostgreSQL(您的版本)\数据”中

in "postgresql.conf" file:

在“postgresql。conf”文件:

check the "listen_addresses" be = ' * ' ( by default its localhost in some postgres versions) if it isn't you must change it to ' * '. it's cause to listen all addresses.

如果不是你必须把它改成' * ',那么请检查"listen_address " = ' * '(默认情况下它的localhost在一些postgres版本中)。所有的地址都要听。

in "pg_hba.conf" file:

在“pg_hba。conf”文件:

add a new row :

添加一个新行:

host all all 0.0.0.0/0 md5

( use of above row is better) or

(使用以上行较好)或。

host guest masterdb 139.126.243.71 md5

And filnally it's very important that the ssl mode be on. for this add blow command in the end of your url:

而且,ssl模式是非常重要的。在您的url末尾添加blow命令:

?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

In Terms of Bean as

就豆子而言。

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://100.64.35.52":5432/masterdb?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</bean>

#3


0  

See my answer here, basically had to put user/pwd in url property

在这里看到我的答案,基本上是把user/pwd放在url属性中。

url="jdbc:postgresql://server:port/mydb?user=fred&amp;password=secret"