Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Initial pg-stat-analysis project #210

Merged
merged 2 commits into from
Dec 3, 2024
Merged

Conversation

johnjcsmith
Copy link
Contributor

@johnjcsmith johnjcsmith commented Dec 3, 2024

Adds an Inferable demonstration for analysing a Postgres DB and recommending index creation

Example output

{
  "summary": "After analyzing the database access patterns through pg_stat_statements, I've identified several potential performance improvements. The analysis shows that the most time-consuming queries are primarily related to job status updates and machine status management.",
  "suggestions": [
    {
      "name": "Add index on jobs.executing_machine_id, status, and remaining_attempts",
      "explanation": "One of the most time-consuming queries updates job status based on machine status and remaining attempts. This compound index would improve the performance of this frequently executed query.",
      "impactedQueries": [
        "UPDATE jobs as j SET status = $1 FROM machines as m WHERE j.status = $2 AND j.executing_machine_id = m.id AND m.status = $3 AND j.cluster_id = m.cluster_id AND j.remaining_attempts > $4"
      ],
      "remediation": "CREATE INDEX idx_jobs_exec_machine_status_attempts ON jobs(executing_machine_id, status, remaining_attempts);",
      "impact": 8
    },
    {
      "name": "Add partial index on jobs for timeout conditions",
      "explanation": "The most time-consuming query involves updating timed-out jobs. A partial index would improve the performance of this specific operation.",
      "impactedQueries": [
        "update \"jobs\" set \"status\" = $1 where (\"jobs\".\"status\" = $2 and \"jobs\".\"last_retrieved_at\" < now() - interval $4 * timeout_interval_seconds and \"jobs\".\"timeout_interval_seconds\" is not null and (\"jobs\".\"approval_requested\" = $3 or \"jobs\".\"approved\" is not null))"
      ],
      "remediation": "CREATE INDEX idx_jobs_timeout_conditions ON jobs(status, last_retrieved_at) WHERE timeout_interval_seconds IS NOT NULL;",
      "impact": 9
    }
  ]
}

@johnjcsmith johnjcsmith marked this pull request as ready for review December 3, 2024 05:24
@johnjcsmith johnjcsmith force-pushed the docs/pg-stat-analysis branch from a10fdf0 to 4c73d11 Compare December 3, 2024 05:29
Co-authored-by: Nadeesha Cabral <[email protected]>
@johnjcsmith johnjcsmith force-pushed the docs/pg-stat-analysis branch from 96e9604 to 3096df3 Compare December 3, 2024 06:08
@johnjcsmith johnjcsmith merged commit 3441a37 into main Dec 3, 2024
25 checks passed
@johnjcsmith johnjcsmith deleted the docs/pg-stat-analysis branch December 3, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants