Altinn / altinn-auth-audit-log

Audit log for authentication and authorisation activities
MIT License
0 stars 1 forks source link

Query analysis and index optimization for auditlog database #106

Open acn-dgopa opened 3 months ago

acn-dgopa commented 3 months ago

Case

Querying data from the auditlog database is slow. Currently we have partitioned database per year. But there is enormous data that is logged.

Query analysis

Start by monitoring the database for slow-running queries. PostgresSql provides tools like pg_stat_statements and pgBadger for query analysis.

Index Optimization

Create indexes on columns used in WHERE clauses, join conditions, and order by clauses to improve query performance. Consider using composite indexes for queries involving multiple columns.

Query Rewriting

Rewrite queries to make them more efficient. this could involve limiting the data based on user, timeperiod.

Query Tuning

Adjust the query parameters such as work_mem, effective_cache_size, and random_page_cost based on the characteristics of the workload and hardware configuration.

### Tasks
- [ ] Identify slow queries
- [ ] Identify columns for indexing
- [ ] Create index for identified columns
- [ ] Document the optimizations made, including changes to the database configuration, indexing strategies, and query optimization techniques