[英]Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"
When I try to connect to my PostgreSQL server using my credentials using (pgadmin iii - postgres sqltool) it works fine.当我尝试使用 (pgadmin iii - postgres sqltool) 使用我的凭据连接到我的 PostgreSQL 服务器时,它工作正常。 When I try to connect from my java application I get the below logs.
当我尝试从我的 java 应用程序连接时,我得到以下日志。 It's weird
有点奇怪
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.getCollegeDetails(Unknown Source)
at com.cts.bo.HESBO.registerCourse(HESBO.java:42)
at com.cts.facade.HESFacade.registerCourse(HESFacade.java:34)
at com.cts.manager.HESManager.registerCourse(HESManager.java:34)
at com.cts.presentation.Tester.registerCourse(Tester.java:66)
at com.cts.presentation.Tester.main(Tester.java:159)
**Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"**
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:415)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:188)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:143)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
at org.postgresql.jdbc3g.Jdbc3gConnection.<init>(Jdbc3gConnection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:412)
at org.postgresql.Driver.connect(Driver.java:280)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202)
... 11 more
.properties file .properties 文件
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/postgres
jdbc.password=admin
jdbc.username=admin
spring.xml spring.xml
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>com\cts\resource\constant.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
Any help on this is much appreciated, I am just not able to progress because of this weird error.非常感谢对此的任何帮助,由于这个奇怪的错误,我无法取得进展。
If you have not tried this already, review your pg_hba.conf file.如果您还没有尝试过,请查看您的 pg_hba.conf 文件。 It will be named something like
它将被命名为
/etc/postgresql/9.6/main/pg_hba.conf # Ubuntu 16.04
/var/lib/pgsql/9.3/data/pg_hba.conf # Fedora 20
You may have to use find / -name pg_hba.conf to locate it.您可能必须使用 find / -name pg_hba.conf 来定位它。
At the bottom of the file, change the METHOD values to trust for local testing (see postgres docs for full information).在文件底部,将 METHOD 值更改为信任以进行本地测试(有关完整信息,请参阅 postgres 文档)。 Restart postgres to ensure everything is started clean and the new params are read:
重新启动 postgres 以确保一切都干净启动并读取新参数:
sudo systemctl restart postgresql # ubuntu
Hopefully this will cure your woes.希望这能治愈你的烦恼。 It solved my problems on Ubuntu/Fedora.
它解决了我在 Ubuntu/Fedora 上的问题。
I think the problem might be that the postgres database is configured to allow the only password that are hashed with md5.我认为问题可能是 postgres 数据库配置为允许使用 md5 散列的唯一密码。
You can check if this is true by going to the configuration file pg_hba.conf
.您可以通过转到配置文件
pg_hba.conf
来检查这是否正确。 Search with the following property host all all all
if you find that the property is configured like below:如果您发现该属性配置如下,请使用以下属性
host all all all
搜索:
host all all all md5
than the issue is that you need to hash the password to md5.比问题是你需要 hash 的密码到 md5。 You can fix this by changing the configuration to:
您可以通过将配置更改为:
trust
instead of md5
-> will allow user to connect without any password trust
而不是md5
-> 将允许用户无需任何密码即可连接password
instead of md5
-> will allow user to connect with plain text password password
而不是md5
-> 将允许用户使用纯文本密码进行连接在 Login 部分下创建一个新用户并在 application.properties 中使用它,解决了这个问题。
I had the same problem, although I was running the PostgreSQL server inside a Docker container.我遇到了同样的问题,尽管我在 Docker 容器内运行 PostgreSQL 服务器。 I fixed it by using a different port mapping (eg 0.0.0.0:5433->5432/tcp).
我通过使用不同的端口映射(例如 0.0.0.0:5433->5432/tcp)来修复它。
Symptoms and debugging:症状及调试:
The error message was "org.postgresql.util.PSQLException: FATAL: password authentication failed for user xxx".错误消息是“org.postgresql.util.PSQLException: FATAL: password authentication failed for user xxx”。
Changing JDBC host, port or username resulted in a different error message.更改 JDBC 主机、端口或用户名会导致不同的错误消息。
PgAdmin was able to connect to the database. PgAdmin 能够连接到数据库。
PgAdmin connections were shown in the PostgreSQL log (after enabling connection logging), but nothing was shown when trying to connect with JDBC. PgAdmin 连接显示在 PostgreSQL 日志中(启用连接日志记录后),但在尝试连接 JDBC 时未显示任何内容。
tcpdump port 5432
showed nothing when trying to connect with JDBC, but showed something when connecting with PgAdmin, or when sending random data with netcat. tcpdump port 5432
在尝试连接 JDBC 时没有显示任何内容,但在连接 PgAdmin 或使用 netcat 发送随机数据时显示了一些内容。
In the end the root cause remained unclear.最后,根本原因仍然不清楚。 But obviously it was not a password problem, so the JDBC driver shouldn't say it is.
但显然不是密码问题,所以JDBC驱动应该不会说是。
Docker version 20.10.17 running on Windows 10. PostgreSQL driver version was 42.4.1. Docker 版本 20.10.17 在 Windows 10 上运行。PostgreSQL 驱动程序版本为 42.4.1。
For me, its worked when i updated the version对我来说,它在我更新版本时起作用
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
<version>42.5.0</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.