docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거

Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,133 @@
---
id: db-partitioning-patterns
title: Partitioning — Range / List / Hash
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [database, partitioning, postgres, vibe-coding]
tech_stack: { language: "SQL / Postgres", applicable_to: ["Backend"] }
applied_in: []
aliases: [partitioning, range partition, partition pruning, table inheritance]
---
# Table Partitioning
> 거대 테이블 (10M+ rows / 100GB+) 을 작은 파티션으로 분할. **인덱스 작아짐 + 오래된 파티션 통째 drop = 빠른 만료**. Postgres 11+ declarative partitioning.
## 📖 핵심 개념
- Range: 시간 / 숫자 범위 (events_2026_05).
- List: 카테고리 / 지역 (users_kr, users_us).
- Hash: 균일 분산 (write 부하 분산).
- Pruning: WHERE 조건이 파티션 키와 맞으면 다른 파티션 skip.
## 💻 코드 패턴
### Range partition (시간)
```sql
CREATE TABLE events (
id BIGSERIAL,
user_id UUID,
event_type TEXT,
created_at TIMESTAMPTZ NOT NULL,
PRIMARY KEY (id, created_at)
) PARTITION BY RANGE (created_at);
CREATE TABLE events_2026_04 PARTITION OF events
FOR VALUES FROM ('2026-04-01') TO ('2026-05-01');
CREATE TABLE events_2026_05 PARTITION OF events
FOR VALUES FROM ('2026-05-01') TO ('2026-06-01');
-- default (필수: 안 맞는 row 의 안전망)
CREATE TABLE events_default PARTITION OF events DEFAULT;
```
### Pruning 확인
```sql
EXPLAIN SELECT * FROM events WHERE created_at >= '2026-05-01' AND created_at < '2026-05-10';
-- "Append" 안에 events_2026_05 만 보여야. default 도 안 보여야.
```
### 자동 파티션 생성 (pg_partman)
```sql
SELECT partman.create_parent(
p_parent_table => 'public.events',
p_control => 'created_at',
p_type => 'native',
p_interval => 'monthly',
p_premake => 3 -- 3개월 미리 생성
);
```
### 오래된 파티션 drop = 빠른 만료
```sql
-- 1년 지난 events 삭제 = DELETE 가 아니라 DROP
DROP TABLE events_2025_05;
-- vacuum 부담 X, 즉시.
```
### List partition
```sql
CREATE TABLE orders (
id UUID,
region TEXT NOT NULL,
...
) PARTITION BY LIST (region);
CREATE TABLE orders_kr PARTITION OF orders FOR VALUES IN ('KR');
CREATE TABLE orders_us PARTITION OF orders FOR VALUES IN ('US');
CREATE TABLE orders_other PARTITION OF orders DEFAULT;
```
### Hash partition (write 분산)
```sql
CREATE TABLE accounts (...) PARTITION BY HASH (id);
CREATE TABLE accounts_p0 PARTITION OF accounts FOR VALUES WITH (modulus 4, remainder 0);
CREATE TABLE accounts_p1 PARTITION OF accounts FOR VALUES WITH (modulus 4, remainder 1);
CREATE TABLE accounts_p2 PARTITION OF accounts FOR VALUES WITH (modulus 4, remainder 2);
CREATE TABLE accounts_p3 PARTITION OF accounts FOR VALUES WITH (modulus 4, remainder 3);
```
### 인덱스 — 자동으로 각 파티션에
```sql
CREATE INDEX events_user ON events (user_id);
-- Postgres 11+ : 자동으로 모든 파티션에 적용
```
### Constraint exclusion 확인
```sql
SET enable_partition_pruning = on;
EXPLAIN ANALYZE SELECT count(*) FROM events WHERE user_id = $1 AND created_at >= '2026-05-01';
```
## 🤔 의사결정 기준
| 상황 | 파티션 종류 |
|---|---|
| 시계열 (이벤트, 로그, 메트릭) | Range (날짜) |
| 다국가 / 다지역 | List (region) |
| 단일 큰 테이블 균등 write | Hash |
| TTL / 자동 만료 | Range + drop old partitions |
| 멀티테넌트 큰 차이 | List (tenant_id) |
| 천만 미만 | 파티션 X — 인덱스로 충분 |
## ❌ 안티패턴
- **PK 가 파티션 키 안 포함**: 못 함 — PK 에 partition column 포함 (composite PK).
- **Default 파티션 누락**: 범위 밖 INSERT 실패.
- **모든 파티션 동시 query**: pruning 안 됨 — WHERE 에 partition column 포함.
- **Cross-partition unique constraint**: 안 됨. 앱 레벨에서.
- **파티션 너무 많음 (1000+)**: planner 오버헤드. 적당히 (<100).
- **Partition pruning 환경 검사 안 함**: 잘못 만들면 아무 효과 X.
- **수동 파티션 생성 잊음**: pg_partman 또는 cron.
## 🤖 LLM 활용 힌트
- Postgres 11+ declarative partitioning 우선.
- Range + 자동 생성 (pg_partman) + drop 으로 만료.
- WHERE 에 partition column 항상.
## 🔗 관련 문서
- [[DB_Sharding_Strategies]]
- [[DB_Soft_Delete_Patterns]]