Files
mamad-app/scripts/database-maintenance.sql
2025-06-22 00:01:22 +03:00

37 lines
1018 B
SQL

-- Database maintenance and optimization script
USE emergency_tracker;
-- Show current connection status
SHOW STATUS LIKE 'Threads_connected';
SHOW STATUS LIKE 'Threads_running';
SHOW STATUS LIKE 'Max_used_connections';
-- Show current process list (active connections)
SHOW PROCESSLIST;
-- Optimize tables for better performance
OPTIMIZE TABLE users;
OPTIMIZE TABLE admin_actions;
-- Update table statistics
ANALYZE TABLE users;
ANALYZE TABLE admin_actions;
-- Show table sizes
SELECT
table_name AS 'Table',
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)'
FROM information_schema.TABLES
WHERE table_schema = 'emergency_tracker'
ORDER BY (data_length + index_length) DESC;
-- Show connection limits
SHOW VARIABLES LIKE 'max_connections';
SHOW VARIABLES LIKE 'wait_timeout';
SHOW VARIABLES LIKE 'interactive_timeout';
-- Recommended settings for connection management
-- SET GLOBAL max_connections = 200;
-- SET GLOBAL wait_timeout = 300;
-- SET GLOBAL interactive_timeout = 300;