Postgres DB

danbi lee·2024년 10월 25일

build.gradle.kts에 의존성 추가

runtimeOnly("org.postgresql:postgresql")

application.yml datasource 수정

  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5438/courses
    username: postgres
    password: postgres

docker-compose.yml 추가

version: '3.7'
services:
  postgres:
    image: postgres:10.5
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=courses
    logging:
      options:
        max-size: 10m
        max-file: "3"
    ports:
      - '5438:5432'

Homebrew로 Docker Compose 설치

// Homebrew를 사용하여 docker-compose 설치
brew install docker-compose
// 버전 확인
docker-compose --version

Docker compose
: 필요한 구성 요소 설정

docker-compose up

// 실행목록 확인
docker ps

brew install postgres

createuser postgres -s

createdb -p 5432 -h localhost -e courses // courses는 이름!

application.yml 2차 수정

spring:
  application:
    name: course-catalog-service
  datasource:
#    url: jdbc:h2:mem:testdb
#    driver-class-name: org.h2.Driver
#    username: sa
#    password: password
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5438/courses
    #    url: jdbc:postgresql://localhost:5432/courses
    username: postgres
    password: postgres
  jpa:
#    database: h2
#    database-platform: org.hibernate.dialect.H2Dialect
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    generate-ddl: true
    hibernate:
      ddl-auto: create-drop
    show-sql: true
    properties:
      hibernate:
        jdbc:
          lob:
            non_contextual_creation: true
  h2:
    console:
      enabled: true
message: Hello from default profile

https://docs.docker.com/compose/install/linux/#install-the-plugin-manually
https://www.udemy.com/course/build-restful-apis-using-kotlin-and-spring-boot-korean/learn/lecture/42677090#questions

profile
계속해서 보완중

0개의 댓글