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

Postgresql parameters for db query investigations #5915

Merged
merged 7 commits into from
Jun 28, 2023
Merged

Postgresql parameters for db query investigations #5915

merged 7 commits into from
Jun 28, 2023

Conversation

alismx
Copy link
Collaborator

@alismx alismx commented Jun 2, 2023

DEVOPS/DATABASE PULL REQUEST

Related Issue

Changes Proposed

  • Installs pg_stat_statement extension ( this will be installed manually )
  • Sets up terraform configuration for the following PostgreSQL parameters
    • log_min_duration_statement
    • track_io_timing
    • pg_stat_statements.track
    • auto_explain.log_analyze
    • auto_explain.log_min_duration
  • Adds auto_explain to our databases list of shared_preload_libraries (previously was pg_cron,pg_stat_statements)
  • Limits our azure.extensions to extensions we use. This was manually set up and had way more than we needed or used.

Additional Information

  • Manual rollout steps:

    • Create a db backup
    • install pg_stat_statements
    • All databases will need to be restarted to add auto_explain to our list of shared_preload_libraries
    • merge this pr
    • Smoke test environment
    • delete db backup
  • I tried to add the pg_stat_statements extension with a backend migration, but our migrations user doesn't have permission

  • All these parameters have been tested to work but have been disabled because these options can cause performance issues, so we only want to enable them when we believe we need them.

  • This is work to enable future devs to investigate query issues.

  • I'd like to run an exercise using these parameters to gather baseline data about our queries.

Wiki Page: https://github.com/CDCgov/prime-simplereport/wiki/Database-investigation-tools

Testing

  • How should reviewers verify this PR?

  • Check the terraform plan.

Checklist for Primary Reviewer

Database

  • Only database changes are included in this PR
  • Any new tables or columns that do not contain PII are accompanied by a GRANT SELECT to the no-PHI user
  • Any changes to tables that have custom no-PHI views are accompanied by changes to those views (including re-granting permission to the no-PHI user if need be)
  • Each new changeset has a corresponding tag
  • Rollback has been verifed locally and in a deployed environment
  • Any changes to the startup configuration have been documented in the README

Infrastructure

  • Consult the results of the terraform-plan job inside the "Terraform Checks" workflow run for this PR. Confirm that there are no unexpected changes!

Security

  • Changes with security implications have been approved by a security engineer (changes to authentication, encryption, handling of PII, etc.)
  • Any dependencies introduced have been vetted and discussed

Cloud

  • Oncall has been notified if this change is going in after-hours
  • If there are changes that cannot be tested locally, this has been deployed to our Azure test, dev, or pentest environment for verification

Documentation

  • Any changes to the startup configuration have been documented in the README

@alismx alismx temporarily deployed to Dev4 June 2, 2023 21:48 — with GitHub Actions Inactive
@alismx alismx temporarily deployed to Dev4 June 7, 2023 18:02 — with GitHub Actions Inactive
@alismx alismx force-pushed the alis/4318 branch 5 times, most recently from 3458116 to 1f95b38 Compare June 7, 2023 18:38
@alismx alismx temporarily deployed to Dev4 June 7, 2023 18:53 — with GitHub Actions Inactive
@alismx alismx temporarily deployed to Dev4 June 7, 2023 19:12 — with GitHub Actions Inactive
@alismx alismx force-pushed the alis/4318 branch 5 times, most recently from 3e61f02 to b231251 Compare June 9, 2023 20:27
@alismx alismx temporarily deployed to Dev4 June 9, 2023 20:45 — with GitHub Actions Inactive
@alismx alismx force-pushed the alis/4318 branch 4 times, most recently from abc1dfe to 9ce8bef Compare June 12, 2023 17:39
@alismx alismx marked this pull request as ready for review June 12, 2023 17:47
resource "azurerm_postgresql_flexible_server_configuration" "log_min_duration_statement" {
name = "log_min_duration_statement"
server_id = azurerm_postgresql_flexible_server.db.id
# To enable: this is in milliseconds, update this to a positive value in milliseconds to enable this logging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for my own learning: is there a good value to start off with when turning this on? Is every minute too much too little? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer to this depends very much on the context, but I expect most queries to complete well under 1 second, so in most cases, setting it to something between 2 and 5 seconds would probably be fine.

Copy link
Collaborator

@emyl3 emyl3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one non-blocking question! Thank you for adding docs on how to use this 😲

Copy link
Contributor

@BobanL BobanL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good! Thanks for adding the documentation 😄

@rin-skylight
Copy link
Collaborator

Quick note: Let's make sure we take a backup of the prod DB before we roll this out. Just in case!

@alismx
Copy link
Collaborator Author

alismx commented Jun 22, 2023

I'll deploy this and perform the manual DB updates on the week of July 26th.

@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@alismx alismx merged commit d7b97b5 into main Jun 28, 2023
41 of 42 checks passed
@alismx alismx deleted the alis/4318 branch June 28, 2023 03:09
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.

Explore database configurations to help with investigations and tuning query usage and performance
4 participants