Alle .md einmal aufgeräumt
Dieser Commit ist enthalten in:
@@ -1,77 +0,0 @@
|
||||
# License Heartbeats Partition Management
|
||||
|
||||
## Overview
|
||||
|
||||
The `license_heartbeats` table uses PostgreSQL partitioning to efficiently store and query time-series data. Each partition contains data for one month.
|
||||
|
||||
## Problem
|
||||
|
||||
The monitoring dashboard may fail with "relation does not exist" errors when:
|
||||
1. The current month's partition hasn't been created
|
||||
2. The license_heartbeats table hasn't been properly initialized
|
||||
|
||||
## Solution
|
||||
|
||||
### Automatic Partition Creation
|
||||
|
||||
The monitoring routes now automatically:
|
||||
1. Check if the `license_heartbeats` table exists
|
||||
2. Create missing partitions for the current month
|
||||
3. Handle missing table/partition gracefully by returning empty data
|
||||
|
||||
### Manual Partition Creation
|
||||
|
||||
If needed, you can manually create partitions:
|
||||
|
||||
1. **Using the migration script:**
|
||||
```bash
|
||||
docker exec -it v2_adminpanel python apply_partition_migration.py
|
||||
```
|
||||
|
||||
2. **Using SQL directly:**
|
||||
```sql
|
||||
-- Create June 2025 partition
|
||||
CREATE TABLE IF NOT EXISTS license_heartbeats_2025_06 PARTITION OF license_heartbeats
|
||||
FOR VALUES FROM ('2025-06-01') TO ('2025-07-01');
|
||||
```
|
||||
|
||||
### Partition Naming Convention
|
||||
|
||||
Partitions follow the naming pattern: `license_heartbeats_YYYY_MM`
|
||||
|
||||
Examples:
|
||||
- `license_heartbeats_2025_01` - January 2025
|
||||
- `license_heartbeats_2025_06` - June 2025
|
||||
- `license_heartbeats_2025_12` - December 2025
|
||||
|
||||
### Best Practices
|
||||
|
||||
1. **Pre-create partitions**: Create partitions for the next 6 months to avoid runtime issues
|
||||
2. **Monitor partition usage**: Check which partitions exist regularly
|
||||
3. **Archive old data**: Consider dropping very old partitions to save space
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
If you see "relation does not exist" errors:
|
||||
|
||||
1. Check if the base table exists:
|
||||
```sql
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM information_schema.tables
|
||||
WHERE table_name = 'license_heartbeats'
|
||||
);
|
||||
```
|
||||
|
||||
2. List existing partitions:
|
||||
```sql
|
||||
SELECT tablename FROM pg_tables
|
||||
WHERE tablename LIKE 'license_heartbeats_%'
|
||||
ORDER BY tablename;
|
||||
```
|
||||
|
||||
3. Create missing partition for current month:
|
||||
```sql
|
||||
-- Replace YYYY_MM with current year and month
|
||||
CREATE TABLE IF NOT EXISTS license_heartbeats_YYYY_MM PARTITION OF license_heartbeats
|
||||
FOR VALUES FROM ('YYYY-MM-01') TO ('YYYY-MM-01'::date + interval '1 month');
|
||||
```
|
||||
@@ -1,75 +0,0 @@
|
||||
# Database Migrations
|
||||
|
||||
## License Heartbeats Table Migration
|
||||
|
||||
### Overview
|
||||
The `create_license_heartbeats_table.sql` migration creates a partitioned table for storing real-time license validation data. This table is essential for the Live Dashboard & Analytics functionality.
|
||||
|
||||
### Features
|
||||
- Monthly partitioning for efficient data management
|
||||
- Automatic creation of current and next month partitions
|
||||
- Optimized indexes for performance
|
||||
- Foreign key relationship with licenses table
|
||||
|
||||
### Running the Migration
|
||||
|
||||
#### Option 1: Using the Python Script
|
||||
```bash
|
||||
cd /path/to/v2_adminpanel
|
||||
python apply_license_heartbeats_migration.py
|
||||
```
|
||||
|
||||
#### Option 2: Manual SQL Execution
|
||||
```bash
|
||||
psql -h postgres -U postgres -d v2_adminpanel -f migrations/create_license_heartbeats_table.sql
|
||||
```
|
||||
|
||||
#### Option 3: Docker Exec
|
||||
```bash
|
||||
docker exec -it v2_adminpanel_postgres psql -U postgres -d v2_adminpanel -f /migrations/create_license_heartbeats_table.sql
|
||||
```
|
||||
|
||||
### Verification
|
||||
After running the migration, verify the table was created:
|
||||
|
||||
```sql
|
||||
-- Check if table exists
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_name = 'license_heartbeats'
|
||||
);
|
||||
|
||||
-- List all partitions
|
||||
SELECT tablename
|
||||
FROM pg_tables
|
||||
WHERE tablename LIKE 'license_heartbeats_%'
|
||||
ORDER BY tablename;
|
||||
```
|
||||
|
||||
### Partition Management
|
||||
The system automatically creates partitions as needed. To manually create future partitions:
|
||||
|
||||
```python
|
||||
from utils.partition_helper import create_future_partitions
|
||||
import psycopg2
|
||||
|
||||
conn = psycopg2.connect(...)
|
||||
create_future_partitions(conn, 'license_heartbeats', months_ahead=6)
|
||||
```
|
||||
|
||||
### Data Retention
|
||||
Consider implementing a data retention policy to remove old partitions:
|
||||
|
||||
```sql
|
||||
-- Drop partitions older than 3 months
|
||||
DROP TABLE IF EXISTS license_heartbeats_2025_03;
|
||||
```
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
1. **Table already exists**: The migration is idempotent and will skip creation if the table exists.
|
||||
|
||||
2. **Permission denied**: Ensure the database user has CREATE privileges.
|
||||
|
||||
3. **Foreign key violation**: The licenses table must exist before running this migration.
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren