본문 바로가기

Web/DB

[Spring postgreSQL] 연동하기

728x90

https://www.postgresql.org/docs/current/postgres-user.html

 

19.1. The PostgreSQL User Account

19.1. The PostgreSQL User Account As with any server daemon that is accessible to the outside world, it is advisable to …

www.postgresql.org

 

 

 

 

 

1. DB driver 설치

# 설치
$ brew install postgresql

# postgreSQL 버전확인
$ postgres --version

 

뭘 엄청 설치해서 당황 ;_; 오래걸렸다

 

 

1-1.

# postgresql start
brew services start postgresql

# version check
postgres -V

# 최초 계정 접속
psql postgres

#db 생성
create database db명;

#user 생성
create user 아이디 with encrypted password '비밀번호';

#user에게 권한 부여
grant all privileges on database db명 to 아이디;

# postgresql stop
brew services stop postgresql

 

 

 

2. build.gradle

dependencies {
	runtimeOnly 'org.postgresql:postgresql'
    }

 

 

 

3. application.properties

# Postgresql
spring.datasource.url=jdbc:postgresql://localhost:port/dbName

# 기본 포트는 localhost:5432/postgres

spring.datasource.username=<username def: postgres>
spring.datasource.password=<password def: superUser의 password>

# JPA
spring.jpa.hibernate.dialect = org.hibernate.dialect.PostgreSQL10Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.show-sql = true

 

728x90