Skip to content

Instantly share code, notes, and snippets.

@varun-dhawan
Last active November 2, 2022 15:45
Show Gist options
  • Save varun-dhawan/5baa7e54f01b773103d7a86089156a55 to your computer and use it in GitHub Desktop.
Save varun-dhawan/5baa7e54f01b773103d7a86089156a55 to your computer and use it in GitHub Desktop.

Azure Database for PostgreSQL Flexible Server - Logging

1. Logs Analytics

// Find Errors
// Search for errors in the last 6 hours.
// To create an alert for this query, click '+ New alert rule'
// Blog - https://techcommunity.microsoft.com/t5/azure-database-for-postgresql/how-do-i-check-logs-for-azure-database-for-postgresql/ba-p/3618983
AzureDiagnostics
| where Resource == "VARUND-PG1"
| where Category == "PostgreSQLLogs"
| where TimeGenerated > ago(6h)

// Statement (Query) level logging
// Blog - https://techcommunity.microsoft.com/t5/azure-database-for-postgresql/how-to-enable-query-logging-in-azure-database-for-postgresql/ba-p/3639626
AzureDiagnostics
| where Resource == "VARUND-PG1"
| where Category == "PostgreSQLLogs"
| where TimeGenerated > ago(3h)
| where processId_d == "4271"
| project TimeGenerated, Message


// Setting Alerts
// Doc - https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/howto-configure-and-access-logs
AzureDiagnostics
| where Resource == "VARUND-PG1"
| where Category == "PostgreSQLLogs"
| where TimeGenerated > ago(3h)
| where sqlerrcode_s == "42P07"

2. Storage Account

image

3. Alerting from Logs

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment