Diagnostic Log - Slow Queries Only on Azure PostgreSQL Flexible Server

ab-oe 6 Reputation points
2023-02-09T10:04:57.4933333+00:00

Hi

We want to log all slow queries on Azure PostgreSQL Flexible Server.
We enabled Diagnostic Logs on the PostgreSQL Server and set the log_min_duration_statement to 1000.

Now, if we query Diagnostic Logs like this, we get a lot of other queries also logged, connection, disconnection, checkpoints, all the "internals".
'disconnection:', 'connection authorized:', 'connection received:', 'checkpoint starting:', 'checkpoint complete:',

AzureDiagnostics
| where Resource == "my-psql-server"
| where Category == "PostgreSQLLogs"
| where TimeGenerated > ago(1d) 

Is there a way to log only slow queries?

As I see here: log_connections cannot be disabled.

https://learn.microsoft.com/en-us/answers/questions/683954/log-connections-cannot-be-set-on-azure-postgresql?source=docs

Azure Database for PostgreSQL
{count} votes

1 answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 13,271 Reputation points Microsoft Employee
    2023-02-09T11:58:07.06+00:00

    Hi @ab-oe ,

    Welcome to Microsoft Q&A forum and thanks for using Azure services.

    As I understand from the question, you want to log all slow queries on Azure PostgreSQL Flexible Server.

    You have got the correct link where it is mentioned log_connections cannot be disabled due to security reasons.

    However, since Azure PostgreSQL Flexible Server is still evolving, an extra filter might be added in future in the Diagnostic Settings like we have in Azure MySQL:

    User's image

    You may post feedback for our team to add this feature in future here: Feedback Channel Azure PostgreSQL Flexible Server.

    Other useful links for Configuration of Logs : https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/howto-configure-and-access-logs

    Enable query logging in Azure database for PostgreSQL

    Hope this helps. Please let us know your inputs in case of further queries. Thanks

    0 comments No comments