Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/myeonghan-nim/database-partitioning

πŸ“– Study: database partitioning
https://github.com/myeonghan-nim/database-partitioning

django partitioning python

Last synced: 26 days ago
JSON representation

πŸ“– Study: database partitioning

Awesome Lists containing this project

README

        

# database partitioning

## νŒŒν‹°μ…”λ‹

ν…Œμ΄λΈ”μ˜ 데이터λ₯Ό 일정 기쀀에 따라 λ‚˜λˆ„λŠ” κΈ°λ²•μœΌλ‘œ μ„±λŠ₯ ν–₯상과 관리 νŽΈμ˜μ„± μ¦λŒ€κ°€ κ°€λŠ₯, μ‹œκ°„(λ‚ μ§œ) λ˜λŠ” μš©λŸ‰μ— 따라 μžλ™μœΌλ‘œ ν…Œμ΄λΈ”μ„ λ‚˜λˆ„λŠ” 방법이 일반적

### μ˜ˆμ‹œ

> postgresql

```sql
CREATE TABLE user_activity (
user_id INT,
action TEXT,
created_at TIMESTAMP NOT NULL
) PARTITION BY RANGE (created_at);

-- 2024λ…„ 1μ›” 데이터λ₯Ό μœ„ν•œ νŒŒν‹°μ…˜
CREATE TABLE user_activity_2024_01 PARTITION OF user_activity
FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');

-- 2024λ…„ 2μ›” 데이터λ₯Ό μœ„ν•œ νŒŒν‹°μ…˜
CREATE TABLE user_activity_2024_02 PARTITION OF user_activity
FOR VALUES FROM ('2024-02-01') TO ('2024-03-01');
```

μœ„μ™€ 같이 postgresql에 **Range Partitioning**을 μ‚¬μš©ν•˜μ—¬ νŒŒν‹°μ…”λ‹μ΄ κ°€λŠ₯

> django

```python
# models.py
from django.db import models

class UserActivity(models.Model):
user_id = models.IntegerField()
action = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
# κΈ°λ³Έ ν…Œμ΄λΈ”μ€ μ—¬μ „νžˆ μ‘΄μž¬ν•˜μ§€λ§Œ, νŒŒν‹°μ…˜ ν…Œμ΄λΈ”μ—μ„œ μ‹€μ œ 데이터λ₯Ό μ²˜λ¦¬ν•¨
db_table = 'user_activity'
```

μœ„μ™€ 같이 μž‘μ„±ν•˜λ©΄ djangoμ—μ„œ 보낸 데이터가 postgresqlμ—μ„œ μžλ™μœΌλ‘œ 처리