Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/myeonghan-nim/database-partitioning
- Owner: myeonghan-nim
- Created: 2024-10-19T18:44:35.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-15T06:40:41.000Z (about 2 months ago)
- Last Synced: 2024-11-15T07:29:53.905Z (about 2 months ago)
- Topics: django, partitioning, python
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 modelsclass 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μμ μλμΌλ‘ μ²λ¦¬