Skip to content

#1043 Add database query performance logging for slow queries #570

Description

@vic-Gray

Area: backend · Effort: S

What: Log all database queries exceeding 100ms with their SQL, parameters, and execution time, and expose a summary of the slowest queries.

Why: Slow queries are the most common performance bottleneck in web applications and are invisible without query logging. Early identification prevents them from becoming production incidents.

Acceptance Criteria:

  • Queries > 100ms are logged at WARN level with full SQL
  • Queries > 1000ms are logged at ERROR level and emit a metric
  • A GET /admin/slow-queries endpoint returns the top 10 slowest query types from the last 24 hours
  • The slow query threshold is configurable via env var

Hints:

  • Use TypeORM's logger option with logSlowQueries: true and a custom logger class
  • backend/src/database/slow-query-logger.ts
  • Aggregate slow query data in Redis with a 24-hour TTL

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions