Configure and Access Logs in Azure Database for PostgreSQL - Flexible Server
APPLIES TO:
Azure Database for PostgreSQL - Flexible Server
PostgreSQL logs are available on every node of a flexible server. You can ship logs to a storage server, or to an analytics service. The logs can be used to identify, troubleshoot, and repair configuration errors and suboptimal performance.
Configure diagnostic settings
You can enable diagnostic settings for your Postgres server using the Azure portal, CLI, REST API, and PowerShell. The log category to select is PostgreSQLLogs.
To enable resource logs using the Azure portal:
In the portal, go to Diagnostic Settings in the navigation menu of your Postgres server.
Select Add Diagnostic Setting.
Name this setting.
Select your preferred endpoint (storage account, event hub, log analytics).
Select the log type PostgreSQLLogs.
Save your setting.
To enable resource logs using PowerShell, CLI, or REST API, visit the diagnostic settings article.
Access resource logs
The way you access the logs depends on which endpoint you choose. For Azure Storage, see the logs storage account article. For Event Hubs, see the stream Azure logs article.
For Azure Monitor Logs, logs are sent to the workspace you selected. The Postgres logs use the AzureDiagnostics collection mode, so they can be queried from the AzureDiagnostics table. The fields in the table are described below. Learn more about querying and alerting in the Azure Monitor Logs query overview.
The following are queries you can try to get started. You can configure alerts based on queries.
Search for all Postgres logs for a particular server in the last day
AzureDiagnostics
| where LogicalServerName_s == "myservername"
| where Category == "PostgreSQLLogs"
| where TimeGenerated > ago(1d)
Search for all non-localhost connection attempts
AzureDiagnostics
| where Message contains "connection received" and Message !contains "host=127.0.0.1"
| where Category == "PostgreSQLLogs" and TimeGenerated > ago(6h)
The query above will show results over the last 6 hours for any Postgres server logging in this workspace.
Next steps
Maklum balas
Kirim dan lihat maklum balas untuk