From 3e61f027ba9e382f267ed285d5f9bdb284fb80c7 Mon Sep 17 00:00:00 2001 From: Alis Akers Date: Fri, 2 Jun 2023 14:07:28 -0700 Subject: [PATCH] update postgresql parameters for db investigations --- .../db/changelog/db.changelog-master.yaml | 13 +++++- ops/services/postgres_db/investigation.tf | 46 +++++++++++++++++++ ops/services/postgres_db/main.tf | 7 +++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 ops/services/postgres_db/investigation.tf diff --git a/backend/src/main/resources/db/changelog/db.changelog-master.yaml b/backend/src/main/resources/db/changelog/db.changelog-master.yaml index e6714ba608e..4bf6ea04ff6 100644 --- a/backend/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/backend/src/main/resources/db/changelog/db.changelog-master.yaml @@ -4723,4 +4723,15 @@ databaseChangeLog: tag: drop-test_order_id-not_null_constraint-from-result - dropNotNullConstraint: tableName: result - columnName: test_order_id \ No newline at end of file + columnName: test_order_id + - changeSet: + id: create-pg-stat-statements-extension + author: alis@skylight.digital + comment: Install the pg_stat_statements extension. + changes: + - sql: + sql: CREATE EXTENSION IF NOT EXISTS pg_stat_statements; + rollback: + - sql: + sql: -- DROP EXTENSION IF EXISTS pg_stat_statements; + comment: Dropping the extension requires superuser permissions, and we don't want to give that to the migration user, so we have to do nothing here. diff --git a/ops/services/postgres_db/investigation.tf b/ops/services/postgres_db/investigation.tf new file mode 100644 index 00000000000..e9372af73da --- /dev/null +++ b/ops/services/postgres_db/investigation.tf @@ -0,0 +1,46 @@ +# These are disabled by default to avoid performance impact. + +# https://www.postgresql.org/docs/current/runtime-config-logging.html +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 + # To disable: update this to -1 + value = 30 +} + +# https://www.postgresql.org/docs/current/runtime-config-statistics.html +resource "azurerm_postgresql_flexible_server_configuration" "track_io_timing" { + name = "track_io_timing" + server_id = azurerm_postgresql_flexible_server.db.id + # To enable: update this to "on" to enable + # To disable: update this to "off" + value = "on" +} + +# https://www.postgresql.org/docs/current/pgstatstatements.html +resource "azurerm_postgresql_flexible_server_configuration" "pg_stat_statements_track" { + name = "pg_stat_statements.track" + server_id = azurerm_postgresql_flexible_server.db.id + # To enable: update this to "top" or "all" to enable' + # To disable: update this to "none" + value = "all" +} + +# https://www.postgresql.org/docs/current/auto-explain.html +resource "azurerm_postgresql_flexible_server_configuration" "auto_explain_log_analyze" { + name = "auto_explain.log_analyze" + server_id = azurerm_postgresql_flexible_server.db.id + # To enable: update this to "on" to enable + # To disable: update this to "off" + value = "on" +} + +# https://www.postgresql.org/docs/current/auto-explain.html +resource "azurerm_postgresql_flexible_server_configuration" "auto_explain_log_min_duration" { + name = "auto_explain.log_min_duration" + 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 + # To disable: update this to -1 + value = 30 +} diff --git a/ops/services/postgres_db/main.tf b/ops/services/postgres_db/main.tf index 15aaf909ae5..edfd5f4c691 100644 --- a/ops/services/postgres_db/main.tf +++ b/ops/services/postgres_db/main.tf @@ -66,3 +66,10 @@ resource "azurerm_postgresql_flexible_server_configuration" "pgms_wait_sampling_ server_id = azurerm_postgresql_flexible_server.db.id value = "ALL" } + +# This allows us to install these extensions on the server +resource "azurerm_postgresql_flexible_server_configuration" "azure_extensions" { + name = "azure.extensions" + server_id = azurerm_postgresql_flexible_server.db.id + value = "PG_STAT_STATEMENTS,PGCRYPTO,PLPGSQL" +}