๐Ÿ˜ PostgreSQL! - 1 ( with ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ฏธ์ž…๋ ฅ ํ•ด๊ฒฐํ•˜๊ธฐ! )

sh_awtylol4ยท2022๋…„ 6์›” 21์ผ
0

๐ŸŒฑ Today I Learn

๋ชฉ๋ก ๋ณด๊ธฐ
5/16
post-thumbnail

RDBMS ์ค‘ ์˜ค๋ผํด ๋‹ค์Œ์œผ๋กœ ๋งŽ์ด ์–ธ๊ธ‰๋˜๋Š” PostgreSQL์„ ํ•œ๋ฒˆ ์„ค์น˜ํ•˜๊ณ  ์‚ฌ์šฉํ•ด๋ณด์ž!

๐Ÿ“€ PostgreSQL ์„ค์น˜ ๋ฐ ํ™•์ธ!

์„ค์น˜

brew install postgresql

์‹คํ–‰

brew services start postgresql

ํ™•์ธ

postgres -V

๐Ÿ™†๐Ÿป DB์— ์ ‘์† ํ•ด ๋ณด์ž!

PostgreSQl์€ ์„ค์น˜์‹œ ์ž๋™์œผ๋กœ ๊ณ„์ •์„ ์ƒ์„ฑํ•ด์ค€๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค!

ํ™•์ธํ•ด ๋ณผ๊นŒ์š”?

psql postgres

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ role(๊ถŒํ•œ) ๋ฆฌ์ŠคํŠธ๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

\du 

์ž˜ ์žˆ๋Š”๊ฒŒ ๋ณด์ž…๋‹ˆ๋‹ค!

๐Ÿ“ผ User ์ƒ์„ฑ๊ณผ ๊ถŒํ•œ ๋ถ€์—ฌ!

์ด์ œ๋Š” User ํ•˜๋‚˜๋ฅผ ๋งŒ๋“ค์–ด ๋ด…์‹œ๋‹ค. ์œ ์ € ์ด๋ฆ„์€ test ๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” test1 ์ž…๋‹ˆ๋‹ค.

# User ์ƒ์„ฑ
create role test with login password 'test1';

# User ์‚ญ์ œ
DROP ROLE test;

์ œ๋Œ€๋กœ ๋งŒ๋“ค์–ด์กŒ๋Š”์ง€ \du ๋กœ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
์ฒ˜์Œ ๋งŒ๋“ค์–ด์ง„ ์œ ์ €์—๋Š” ๊ถŒํ•œ์ด ์•„๋ฌด๊ฒƒ๋„ ์„ค์ • ๋˜์–ด์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๊ถŒํ•œ์ธ CREATEDB; ๋ฅผ ๋ถ€์—ฌํ•ด๋ณผ๊นŒ์š”?

ALTER USER (User_name) (์ค„ ๊ถŒํ•œ);

ALTER USER test CREATEDB;

ํ™•์ธํ•ด ๋ด…์‹œ๋‹ค. \du

๐Ÿ•น DB ์ƒ์„ฑํ•˜๊ธฐ!

# DB ์ƒ์„ฑํ•˜๊ธฐ
CREATE DATABASE (DB_NAME) WITH OWNER (USER_NAME) ENCODING 'UTF8';

# DB ์‚ญ์ œํ•˜๊ธฐ
DROP DATABASE (DB_NAME);

# DB์— ์œ ์ €์˜ ๋ชจ๋“  ๊ถŒํ•œ ๋ถ€์—ฌํ•˜๊ธฐ
GRANT ALL PRIVILEGES ON DATABASE (DB_NAME) TO (USER_NAME);

ํ™•์ธ์€ \l๋กœ ํ™•์ธํ•ด๋ด…์‹œ๋‹ค.

๐Ÿค” ์ ‘์†์€ ์ž˜๋˜๋Š”๋ฐ, ํŒจ์Šค์›Œ๋“œ ์ž…๋ ฅ์„ ๋ฐ›์ง€์•Š๋Š”๋‹ค?

Step.1

๋จผ์ € ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค.

# User ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ
ALTER USER (USER_NAME) WITH PASSWORD '(USER_PASSWORD)';

Step.2

์šฐ์„  pg_hba.conf ํŒŒ์ผ์ด ์–ด๋””์žˆ๋Š”์ง€ ์ฐพ์•„์•ผํ•œ๋‹ค. ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์–ด๋””์— ์žˆ๋Š”์ง€ ์•Œ๋ ค์ค€๋‹ค.

postgres=# show data_directory;

Step.3

์œ„ ๊ฒฝ๋กœ๋ฅผ ์ฐพ์•„๋“ค์–ด๊ฐ€๋ฉด, pg_hba.conf ํŒŒ์ผ์ด ์กด์žฌํ•œ๋‹ค. ์ด๋ฅผ ์—ด๋ฉด ์•„๋ž˜์™€ ๋นจ๊ฐ„ ํ‘œ์‹œ๋ถ€๋ถ„์ด "trust"๋กœ ๋˜์–ด์žˆ๋‹ค. ์ด๋ฅผ md5๋กœ ์ˆ˜์ •ํ•ด์ฃผ๊ณ  ์ €์žฅ ํ›„ ๋‚˜๊ฐ„๋‹ค.

vim pg_hba.conf

Step.4

์ด์ œ PostgreSQL ์„ ์ข…๋ฃŒํ–ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ๋ถ€ํŒ…ํ•ฉ๋‹ˆ๋‹ค.

$ > brew services stop postgresql

$ > brew services start postgresql

๋‹ค์‹œ ์ ‘์†ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์ฐฝ์ด ๋ณด์ด๊ณ , ์œ„์—์„œ ์ง€์ •ํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์ ‘๊ทผ์ด๋œ๋‹ค.

profile
ํฌ๊ธฐํ•˜๋Š” ๊ทธ ์ˆœ๊ฐ„์ด ๋ฐ”๋กœ ์‹œํ•ฉ์ข…๋ฃŒ์˜ˆ์š”...

0๊ฐœ์˜ ๋Œ“๊ธ€