PostgreSQL
Mac OS 설치하기
설치전에 homebrew를 최신 버전으로 update해준다.
$ brew updateupdate를 완료하면, 설치하고자 하는 패키지가 존재하는지 검색해본다.
$ brew search postgresql
==> Formulae
postgresql ✔ postgresql@11 postgresql@13 postgresql@9.5 qt-postgresql
postgresql@10 postgresql@12 postgresql@9.4 postgresql@9.6 postgrest원하는 버전의 postgresql을 설치해준다.
$ brew install postgresql
...
==> Installing postgresql
==> Pouring postgresql--14.1_1.arm64_monterey.bottle.tar.gz
==> /opt/homebrew/Cellar/postgresql/14.1_1/bin/initdb --locale=C -E UTF-8 /opt/h
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres
For more details, read:
https://www.postgresql.org/docs/14/app-initdb.html
To restart postgresql after an upgrade:
brew services restart postgresql
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres
==> Summary
🍺 /opt/homebrew/Cellar/postgresql/14.1_1: 3,304 files, 44.5MB
==> Running `brew cleanup postgresql`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> postgresql
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres
For more details, read:
https://www.postgresql.org/docs/14/app-initdb.html
To restart postgresql after an upgrade:
brew services restart postgresql
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres설치가 완료되면 사용법에 대해 알려주며, 설치 버전 확인을 통해 설치가 정상적으로 됐는지 확인한다.
현재 기준 default 버전 14.1이 정상적으로 설치 된 것을 확인할 수 있다.
start명령어를 통해 postgresql을 시작할 수 있다.
시작하기
접속하기
superuser로 접속하는 경우 database명#로 뜬다.
특정 사용자로 특정 database 접속하기
다음과 같이 spring으로 뜨는 것을 확인할 수 있다. superuser가 아닌경우에는 database명=>로 뜬다.
계정 조회 하기
https://www.postgresql.org/docs/current/postgres-user.html에 보면 설치시 자동으로 적합한 사용자 계정을 생성해준다고 되어있다.
조회 명령어를 치면, 별도로 생성한적 없는 dahyelele(mac 계정명) superuser가 생성되어있는 것을 볼 수 있다.
계정 생성하기
권한 부여하기
사용자에게 어떤 권한을 줄지 입력하면 된다. 권한 부여 후 \du로 부여된 권한을 확인할 수 있다.
DB 권한 부여하기
Database 리스트 조회
Database 연결하기
Table 리스트 조회
Schema 생성
PostgreSQL에서는 Database -> Schema -> Table 개념이다. 그래서 Schema를 생성해준 후 테이블을 생성해주어야한다. 이때 권한이 있는 database로 연결한 후 스키마를 생성해야한다.
Schema 조회
스키마 목록을 보면 test에 위에서 생성한 spring이 생성된 것을 확인할 수 있다.
client
DBeaver는 mysql, postgresql 등등 다양한 database접근을 제공해준다.

host, username, password등 사용할 계정 정보를 입력하여 시작할 수 있다.
이때 
다음과 같이 show all databases를 설정해주어야지 기존에 생성한 모든 database가 목록에 보인다.
참고
Last updated
Was this helpful?