diff --git a/backend/db-setup/reset-db.sql b/backend/db-setup/reset-db.sql index 5878329033..27831a8fda 100644 --- a/backend/db-setup/reset-db.sql +++ b/backend/db-setup/reset-db.sql @@ -17,3 +17,5 @@ ALTER DEFAULT PRIVILEGES FOR USER simple_report_migrations IN SCHEMA simple_repo GRANT USAGE ON LANGUAGE plpgsql to simple_report_app; DROP EXTENSION IF EXISTS pgcrypto; CREATE EXTENSION IF NOT EXISTS pgcrypto SCHEMA simple_report; +DROP EXTENSION IF EXISTS pg_stat_statements; +CREATE EXTENSION IF NOT EXISTS pg_stat_statements SCHEMA simple_report; diff --git a/ops/services/postgres_db/investigation.tf b/ops/services/postgres_db/investigation.tf new file mode 100644 index 0000000000..9cec5c4e1d --- /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 = -1 +} + +# 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 = "off" +} + +# 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 = "none" +} + +# 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 = "off" +} + +# 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 = -1 +} diff --git a/ops/services/postgres_db/main.tf b/ops/services/postgres_db/main.tf index 15aaf909ae..56adcc6fc9 100644 --- a/ops/services/postgres_db/main.tf +++ b/ops/services/postgres_db/main.tf @@ -66,3 +66,16 @@ resource "azurerm_postgresql_flexible_server_configuration" "pgms_wait_sampling_ server_id = azurerm_postgresql_flexible_server.db.id value = "ALL" } + +resource "azurerm_postgresql_flexible_server_configuration" "postgresql_shared_preload_libraries" { + name = "shared_preload_libraries" + server_id = azurerm_postgresql_flexible_server.db.id + value = "AUTO_EXPLAIN,PG_CRON,PG_STAT_STATEMENTS" +} + +# This allows us to install these extensions on the server +resource "azurerm_postgresql_flexible_server_configuration" "postgresql_extensions" { + name = "azure.extensions" + server_id = azurerm_postgresql_flexible_server.db.id + value = "PG_STAT_STATEMENTS,PGCRYPTO,PLPGSQL" +}