使用 Azure CLI 配置和访问服务器日志Configure and access server logs by using Azure CLI

可以使用命令行接口 (Azure CLI) 下载 PostgreSQL 服务器错误日志。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. 要启动日期,请更新 log_statement 和 log_min_duration_statement。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

若要列出服务器的可用日志文件,请运行 az postgres server-logs list 命令。To list the available log files for your server, run the az postgres server-logs list command.

可以列出资源组“myresourcegroup”下的服务器 mydemoserver.postgres.database.chinacloudapi.cn 的日志文件。You can list the log files for server mydemoserver.postgres.database.chinacloudapi.cn under the resource group myresourcegroup. 然后在日志文件列表中找到名为“log_files_list.txt”的文本文件。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

使用 az postgres server-logs download 命令可下载服务器的单个日志文件。With the az postgres server-logs download command, you can download individual log files for your server.

使用以下示例,可以将资源组“myresourcegroup”下服务器 mydemoserver.postgres.database.chinacloudapi.cn 的特定日志文件下载到本地环境 。Use the following example to download the specific log file for the server mydemoserver.postgres.database.chinacloudapi.cn under the resource group myresourcegroup to your local environment.

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

后续步骤Next steps