initial commit of v5

This commit is contained in:
Amruth Pillai
2026-01-19 23:31:54 +01:00
parent 55bdfd0067
commit cad390fa13
1132 changed files with 200807 additions and 165288 deletions
+46
View File
@@ -0,0 +1,46 @@
-- Enable pg_stat_statements extension
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
-- Enable other useful extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- UUID generation
CREATE EXTENSION IF NOT EXISTS "pgcrypto"; -- Cryptographic functions
CREATE EXTENSION IF NOT EXISTS "btree_gin"; -- GIN indexes for btree types
CREATE EXTENSION IF NOT EXISTS "btree_gist"; -- GIST indexes for btree types
-- Create a function to reset pg_stat_statements (useful for debugging)
CREATE OR REPLACE FUNCTION reset_query_stats()
RETURNS void AS $$
BEGIN
PERFORM pg_stat_statements_reset();
END;
$$ LANGUAGE plpgsql;
-- Create a view for easier query analysis
CREATE OR REPLACE VIEW slow_queries AS
SELECT
query,
calls,
ROUND(total_exec_time::numeric, 2) AS total_time_ms,
ROUND(mean_exec_time::numeric, 2) AS mean_time_ms,
ROUND(max_exec_time::numeric, 2) AS max_time_ms,
ROUND((100 * total_exec_time / SUM(total_exec_time) OVER ())::numeric, 2) AS percentage,
rows
FROM pg_stat_statements
ORDER BY total_exec_time DESC;
-- Create a view for most frequent queries
CREATE OR REPLACE VIEW frequent_queries AS
SELECT
query,
calls,
ROUND(mean_exec_time::numeric, 2) AS mean_time_ms,
ROUND(total_exec_time::numeric, 2) AS total_time_ms,
rows
FROM pg_stat_statements
ORDER BY calls DESC;
-- Notification for successful initialization
DO $$
BEGIN
RAISE NOTICE 'Database initialized with pg_stat_statements and helper views';
END $$;