Update database cleanup to retain logs for 3 days

Modify `cleanup_old_logs.sql` to retain logs for 3 days instead of 7, and update the `cleanup_database.sh` script to reflect this change.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 6c570c89-bf79-4953-8af1-61fd481625bc
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/x5P9dcJ
This commit is contained in:
marco370 2025-11-24 10:56:07 +00:00
parent 070adb0d14
commit 2067c390c1
3 changed files with 11 additions and 6 deletions

View File

@ -14,6 +14,10 @@ run = ["npm", "run", "start"]
localPort = 5000
externalPort = 80
[[ports]]
localPort = 34435
externalPort = 3001
[[ports]]
localPort = 41303
externalPort = 3002

View File

@ -1,7 +1,8 @@
-- =============================================================================
-- IDS - Pulizia Automatica Log Vecchi
-- =============================================================================
-- Mantiene solo gli ultimi 7 giorni di network_logs
-- Mantiene solo gli ultimi 3 giorni di network_logs
-- Con 4.7M record/ora, 3 giorni = ~340M record massimi
-- Esegui giornalmente via cron: psql $DATABASE_URL < cleanup_old_logs.sql
-- =============================================================================
@ -12,15 +13,15 @@ DECLARE
old_count bigint;
BEGIN
SELECT COUNT(*) INTO total_count FROM network_logs;
SELECT COUNT(*) INTO old_count FROM network_logs WHERE timestamp < NOW() - INTERVAL '7 days';
SELECT COUNT(*) INTO old_count FROM network_logs WHERE timestamp < NOW() - INTERVAL '3 days';
RAISE NOTICE 'Log totali: %', total_count;
RAISE NOTICE 'Log da eliminare (>7 giorni): %', old_count;
RAISE NOTICE 'Log da eliminare (>3 giorni): %', old_count;
END $$;
-- Elimina log più vecchi di 7 giorni
-- Elimina log più vecchi di 3 giorni
DELETE FROM network_logs
WHERE timestamp < NOW() - INTERVAL '7 days';
WHERE timestamp < NOW() - INTERVAL '3 days';
-- Vacuum per liberare spazio fisico
VACUUM ANALYZE network_logs;

View File

@ -35,7 +35,7 @@ psql "$DATABASE_URL" -c "SELECT pg_size_pretty(pg_database_size(current_database
# Esegui pulizia
echo ""
echo "🧹 Eliminazione log vecchi (>7 giorni)..."
echo "🧹 Eliminazione log vecchi (>3 giorni)..."
psql "$DATABASE_URL" -f "$IDS_DIR/database-schema/cleanup_old_logs.sql"
# Dimensione database DOPO la pulizia