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?