๐Ÿงฉ

004 PostgreSQL

ย 
ย 
์ด๋ฒˆ์—๋Š” PostgreSQL์„ ํ„ฐ๋ฏธ๋„์—์„œ ์„ธํŒ…ํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ, ์œ ์ €๊ถŒํ•œ ๋ฐ ์†Œ์œ ๊ถŒ ๋ณ€๊ฒฝ, Django์— ์—ฐ๊ฒฐ์„ ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ๋‚ด์šฉ์„ ๋”ฐ๋ผ ํ•˜์‹œ๋‹ค๊ฐ€ ์–ด๋ ค์šฐ์‹œ๋ฉด PostgreSQL ์ ์šฉ์€ ๋‚˜์ค‘์— ํ•˜์‹œ๋Š” ๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์šฐ์„  Django์˜ ๊ตฌ์กฐ๊ฐ€ ์ต์ˆ™ํ•ด์ง€์‹  ํ›„์— ์ ์šฉํ•˜์…”๋„ ์•„๋ฌด ๋ฌธ์ œ ์—†์Šต๋‹ˆ๋‹ค.
ย 

1. PostgreSQL ์ด๋ž€?

PostgreSQL์€ ๊ต‰์žฅํžˆ ๊ฐ๊ด‘๋ฐ›๊ณ  ์žˆ๋Š” DB ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
notion imagenotion image
notion imagenotion image
ย 
ย 
๋ฌธ์ œ๋Š” PostgreSQL์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํ„ฐ๋ฏธ๋„์—์„œ ์ž‘์—…์„ ๋งŽ์ด ํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ์•ž์—์„œ Django ์„ธํŒ…ํ•˜๋Š” ๋ถ€๋ถ„์„ ์ง„ํ–‰ํ–ˆ๋Š”๋ฐ ํ„ฐ๋ฏธ๋„ ์„ธํŒ…ํ•˜๋Š” ๋ถ€๋ถ„์ด ๊ต‰์žฅํžˆ ์–ด๋ ค์› ๋˜ ๋ถ„์€ ์ด ๋ถ€๋ถ„์€ ํŒจ์Šคํ•˜์…”๋„ ์ƒ๊ด€์—†์Šต๋‹ˆ๋‹ค. ํŒจ์Šคํ•˜์‹œ๋Š” ๋ถ„๋“ค์€ ๋‚˜์ค‘์— ์›ํ•˜์‹ค ๋•Œ ๋ฐฐ์šฐ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
ย 

1. PostgreSQL ์„ค์น˜

์šฐ์„ , ํ„ฐ๋ฏธ๋„๋กœ ์‹คํ–‰์„ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
ย 
notion imagenotion image
ย 
apt-get์„ ์—…๋ฐ์ดํŠธํ•ด์ค๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone# apt-get update
ย 
notion imagenotion image
ย 
apt-get์„ ์ด์šฉํ•ด postgreSQL์„ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone# apt-get install postgresql Y
ย 
notion imagenotion image
ย 
notion imagenotion image
ย 

2. PostgreSQL ์‚ฌ์šฉํ•˜๊ธฐ

1. PostrgeSQL ์‹คํ–‰

PostgreSQL ์‹คํ–‰์‹œํ‚ค๊ฒ ์Šต๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone# service postgresql start
ย 
notion imagenotion image
ย 
PostgreSQL์ด ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone# ps -ef|grep postgres
ย 
notion imagenotion image
ย 
PostgreSQL์€ ์„ค์น˜๊ฐ€ ๋˜๋ฉด์„œ, ์Šˆํผ ์œ ์ €๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์ƒ์„ฑ๋œ ์Šˆํผ์œ ์ €๋กœ ์ ‘์†์„ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone# su - postgres
ย 
notion imagenotion image
ย 
psql์ด๋ผ ์ž…๋ ฅํ•˜๊ณ  ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์•ˆ์œผ๋กœ ๋“ค์–ด๊ฐ€๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 

2. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํ•œ ๋ฒˆ ์ƒ์„ฑํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. instaclone์ด๋ผ๋Š” ์ด๋ฆ„์˜ database๋ฅผ ๋งŒ๋“œ๋Š” ๋ช…๋ น์ž…๋‹ˆ๋‹ค. ;(์„ธ๋ฏธ์ฝœ๋ก )์„ ๋น ํŠธ๋ฆฌ๋ฉด ์•ˆ ๋ฉ๋‹ˆ๋‹ค.
create database instaclone;
ย 
notion imagenotion image
ย 
CREATE DATABASE ๋ผ๊ณ  ์ถœ๋ ฅ๋˜๋ฉด ์„ฑ๊ณต์ ์œผ๋กœ database๊ฐ€ ๋งŒ๋“ค์–ด ์ง„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์ž˜ ์ƒ์„ฑ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
\l
ย 
instaclone database๊ฐ€ ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 

3. ์œ ์ € ์ƒ์„ฑ ๋ฐ ์„ค์ •

์•ž์œผ๋กœ ๊ณ„์† ์Šˆํผ์œ ์ €๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋Š” ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ€์ง„ ์œ ์ €๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
ย 
๋จผ์ € ์ด๋ฆ„๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ง„ ์œ ์ €๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
create user username with password '12341234';
์œ ์ € ์ด๋ฆ„์€ username์ด๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” '12341234' ์ธ ์œ ์ €๋ฅผ ๋งŒ๋“ค๊ฒ ๋‹ค๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.
username๊ณผ password๋Š” ๋ณธ์ธ์ด ์ •ํ•ฉ๋‹ˆ๋‹ค.
ย 
CREATE ROLE ์ด ์ถœ๋ ฅ๋˜๋ฉด์„œ ๋ช…๋ น์ด ์ˆ˜ํ–‰๋˜์—ˆ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
๋ช‡ ๊ฐ€์ง€ ์„ค์ •์„ ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
  1. ์œ ์ €์˜ ์ธ์ฝ”๋”ฉ์„ utf-8๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    1. alter role username set client_encoding to 'utf-8';
      ย 
      notion imagenotion image
      ย 
  1. ์œ ์ €์˜ ์‹œ๊ฐ„์„ ์„œ์šธ ๊ธฐ์ค€์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    1. alter role username set timezone to 'Asia/Seoul';
      ย 
      notion imagenotion image
      ย 
  1. instaclone ์ด๋ผ๋Š” database์˜ ๊ถŒํ•œ์„ username์—๊ฒŒ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.
    1. grant all privileges on database instaclone to username;
      ย 
      notion imagenotion image
ย 
\l ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋ฐ”๋€ ์„ค์ •์„ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.
notion imagenotion image
ย 
Access privileges ์ ‘๊ทผ ๊ถŒํ•œ์— username์ด ์ถ”๊ฐ€๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
instaclone ์œ ์ €๋กœ์„œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ€์ง€๊ฒŒ ๋˜์—ˆ์ง€๋งŒ, Owner๊ฐ€ postgres๋กœ ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— username์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†์„ ํ•  ๋•Œ ๋กœ๊ทธ์ธ์ด ์•ˆ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ username๋ฅผ ์˜ค๋„ˆ๋กœ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
ย 
instaclone ์ด๋ผ๋Š” DATABASE์˜ OWNER๋ฅผ username์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.
ALTER DATABASE instaclone OWNER TO username;
ย 
notion imagenotion image
ย 
์ด์ œ instagram ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ Owner๊ฐ€ username์œผ๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 

4. ํด๋ผ์ด์–ธํŠธ ์ธ์ฆ ํŒŒ์ผ ์ˆ˜์ •

ํด๋ผ์ด์–ธํŠธ ์ธ์ฆ์— ๊ด€ํ•œ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ˆ˜์ •ํ•  ํŒŒ์ผ์€ pg_hba.conf ๋ผ๋Š” ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
ย 
๋จผ์ €, ํŒŒ์ผ์ด ์–ด๋”” ์žˆ๋Š”์ง€ ํ™•์ธํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
show hba_file;
ย 
pg_hba.conf ์˜ ๊ฒฝ๋กœ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
ํ•ด๋‹น ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์„ vim ์—๋””ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํŒŒ์ผ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
\q ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋น ์ ธ๋‚˜์˜ค๊ฒ ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
์ด์™€ ๊ฐ™์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๋น ์ ธ๋‚˜์˜จ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ exit ๋ช…๋ น์–ด๋ฅผ ์น˜๋ฉด postgreSQL์„ ์™„์ „ํžˆ ์ข…๋ฃŒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
์•„๊นŒ ํ•ด๋‹น ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์„ vim ์—๋””ํ„ฐ๋กœ ์—ฝ๋‹ˆ๋‹ค. ์•„๊นŒ ๊ฒฝ๋กœ๋ฅผ ํ™•์ธํ–ˆ๋˜ ๊ฒƒ์„ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ฒฝ๋กœ๋Š” ๋ฒ„์ „๋งˆ๋‹ค ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ํ•ด ์ฃผ์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# vim /etc/postgresql/10/main/pg_hba.conf
ย 
notion imagenotion image
ย 
๋ฐฉํ–ฅํ‚ค๋กœ ์ˆ˜์ •ํ•  ์œ„์น˜๋ฅผ ์ฐพ์•„๊ฐ€๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ „์— ์ค„ ๋ฒˆํ˜ธ๋ฅผ ํ‘œ์‹œํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ผ๋‹จ :(์ฝœ๋ก )์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
notion imagenotion image
ย 
:(์ฝœ๋ก )์„ ์ž…๋ ฅํ•˜๋ฉด ํ™”๋ฉด ํ•˜๋‹จ์— : ์ด ์ƒ๊น๋‹ˆ๋‹ค. Vim์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ์ƒํƒœ๊ฐ€ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ set number ๋˜๋Š” ์ค„์—ฌ์„œ set nu์„ ์ž…๋ ฅํ•˜๊ณ  Enter๋ฅผ ์ณ๋ด…๋‹ˆ๋‹ค.
:set number :set nu
ย 
notion imagenotion image
ย 
๊ทธ๋Ÿฌ๋ฉด ์ค„ ๋ฒˆํ˜ธ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์ด์ œ ๋ฐฉํ–ฅํ‚ค๋กœ ํŒŒ์ผ ๋‚ด์šฉ์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฐฉํ–ฅํ‚ค๋กœ ์ปค์„œ ์œ„์น˜๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ๋ถ€๋ถ„์— Unix domain socket connections only ๋ผ๋Š” ๋ถ€๋ถ„์ด ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
์—ฌ๊ธฐ์— METHOD๊ฐ€ peer๋กœ ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์„ ์•„๋ž˜ ํ•ญ๋ชฉ๊ณผ ๊ฐ™์ด md5๋กœ ๋ฐ”๊ฟ€ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
notion imagenotion image
ย 
vim ์—์„œ ์ˆ˜์ •๋ชจ๋“œ๋กœ ๋“ค์–ด๊ฐ€๊ธฐ ์œ„ํ•ด์„œ๋Š” i(insert) ๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค. (ํ•œ์˜ํ‚ค ํ™•์ธํ•ด์ฃผ์…”์•ผ ๋ฉ๋‹ˆ๋‹ค.)
i ๋ฅผ ๋ˆ„๋ฅด๋ฉด ํ™”๋ฉด ํ•˜๋‹จ์— โ€” ๋ผ์›Œ๋„ฃ๊ธฐ โ€” ๋ผ๊ณ  ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.
notion imagenotion image
ย 
์ปค์„œ๋ฅผ peer ๋กœ ์˜ฎ๊ฒจ์„œ Delete ํ‚ค๋กœ ์ง€์šฐ๊ณ  m๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
notion imagenotion image
ย 
esc ๋ฅผ ๋ˆŒ๋Ÿฌ์„œ ๋ผ์›Œ ๋„ฃ๊ธฐ ๋ชจ๋“œ์—์„œ ๋น ์ ธ๋‚˜์˜ต๋‹ˆ๋‹ค.
ย 
๋งˆ์ง€๋ง‰์œผ๋กœ ํŒŒ์ผ์„ ์ €์žฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. :(์ฝœ๋ก )์„ ๋ˆ„๋ฅด๊ณ  wq ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
:wq
wq๋Š” ์ €์žฅ(write)ํ•˜๊ณ  ๋‚˜๊ฐ„๋‹ค(quit)๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. ํŒŒ์ผ์„ ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜์ •ํ•˜๊ณ  ๋‚˜์™”์Šต๋‹ˆ๋‹ค.
ย 
notion imagenotion image
ย 
๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ž˜ ์ ์šฉ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ์„œ๋ฒ„๋ฅผ ์žฌ์‹œ์ž‘ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# service postgresql restart
ย 
์ž…๋ ฅํ•˜๋ฉด, done์ด ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
username ์œ ์ €๋กœ ์ ‘์†ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ผ๋‹จ postgres๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# su - postgres
ย 
notion imagenotion image
ย 
postgres๊ฐ€ ์‹คํ–‰๋˜๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด username์œผ๋กœ instaclone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†์„ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.
psql -U username -d instaclone
ย 
๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ผ๊ณ  ๋‚˜์˜ต๋‹ˆ๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์•„๊นŒ user๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์„ค์ •ํ•œ ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค.
notion imagenotion image
ย 
๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด, ์„ฑ๊ณต์ ์œผ๋กœ ์œ ์ €๋กœ instaclone ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘์†ํ•œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ˜„์žฌ username ์œ ์ €๋กœ ์ ‘์†ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์•ˆ์—์„œ ํ•ด์•ผ ๋˜๋Š” ์„ธํŒ…์€ ์ „๋ถ€ ๋๋‚ฌ์Šต๋‹ˆ๋‹ค.
ย 

3. ์žฅ๊ณ ์— PostgreSQL ์—ฐ๊ฒฐ

Django ์•ˆ์— ์žˆ๋Š” settings.py ๋ฅผ ์ˆ˜์ •ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ตฌ๋ฆ„ IDE ์ปจํ…Œ์ด๋„ˆ๋กœ ๋Œ์•„๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค.
๋จผ์ €, ํ„ฐ๋ฏธ๋„์—์„œ ํ”„๋กœ์ ํŠธ ํด๋”๋กœ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# cd instaclone
ย 
์ด๋•Œ, (master) ๋ผ๋Š” ํ‘œ์‹œ๋Š” Git์ด ์ถ”์ ํ•˜๋Š” ํด๋”๋ผ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
notion imagenotion image
ย 
๊ฐ€์ƒ ํ™˜๊ฒฝ(venv)์„ ํ™œ์„ฑํ™” ํ•ฉ๋‹ˆ๋‹ค. ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ๊ด€๋ จ ์ž‘์—…์„ ํ•˜๊ธฐ ์ „์—๋Š” ํ•ญ์ƒ ๊ฐ€์ƒ ํ™˜๊ฒฝ์ด ํ™œ์„ฑํ™” ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ์Šต๊ด€์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# source venv/bin/activate
ย 
notion imagenotion image
ย 
config/settings.py ํŒŒ์ผ์„ ์—ด๊ฒ ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
notion imagenotion image
ย 
config/settings.py 76๋ฒˆ์งธ ์ค„์˜ DATABASES ๋ณ€์ˆ˜๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
notion imagenotion image
ย 
์ด ๋ถ€๋ถ„์€ Django์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ๊ด€๋ จ๋œ ๋‚ด์šฉ์„ ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ๋กœ ๋‹ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์‹œ default ๊ฐ’์œผ๋กœ SQLite3๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ์ ํ˜€์žˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š์œผ๋ฉด PostgreSQL์„ ์„ค์น˜ํ•ด๋„ Django๋Š” SQLite3๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
ย 
DATABASES์˜ 'default' ๋‚ด์šฉ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.
ย 
ํŒŒ์ผ๋ช… : config/settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'instaclone', 'USER': 'username', 'PASSWORD': '12341234', 'HOST': 'localhost', 'PORT': '', } }
ย 
์•ž์œผ๋กœ๋„ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ์ด ๋ถ€๋ถ„์—์„œ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Django๋Š” ๋‹ค์–‘ํ•œ DB๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ข‹์€ ํ™˜๊ฒฝ์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ถ”ํ›„์— ๋‹ค๋ฅธ DB๋„ ์‚ฌ์šฉํ•ด๋ณผ ๋•Œ๋„ ์ด ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•˜๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.
์ด์ œ migrateํ•˜๋ฉด Django๊ฐ€ PostgreSQL์— ๋งž๊ฒŒ ๋‚ด์šฉ์„ ๋ณ€๊ฒฝํ•ด์ค๋‹ˆ๋‹ค.
(venv)root@goorm:/workspace/instaclone/instaclone# python manage.py migrate
ย 
ํ•˜์ง€๋งŒ ์•„๋ž˜์™€ ๊ฐ™์ด psycopg2๋ผ๋Š” ๋ชจ๋“ˆ์ด ์—†๋‹ค๋Š” ์—๋Ÿฌ๊ฐ€ ํ‘œ์‹œ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
ย 
์ด ๊ฒฝ์šฐ pip๋ฅผ ์ด์šฉํ•ด psycopg2-binary๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
(venv)root@goorm:/workspace/instaclone/instaclone# pip install psycopg2-binary
ย 
notion imagenotion image
ย 
psycopg2-binary๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ์„ค์น˜ํ•œ ๋’ค, ๋‹ค์‹œ migrate๋ฅผ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.
(venv)root@goorm:/workspace/instaclone/instaclone# python manage.py migrate
ย 
notion imagenotion image
ย 
No module named 'imagekit' ๋ผ๊ณ  ์ถœ๋ ฅ๋  ๋•Œ, django-imagekit๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# pip install django-imagekit
ย 
No module named 'PIL' ๋ผ๊ณ  ์ถœ๋ ฅ๋  ๋•Œ, pillow๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
root@goorm:/workspace/instaclone/instaclone# pip install pillow
ย