共用方式為


Configure and access server logs by using Azure CLI

APPLIES TO: Azure Database for PostgreSQL - Single Server

Important

Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.

You can download the PostgreSQL server error logs by using the command-line interface (Azure CLI). However, access to transaction logs isn't supported.

Prerequisites

To step through this how-to guide, you need:

Configure logging

You can configure the server to access query logs and error logs. Error logs can have auto-vacuum, connection, and checkpoint information.

  1. Turn on logging.
  2. To enable query logging, update log_statement and log_min_duration_statement.
  3. Update retention period.

For more information, see Customizing server configuration parameters.

List logs

To list the available log files for your server, run the az postgres server-logs list command.

You can list the log files for server mydemoserver.postgres.database.azure.com under the resource group myresourcegroup. Then direct the list of log files to a text file called log_files_list.txt.

az postgres server-logs list --resource-group myresourcegroup --server mydemoserver > log_files_list.txt

Download logs locally from the server

With the az postgres server-logs download command, you can download individual log files for your server.

Use the following example to download the specific log file for the server mydemoserver.postgres.database.azure.com under the resource group myresourcegroup to your local environment.

az postgres server-logs download --name 20170414-mydemoserver-postgresql.log --resource-group myresourcegroup --server mydemoserver

To download all available logs at once.

az postgres server-logs list -g [resource-group] -s [server-name] --query '[].{Name:name}' -o tsv |xargs -I {} az postgres server-logs download -g [resource-group] -s [server-name] -n {}

Next steps