Skip to content

Commit

Permalink
update postgresql parameters for db investigations
Browse files Browse the repository at this point in the history
  • Loading branch information
alismx committed Jun 12, 2023
1 parent a87238f commit 4594515
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/db-setup/reset-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
46 changes: 46 additions & 0 deletions ops/services/postgres_db/investigation.tf
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions ops/services/postgres_db/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 4594515

Please sign in to comment.