Postgres数据库问题编码UTF-8
我已经使用此命令Docker创建了一个Docker映像-D 我能够在http:// localhost中加载pgadmin实例:5050/浏览器/ 在相同的情况下创建数据库和表,凭据正常工作。
但是,当我开始运行主要的Spring Boot应用程序 CustomerApplication 时,它会在以下错误&gt中失败。
org.postgresql.util.util.psqlexception:致命:laautentificación密码fallóparapara el usuario«amigoscode»(pgjdbc:自动检测服务器对编码为iso-88859-1 /或主机,端口,dbname,用户,密码,pg_hba.conf)
我不知道怎么了,我的凭据是正确的。 似乎是什么问题?
应用
是
services:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: amigoscode
POSTGRES_PASSWORD: password
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "5050:80"
networks:
- postgres
restart: unless-stopped
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:
。
server:
port: 8080
spring:
application:
name: customer
datasource:
username: amigoscode
url: jdbc:postgresql://localhost:5432/customer
password: password
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
show-sql: true
以下 客户表脚本
CREATE DATABASE customer
WITH
OWNER = amigoscode
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.utf8'
LC_CTYPE = 'en_US.utf8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
I have created a docker image with this command docker compose up -d
where I was able to load pgAdmin instance in http://localhost:5050/browser/
create a database and table in the same , credentials are working properly.
However when I start to run my main spring boot application CustomerApplication it fails with below error >
org.postgresql.util.PSQLException: FATAL: la autentificación password falló para el usuario «amigoscode» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)
I do not know what is wrong, my credentials are correct.
what seems to be the issue?
below are application.yml and docker-compose.yml
docker-compose.yml
services:
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: amigoscode
POSTGRES_PASSWORD: password
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "5050:80"
networks:
- postgres
restart: unless-stopped
networks:
postgres:
driver: bridge
volumes:
postgres:
pgadmin:
application.yml
server:
port: 8080
spring:
application:
name: customer
datasource:
username: amigoscode
url: jdbc:postgresql://localhost:5432/customer
password: password
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
show-sql: true
customer table Script
CREATE DATABASE customer
WITH
OWNER = amigoscode
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.utf8'
LC_CTYPE = 'en_US.utf8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于我在本地(port 5432 )中安装了Postgres实例并运行,因此MicroService客户试图连接到该实例,而不是使用同一端口的Docker中的一个。
解决方案是从 application.yml 更改URL端口
URL:JDBC:PostgreSql:// localhost: 5433 /客户
ports的Postgres港口
以及来自 docker-compose.yml
:
- “ 5432 :5432”
to
端口:
- “ 5433 :5432”,
因此微服务连接到docker映像中的postgres实例,而不是本地的,
然后重新运行的docker命令docker docker构成-d
运行客户应用( sprinbgootapplication ),这次
通过创建客户表,应用程序启动良好,顺利。
Since I have a postgres instance installed and running in my local (port 5432), the microservice customer was trying to connect to that instance, not the one from docker which was using the same port.
the solution was to change the url port from application.yml
url: jdbc:postgresql://localhost:5433/customer
and the port of postgres from docker-compose.yml
from
ports:
- "5432:5432"
to
ports:
- "5433:5432"
so microservice connects to the postgres instance in the docker image, not the local one
then re-run docker command docker compose up -d
run the CustomerApplication (SprinbgootApplication) and this time
application starts up nice and smoothly by creating the customer table.
当您创建角色
Amigoscode
时,您是否为其设置了密码?您可能已经登录pgadmin作为
postgres
superuser,创建了角色amigoscode
,并且从未设置密码。编码问题看起来类似于指定的在这里提供的密码不正确。看起来PGJDBC错误是在2014年修复的,但可能已经在更现代的版本中进行了回归 - for-postgresql-messages in-jdbc“>类似的未解决的问题。其他可能的替代方法:
application.properties
文件,该文件具有不同的密码,该密码将优先于application.yml
。When you created the role
amigoscode
did you actually set a password for it?You may have logged into pgadmin as the
postgres
superuser, created the roleamigoscode
and never set a password. The encoding issue looks similar to the one specified here which appears when the supplied password is incorrect. It looks like that pgjdbc bug was fixed in 2014, but has possibly regressed in more modern versions >= 42.2.x as there is currently a similar unresolved issue.Other likely alternatives:
application.properties
file which has a different password that will take precedence over the one inapplication.yml
.我也发生了同样的事情,问题是我正在运行另一个正在使用端口5432(PostgreSql Server和Docker)的实例,我正在使用DBEAVER,它试图连接到该实例,而是我想使用的实例。
检查哪些应用程序正在使用端口并关闭您不需要的应用程序,然后重新尝试连接到数据库。
The same happened to me, the problem is that i was running another instance that was using the port 5432 (postgresql server and docker), I was using dbeaver and it was trying to connect to that instance instead the one that i wanted to use.
Check which applications are using the port and close the ones that you don't need and try again to connect to the database.