DB ์ฌ์ฉํ๋ค ๋ณด๋ฉด ํด๋ผ์ฐ๋๋ ๋ค๋ฅธ ์๋ฒ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐฑ์ (๋คํ)ํ๊ณ ,
์ด๋ฅผ ๋ก์ปฌ ํ๊ฒฝ์ผ๋ก ๋ณต์ํด์ผ ํ ์ผ์ด ์์ฃผ ์๊น๋๋ค.
์ด ๊ธ์์๋ pg_dump๋ก ๋ฐฑ์ ์ ๋ง๋ค๊ณ , pg_restore๋ฅผ ์ด์ฉํด ๋ก์ปฌ DB·ํน์ ์คํค๋ง์ ๋ณต์ํ๋ ์ ์ฒด ๊ณผ์ ์ ์ ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค.
1. pg_dump๋ก DB ๋ฐฑ์ (dump) ๋ง๋ค๊ธฐ
๋ฐฑ์
(dump) ์์ฑ์ PostgreSQL์ pg_dump๋ฅผ ์ด์ฉํฉ๋๋ค.
Custom format(-F c)์ผ๋ก ๋ฐฑ์
ํ๋ฉด ๋์ค์ pg_restore๋ก ์คํค๋ง ๋จ์ ๋ณต์์ด ๊ฐ๋ฅํฉ๋๋ค.
์์ ๋ช ๋ น
pg_dump -h {host} -U {user} -d {database} -F c -f "๊ฒฝ๋ก\ํ์ผ๋ช
.dump"
์ต์ ์ค๋ช
| ์ต์ | ์ค๋ช |
| -h | ์ ์ํ ์๋ฒ ์ฃผ์. Render ๋ฑ ์ธ๋ถ ์๋ฒ์ผ ๊ฒฝ์ฐ ์ธ๋ถ ํธ์คํธ, ๋ก์ปฌ์ localhost |
| -U | PostgreSQL ์ฌ์ฉ์๋ช |
| -d | ๋ฐฑ์ ํ DB ์ด๋ฆ |
| -F c | Custom format (pg_restore๋ก ๋ณต์ ๊ฐ๋ฅ) |
| -f | ์ถ๋ ฅ ํ์ผ ๊ฒฝ๋ก |
2. localhost ํ์ธ (๋ก์ปฌ PostgreSQL ์๋ฒ ๋ชฉ๋ก ํ์ธ)
๋ก์ปฌ DB์ ๋ณต์ํ๊ธฐ ์ ์, ๋ด PC์์ ์ด๋ค DB๊ฐ ์กด์ฌํ๋์ง ํ์ธํด ๋ณด๊ฒ ์ต๋๋ค.
์ด ๋ช
๋ น์ **CMD(๋ช
๋ น ํ๋กฌํํธ)**์์ ์คํํด์ผ ํฉ๋๋ค.
psql -h localhost -U postgres -l
๋๋ถ๋ถ ์ค์น ์งํ์๋ ์๋ 3๊ฐ๊ฐ ๋ณด์ ๋๋ค.
| DB ์ด๋ฆ | ์ค๋ช |
| postgres | ๊ธฐ๋ณธ DB (์ฐ๋ฆฌ๊ฐ ์ฃผ๋ก ๋ณต์ํ๊ฒ ๋๋ DB) |
| template0 | ์์คํ ํ ํ๋ฆฟ DB |
| template1 | ์๋ก์ด DB ์์ฑ ์ ๊ธฐ๋ณธ ํ ํ๋ฆฟ |
์ฆ, ๋ก์ปฌ์์ ์ฐ๋ฆฌ๊ฐ ์ฌ์ฉํ DB๋ ๋๋ถ๋ถ postgres DB์ ๋๋ค.
3. pg_restore๋ฅผ ์ด์ฉํ ๋ก์ปฌ DB ๋ณต์
3-1. ํน์ ์คํค๋ง(abc)์ ๋ณต์
์ด๋ฏธ ๋ก์ปฌ DB(postgres)์ abc์คํค๋ง๊ฐ ์กด์ฌํ๋ค๊ณ ๊ฐ์ ํ๋ฉด:
pg_restore -h localhost -U postgres -d postgres -n abc "C:\๊ฒฝ๋ก\ํ์ผ.dump"
์ต์ ์ค๋ช
| ์ต์ | ์ค๋ช |
| -d postgres | ๋ก์ปฌ์ postgres DB์ ๋ณต์ |
| -n split | split ์คํค๋ง์๋ง ๋ณต์ |
| "ํ์ผ.dump" | ๋ฐฑ์ ๋ณธ ํ์ผ ๊ฒฝ๋ก |
์ฃผ์
dump ์์ ์๋ณธ ์คํค๋ง๊ฐ public์ด๋ฉด abc๋ก ๋ค์ด๊ฐ์ง ์์ ์๋ ์๋ค. ๊ทธ๋ด ๋ ์๋ ์ต์ ์ฌ์ฉํด์ผ ํ๋ค.
pg_restore -h localhost -U postgres -d postgres -N public --schema=abc "C:\๊ฒฝ๋ก\ํ์ผ.dump"
4. ๋ณต์ ๊ฒฐ๊ณผ ํ์ธ
๋ณต์ ํ ์๋ ๋ช ๋ น์ผ๋ก ํ ์ด๋ธ์ด ์ ์์ ์ผ๋ก ๋ค์ด์๋์ง ํ์ธํ ์ ์๋ค.
์คํค๋ง์ ํ ์ด๋ธ ๋ชฉ๋ก ๋ณด๊ธฐ
\dt abc.*
5. ์ ๋ฆฌ
- pg_dump → DB ์ ์ฒด๋ฅผ ๋ฐฑ์ ํ๋ ๋๊ตฌ
- pg_restore → Custom format dump๋ฅผ ๋ณต์ํ๋ ๋๊ตฌ
- ๋ก์ปฌ ๋ณต์ ์ -h localhost๋ฅผ ์ฌ์ฉํ๋ฉด ๋ด PC์๋ง ๋ณต์๋๋ฏ๋ก ๋ค๋ฅธ ์๋ฒ์ ์ํฅ์ ์ฃผ์ง ์๋๋ค
- dump ์์ฑ ์ ์๋ณธ ์คํค๋ง ๊ตฌ์กฐ์ ๋ฐ๋ผ ๋ณต์ํ ์คํค๋ง ์ต์ ์ด ๋ค๋ฅผ ์ ์๋ค
- pgAdmin์ SQL ์ฐฝ์์๋ pg_restore๊ฐ ๋์ํ์ง ์์ → ๋ฐ๋์ CMD์์ ์คํํด์ผ ํจ
'๐๏ธ ๋ฐฑ์๋ > ๐๏ธDB' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| # org.postgresql.util.PSQLException: The authentication type 10 is not supported DB ์ธ์ฆ๋ฐฉ์ ์๋ฌ ํด๊ฒฐ๋ฐฉ๋ฒ (2) | 2025.07.08 |
|---|---|
| # PostgreSQL ๋ฝ(blocking) ์ํฉ ์ ๋ฆฌ ํด๊ฒฐ๋ฐฉ๋ฒ (1) | 2025.07.01 |
| # DB multipolygon ์์น ์กฐ์ ํ๊ธฐ (0) | 2025.04.07 |
| # JOIN (0) | 2025.03.06 |
| dbeaver(๋๋น๋ฒ) auto commit ํด์ (0) | 2025.02.19 |