Enable, list and download server logs in Azure Database for PostgreSQL - Flexible Server using the Azure CLI

APPLIES TO: Azure Database for PostgreSQL - Flexible Server

This article shows you how to list and download Azure Database for PostgreSQL flexible server logs by using the Azure CLI.

Prerequisites

  • You must be running the Azure CLI version 2.39.0 or later locally. To see the version installed, run the az --version command. If you need to install or upgrade, see Install Azure CLI.
  • Sign in to your account by using the az login command. The id property refers to the Subscription ID for your Azure account.
az login

Select the specific subscription under your account by using the az account set command. Make a note of the id value from the az login output to use as the value for the subscription argument in the command. If you have multiple subscriptions, choose the appropriate subscription in which the resource should be billed. To get all your subscriptions, use az account list.

az account set --subscription <subscription id>

List server logs by using the Azure CLI

After you configure the prerequisites and connect to your required subscription, you can list the server logs from your Azure Database for PostgreSQL flexible server instance by using the following command.

Note

You can configure your server logs in the same way as just shown by using the server parameters. Set the appropriate values for these parameters. Set logfiles.download_enable to ON to enable this feature. Set logfiles.retention_days to define retention in days. Initially, server logs occupy data disk space for about an hour before moving to backup storage for the set retention period.

az postgres flexible-server server-logs list --resource-group <myresourcegroup> --server-name <serverlogdemo> --out <table>

Here are the details for the preceding command.

LastModifiedTime Name ResourceGroup SizeInKb TypePropertiesType URL
2024-01-10T13:20:15+00:00 serverlogs/postgresql_2024_01_10_12_00_00.log myresourcegroup 242 LOG https://00000000000.blob.core.windows.net/serverlogs/postgresql_2024_01_10_12_00_00.log?
2024-01-10T14:20:37+00:00 serverlogs/postgresql_2024_01_10_13_00_00.log myresourcegroup 237 LOG https://00000000000.blob.core.windows.net/serverlogs/postgresql_2024_01_10_13_00_00.log?
2024-01-10T15:20:58+00:00 serverlogs/postgresql_2024_01_10_14_00_00.log myresourcegroup 237 LOG https://00000000000.blob.core.windows.net/serverlogs/postgresql_2024_01_10_14_00_00.log?
2024-01-10T16:21:17+00:00 serverlogs/postgresql_2024_01_10_15_00_00.log myresourcegroup 240 LOG https://00000000000.blob.core.windows.net/serverlogs/postgresql_2024_01_10_15_00_00.log?

The output table here lists LastModifiedTime, Name, ResourceGroup, SizeInKb, and Download Url of the server logs.

By default, LastModifiedTime is set to 72 hours. For listing files older than 72 hours, use the flag --file-last-written <Time:HH>.

az postgres flexible-server server-logs list --resource-group <myresourcegroup>  --server-name <serverlogdemo> --out table --file-last-written <144>

Download server logs by using the Azure CLI

The following command downloads the preceding server logs to your current directory.

az postgres flexible-server server-logs download --resource-group <myresourcegroup> --server-name <serverlogdemo>  --name <serverlogs/postgresql_2024_01_10_12_00_00.log>

Share your suggestions and bugs with the Azure Database for PostgreSQL product team.