docs: add robeing instance database separation troubleshooting guide
- Document rb8001 and rb10508_test DB separation process - Include server infrastructure setup and code modifications - Explain design decisions for ChromaDB and log storage - Add scalability considerations and future directions
This commit is contained in:
parent
f1b7b0c1d5
commit
e07acf9d73
146
docs/troubleshooting/20250716_robeing_db_separation.md
Normal file
146
docs/troubleshooting/20250716_robeing_db_separation.md
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
# 로빙 인스턴스 DB 분리 작업
|
||||||
|
|
||||||
|
**날짜**: 2025-07-16
|
||||||
|
**작업자**: Claude & happybell
|
||||||
|
|
||||||
|
## 개요
|
||||||
|
|
||||||
|
rb8001과 rb10508_test 두 로빙 인스턴스가 동일한 DB를 공유하는 문제를 해결하기 위해 각각 독립된 DB와 스토리지를 갖도록 분리
|
||||||
|
|
||||||
|
## 문제 상황
|
||||||
|
|
||||||
|
### 초기 상태
|
||||||
|
- 두 로빙이 동일한 PostgreSQL DB 사용 (robing_metrics)
|
||||||
|
- ChromaDB 컬렉션명 충돌 (conversations, documents, insights)
|
||||||
|
- 로그 파일 구분 없음
|
||||||
|
|
||||||
|
### 요구사항
|
||||||
|
- 각 로빙은 독립된 존재로 별도 데이터 관리 필요
|
||||||
|
- 확장성 고려 (향후 100개 이상의 로빙 운영 가능성)
|
||||||
|
- 서버 환경변수 관리 최소화
|
||||||
|
|
||||||
|
## 해결 과정
|
||||||
|
|
||||||
|
### 1. 서버 인프라 준비 (admin 계정)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# PostgreSQL DB 생성
|
||||||
|
sudo -u postgres psql
|
||||||
|
CREATE DATABASE rb8001_db;
|
||||||
|
CREATE DATABASE rb10508_test_db;
|
||||||
|
\q
|
||||||
|
|
||||||
|
# 디렉토리 구조 설정
|
||||||
|
# rb8001은 기존 logs 유지, logs_hdd 심링크 추가
|
||||||
|
ln -s /mnt/hdd/robeing-logs/rb8001 /home/admin/rb8001/logs_hdd
|
||||||
|
|
||||||
|
# rb10508_test는 처음부터 HDD 사용
|
||||||
|
mkdir -p /mnt/hdd/robeing-logs/rb10508_test
|
||||||
|
chown -R 999:docker /mnt/hdd/robeing-logs/rb10508_test
|
||||||
|
ln -s /mnt/hdd/robeing-logs/rb10508_test /home/admin/rb10508_test/logs
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 코드 수정
|
||||||
|
|
||||||
|
#### config.py - ROBING_ID 기반 설정
|
||||||
|
```python
|
||||||
|
class Settings(BaseSettings):
|
||||||
|
# Robeing Configuration
|
||||||
|
ROBING_ID: str = "rb8001" # 또는 "rb10508_test"
|
||||||
|
|
||||||
|
# Database Configuration
|
||||||
|
DATABASE_URL: str = f"postgresql://postgres:postgres@localhost/{ROBING_ID}_db"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### chroma_service.py - 기존 경로 유지
|
||||||
|
```python
|
||||||
|
# 물리적 분리는 Docker 볼륨으로 해결
|
||||||
|
self.client = chromadb.PersistentClient(
|
||||||
|
path="/code/chroma_db", # 경로는 동일
|
||||||
|
# ...
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### main.py - 로그 파일명에 ROBING_ID 포함
|
||||||
|
```python
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
handlers=[
|
||||||
|
logging.StreamHandler(),
|
||||||
|
logging.FileHandler(f"/code/logs/{settings.ROBING_ID}_app.log")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Docker 설정
|
||||||
|
|
||||||
|
#### docker-compose.yml - 볼륨 설정
|
||||||
|
```yaml
|
||||||
|
volumes:
|
||||||
|
# 각 로빙별 디렉토리가 물리적으로 분리됨
|
||||||
|
- ./chroma_db:/code/chroma_db
|
||||||
|
- ./logs_hdd:/code/logs # rb8001
|
||||||
|
# 또는
|
||||||
|
- ./logs:/code/logs # rb10508_test (심링크)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 핵심 설계 결정
|
||||||
|
|
||||||
|
### 1. ChromaDB 분리 방식
|
||||||
|
- **초기 고려안**: 컬렉션명에 ROBING_ID 포함 (`rb8001_conversations`)
|
||||||
|
- **최종 결정**: 디렉토리 분리로 해결
|
||||||
|
- **이유**: 코드 수정 최소화, 기존 데이터 유지, 마이그레이션 불필요
|
||||||
|
|
||||||
|
### 2. 로그 저장 위치
|
||||||
|
- **SSD vs HDD**: HDD 선택 (로그는 쓰기 작업이 많아 SSD 수명 영향)
|
||||||
|
- **중앙화 관리**: `/mnt/hdd/robeing-logs/` 아래 로빙별 디렉토리
|
||||||
|
- **호환성 유지**: rb8001은 기존 logs 디렉토리 유지, logs_hdd 추가
|
||||||
|
|
||||||
|
### 3. 확장성 고려
|
||||||
|
- **현재**: 각 로빙마다 별도 레포지토리
|
||||||
|
- **문제점**: 100개 로빙 = 100개 레포 = 관리 지옥
|
||||||
|
- **향후 방향**: 로빙 관리 시스템 필요 (메타 로빙)
|
||||||
|
|
||||||
|
## 교훈
|
||||||
|
|
||||||
|
### 1. 기존 인프라 활용
|
||||||
|
- 서버에 이미 구축된 환경 최대한 활용
|
||||||
|
- 코드보다 설정으로 해결 가능한 부분 우선
|
||||||
|
|
||||||
|
### 2. 단순함 유지
|
||||||
|
- 환경변수 관리 복잡도 최소화
|
||||||
|
- 하드코딩이 때로는 더 명확한 해결책
|
||||||
|
|
||||||
|
### 3. 물리적 분리 vs 논리적 분리
|
||||||
|
- DB: 논리적 분리 (스키마/데이터베이스명)
|
||||||
|
- 파일: 물리적 분리 (디렉토리/볼륨)
|
||||||
|
|
||||||
|
## 참고사항
|
||||||
|
|
||||||
|
### 서버 디렉토리 구조
|
||||||
|
```
|
||||||
|
/home/admin/
|
||||||
|
├── rb8001/
|
||||||
|
│ ├── chroma_db/ (SSD)
|
||||||
|
│ ├── logs/ (SSD, 기존)
|
||||||
|
│ └── logs_hdd@ (심링크 → HDD)
|
||||||
|
└── rb10508_test/
|
||||||
|
├── chroma_db/ (SSD)
|
||||||
|
└── logs@ (심링크 → HDD)
|
||||||
|
|
||||||
|
/mnt/hdd/robeing-logs/
|
||||||
|
├── rb8001/
|
||||||
|
└── rb10508_test/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Git 작업 규칙 준수
|
||||||
|
- 코드 수정 전 `git fetch` → `git status` 확인 필수
|
||||||
|
- 원격 변경사항 확인 후 작업으로 충돌 예방
|
||||||
|
|
||||||
|
## 다음 단계
|
||||||
|
|
||||||
|
1. CI/CD 자동 배포 확인
|
||||||
|
2. 컨테이너 재시작 후 DB 연결 테스트
|
||||||
|
3. 로그 파일 생성 확인
|
||||||
|
4. 향후 로빙 관리 시스템 설계
|
||||||
Loading…
x
Reference in New Issue
Block a user