Ensure that “log_duration” server parameter is enabled for all PostgreSQL database servers created in your Microsoft Azure cloud account. Once enabled, the “log_duration” parameter allows recording the duration of each completed PostgreSQL statement. Only users with administrative privileges can change this setting within Azure PostgreSQL server configuration. For database clients using extended query protocol, the duration of the “Parse”, “Bind”, and “Execute” steps is logged independently.
To remediate the misconfiguration of enabling the “LOG_DURATION” parameter for PostgreSQL servers in AZURE using AZURE CLI, you can follow the below steps:
Open the AZURE CLI and log in to your AZURE account.
Run the below command to get the list of all the PostgreSQL servers in your subscription:
Copy
Ask AI
az postgres server list
Select the PostgreSQL server for which you want to enable the “LOG_DURATION” parameter and note down its resource group name and server name.
Run the below command to enable the “LOG_DURATION” parameter for the selected PostgreSQL server:
Copy
Ask AI
az postgres server configuration set --resource-group <resource_group_name> --server-name <server_name> --name log_duration --value on
Replace <resource_group_name> and <server_name> with the actual values of the resource group name and server name noted down in step 3.
Verify that the “LOG_DURATION” parameter is enabled for the PostgreSQL server by running the below command:
Copy
Ask AI
az postgres server configuration list --resource-group <resource_group_name> --server-name <server_name> --query "[?name=='log_duration']"
If the output shows the value of “value” parameter as “on”, then the “LOG_DURATION” parameter is enabled for the PostgreSQL server.
By following the above steps, you can remediate the misconfiguration of enabling the “LOG_DURATION” parameter for PostgreSQL servers in AZURE using AZURE CLI.
Using Python
To enable the “LOG_DURATION” parameter for PostgreSQL servers in Azure using python, you can follow the below steps:
Import the necessary libraries:
Copy
Ask AI
from azure.common.credentials import ServicePrincipalCredentialsfrom azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient