프로젝트

RDS postgresql 에서 Springboot 로 데이터 베이스 연결 오류 해결

쿠키담임선생님 2023. 12. 12. 19:03

Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:301) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.3.1.jar:42.3.1] at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225) ~[po|

 

 

이런 에러가 콘솔에 등장했다.

 

분명 application.yml도 

 

spring:
  jpa:
    hibernate:
      format_sql: true
      use_sql_comments: true
      ddl-auto: create
    show-sql: true
    database: postgresql
  datasource:
#    url: jdbc:h2:mem:testdb
    url: database-1.c8.ap-northeast-2.rds.amazonaws.com
    username: postgres
    password: postgres2023!
    driver-class-name: org.postgresql.Driver
#  h2:
#    console:
#      enabled: true
  defer-datasource-initialization: true

 

이렇게 넣었었고

 

build.gradle 도

implementation group: 'org.postgresql', name: 'postgresql', version: '42.3.1'
runtimeOnly 'org.postgresql:postgresql'

 

이렇게 넣었는데

 

원인은 .yml 파일의 url을 저렇게 바로 복붙해서 넣으면 안되었다.

 

평소 디비버나 디비툴에 연동시킬때처럼 했더니 오류가 난것이다.

 

저 부분을 

 

spring:
  jpa:
    hibernate:
      format_sql: true
      use_sql_comments: true
      ddl-auto: create
    show-sql: true
    database: postgresql
  datasource:
#    url: jdbc:h2:mem:testdb
    url: jdbc:postgresql://database-1.c8.ap-northeast-2.rds.amazonaws.com/postgres
    username: postgres
    password: postgres2023!
    driver-class-name: org.postgresql.Driver
#  h2:
#    console:
#      enabled: true
  defer-datasource-initialization: true

 

 

이렇게 //와 뒤에 / 로 감싸서 앞뒤로 덧붙여주어야 했다.

그랫더니 잘 데이터가 들어가는 것을 확인했다.