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

Research Creating a Celery Task to Check for Long Running Database Queries #5755

Closed
4 of 5 tasks
tmpayton opened this issue Mar 12, 2024 · 1 comment · Fixed by #5769 · May be fixed by #5800
Closed
4 of 5 tasks

Research Creating a Celery Task to Check for Long Running Database Queries #5755

tmpayton opened this issue Mar 12, 2024 · 1 comment · Fixed by #5769 · May be fixed by #5800

Comments

@tmpayton
Copy link
Contributor

tmpayton commented Mar 12, 2024

What we’re after

We should research creating a celery task to check for database queries over five minutes long. We should also be able to run a task manually that will clear out any long running queries. Ex- cf run-task api "python manage.py clear_long_running_query" -m 4G --name clear-queries https://github.com/fecgov/fecfile-web-api/pull/645/commits/439912a0d4f6c526697a708184f7f0d81fe9ca22

Action item(s)

  • Research creating a celery task to display queries over 5 mins
  • Research creating a manual task to clear long running queries
  • Research if we can create create a dashboard of the task log in Kibana
  • Research if the #bots-long-query slack channel displays the long running queries

Completion criteria

  • Research and next steps are documented

References/resources/technical considerations

SQL for canceling queries:

SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
where (lower(query) like '%select count(*) as count_1%'
or  lower(query) not like '%rollback%'   
or  lower(query) not like '%rollback%'  
or  lower(query) not like '%refresh %' )
and datname <>'<database_name>'
and usename ='<username>'
and  (now() - pg_stat_activity.query_start) > interval '5 minutes'
order by pg_stat_activity.query_start desc

SQL for finding long running queries:

SELECT  pg_terminate_backend(pid)   FROM pg_stat_activity   WHERE datname <>'<database_name>'   and usename ='<username>'   AND (now() - pg_stat_activity.query_start) > interval '2 minutes';
@cnlucas
Copy link
Member

cnlucas commented Mar 20, 2024

Manual commands added in this PR #5769 We can make it a celery task easily, but more research and discussion about that with the DB team is needed.

@pkfec pkfec moved this to 👀 Ready in Website project Apr 1, 2024
@pkfec pkfec moved this from 👀 Ready to 🏗 In Progress in Website project Apr 1, 2024
@tmpayton tmpayton modified the milestones: 24.4, 24.5 Apr 2, 2024
@tmpayton tmpayton moved this from 🏗 In Progress to 👀 Ready in Website project Apr 3, 2024
@github-project-automation github-project-automation bot moved this from 👀 Ready to ✅ Done in Website project Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment