

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息，请参阅[博客文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

# Amazon Redshift 中的日志记录和监控
<a name="security-incident-response"></a>

监控是保持 Amazon Redshift 和您的 AWS 解决方案的可靠性、可用性和性能的重要方面。您可以从 AWS 解决方案的各个部分收集监控数据，以便您可以更轻松地调试多点故障（如果发生）。AWS 提供了多种工具来监控您的 Amazon Redshift 资源并对潜在事件做出响应：

**Amazon CloudWatch 警报**  
使用 Amazon CloudWatch 警报，您可以在指定时间段内监控某个指标。如果指标超过给定阈值，则会向 Amazon SNS 主题或 AWS Auto Scaling 策略发送通知。CloudWatch 警报将不会调用操作，因为这些操作处于特定状态。而是必须在状态已改变并在指定的若干个时间段内保持不变后才调用。有关更多信息，请参阅 [创建警报](performance-metrics-alarms.md)。有关 指标的列表，请参阅 [Amazon Redshift 中的性能数据](metrics-listing.md)。

**AWS CloudTrail 日志**  
CloudTrail 会提供用户、IAM 角色或 AWS 服务在 Amazon Redshift 中所执行的 API 操作的记录。使用 CloudTrail 收集的信息，您可以确定向 Amazon Redshift 发出了什么请求、发出请求的 IP 地址、何人发出的请求、请求的发出时间以及其他详细信息。有关更多信息，请参阅 [使用 Cloudtrail 进行日志记录](logging-with-cloudtrail.md)。

# 数据库审计日志记录
<a name="db-auditing"></a>

Amazon Redshift 记录您的数据库中的连接和用户活动相关信息。这些日志有助于您监控数据库以确保安全并进行故障排除，该流程称为*数据库审计*。可以存储日志的位置包括：
+ *Amazon S3 存储桶* - 这为负责监控数据库中活动的用户提供了访问权限以及数据安全功能。
+ *Amazon CloudWatch* - 您可以使用 CloudWatch 中内置的功能（例如可视化功能和设置操作）查看审计日志记录数据。

**注意**  
[SYS\$1CONNECTION\$1LOG](https://docs.aws.amazon.com/redshift/latest/dg/SYS_CONNECTION_LOG.html) 收集 Amazon Redshift Serverless 的连接日志数据。请注意，当您收集 Amazon Redshift Serverless 的审计日志记录数据时，无法将其发送到日志文件，只能发送到 CloudWatch。

**Topics**
+ [Amazon Redshift 日志](#db-auditing-logs)
+ [审计日志和 Amazon CloudWatch](#db-auditing-cloudwatch-provisioned)
+ [启用审计日志记录](db-auditing-console.md)
+ [安全日志记录](db-auditing-secure-logging.md)

## Amazon Redshift 日志
<a name="db-auditing-logs"></a>

Amazon Redshift 在以下日志文件中记录信息：
+ *连接日志* – 记录身份验证尝试以及连接与断开连接。
+ *用户日志* – 记录与数据库用户定义更改相关的信息。
+ *用户活动日志* – 记录在数据库中运行之前的每个查询。

连接日志和用户日志主要用于实现安全性。您可以使用连接日志来监控连接到数据库的用户信息以及相关的连接信息。这些信息可能是他们的 IP 地址、发出请求的时间以及使用的身份验证类型等。您可以使用用户日志来监控数据库用户定义更改。

用户活动日志主要用于进行故障排除。它会跟踪用户及系统在数据库中执行的查询类型的相关信息。

连接日志和用户日志均对应于数据库的系统表中存储的信息。您可以使用系统表获取相同的信息，但日志文件可提供更简单的检索和查看机制。日志文件依赖 Simple Storage Service（Amazon S3）权限（而非数据库权限）针对表执行查询。此外，通过查看日志文件中的信息（而非查询系统表），您可以减少与数据库互动产生的任何影响。

**注意**  
日志文件没有系统日志表（即 [STL\$1USERLOG](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_USERLOG.html) 和 [STL\$1CONNECTION\$1LOG](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_CONNECTION_LOG.html)）那么新。早于 (但不包括) 最新记录的记录将被复制到日志文件。

**注意**  
对于 Amazon Redshift Serverless，[SYS\$1CONNECTION\$1LOG](https://docs.aws.amazon.com/redshift/latest/dg/SYS_CONNECTION_LOG.html) 收集连接日志数据。当您收集 Amazon Redshift Serverless 的审计日志记录数据时，无法将其发送到日志文件，只能发送到 CloudWatch。

### 连接日志
<a name="db-auditing-connection-log"></a>

记录身份验证尝试以及连接与断开连接。下表介绍了连接日志中的信息。有关这些字段的更多信息，请参阅《Amazon Redshift 数据库开发人员指南》**中的 [STL\$1CONNECTION\$1LOG](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_CONNECTION_LOG.html)。有关为 Amazon Redshift Serverless 收集的连接日志数据的更多信息，请参阅 [SYS\$1CONCON\$1LOG](https://docs.aws.amazon.com/redshift/latest/dg/SYS_CONNECTION_LOG.html)。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/redshift/latest/mgmt/db-auditing.html)

### 用户日志
<a name="db-auditing-user-log"></a>

 记录数据库用户的以下更改的详细信息。
+ 创建用户
+ 删除用户
+ 更改用户（重命名）
+ 更改用户（更改属性）

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/redshift/latest/mgmt/db-auditing.html)

查询 [SYS\$1USERLOG](https://docs.aws.amazon.com/redshift/latest/dg/SYS_USERLOG.html) 系统视图，以查找有关用户更改的更多信息。此视图包括来自 Amazon Redshift Serverless 的日志数据。

### 用户活动日志
<a name="db-auditing-user-activity-log"></a>

记录在数据库中运行之前的每个查询。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/redshift/latest/mgmt/db-auditing.html)

## 审计日志和 Amazon CloudWatch
<a name="db-auditing-cloudwatch-provisioned"></a>

 在 Amazon Redshift 中，原定设置情况下审计日志记录处于未启用状态。当您针对集群打开日志记录时，Amazon Redshift 将日志导出到 Amazon CloudWatch 中，或创建日志并将其上载到 Simple Storage Service (Amazon S3) 中，以捕获从启用审计日志记录的时间到当前时间的数据。每个日志记录更新都是以前日志的延续。

在 CloudWatch 或 Simple Storage Service (Amazon S3) 中存储审计日志记录是一个可选流程。记录到数据表并非可选流程，而会自动发生。有关系统表日志记录的更多信息，请参阅 Amazon Redshift 数据库开发人员指南中的[系统表参考](https://docs.aws.amazon.com/redshift/latest/dg/cm_chap_system-tables.html)。

您可以通过使用 AWS 管理控制台、Amazon Redshift API 参考或 AWS Command Line Interface (AWS CLI) 一起启用连接日志、用户日志以及用户活动日志。对于用户活动日志，您还必须启用 `enable_user_activity_logging` 数据库参数。如果您仅启用审计日志记录功能，但不启用相关参数，则数据库审计日志将仅为连接日志和用户日志记录信息，而不为用户活动日志记录信息。`enable_user_activity_logging` 参数预设情况下未启用 (`false`)。您可以将它设置为 `true` 以启用用户活动日志。有关更多信息，请参阅 [Amazon Redshift 参数组](working-with-parameter-groups.md)。

在对 CloudWatch 启用日志记录后，Amazon Redshift 将集群连接、用户和用户活动日志数据导出到 Amazon CloudWatch Logs 日志组。就 架构 而言，日志数据不会改变。CloudWatch 专为监控应用程序而构建，您可以使用它来执行实时分析或将其设置为采取措施。还可以使用 Amazon CloudWatch Logs 在持久性存储中存储日志记录。

使用 CloudWatch 查看日志是在 Simple Storage Service (Amazon S3 )中存储日志文件的推荐替代方法。它不需要太多的配置，而且可能符合您的监控要求，尤其是如果您已经使用它来监控其他服务和应用程序。

### Amazon CloudWatch 中的日志组和日志事件
<a name="db-auditing-cloudwatch-provisioned-log-group"></a>

在选择要导出的 Amazon Redshift 日志后，您可以在 Amazon CloudWatch Logs 中监控日志事件。将使用以下前缀为 Amazon Redshift 无服务器自动创建新的日志组，其中 `log_type` 表示日志类型。

```
/aws/redshift/cluster/<cluster_name>/<log_type>
```

例如，如果您选择导出连接日志，则日志数据将存储在以下日志组中。

```
/aws/redshift/cluster/cluster1/connectionlog
```

使用日志流将日志事件导出到日志组。要在无服务器端点的日志事件中搜索信息，请使用 Amazon CloudWatch Logs 控制台、AWS CLI 或 Amazon CloudWatch Logs API。有关搜索和筛选日志数据的信息，请参阅[使用筛选条件从日志事件创建指标](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/MonitoringLogData.html)。

在 CloudWatch 中，您可以使用所提供的旨在实现粒度和灵活性的查询语法搜索日志数据。有关更多信息，请参阅 [CloudWatch Logs Insights 查询语法](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html)。

### 迁移到 Amazon CloudWatch 审计日志记录
<a name="db-auditing-cloudwatch-provisioned-migration"></a>

在任何情况下，如果您要向 Simple Storage Service (Amazon S3) 发送日志并更改配置（例如向 CloudWatch 发送日志），保留在 Simple Storage Service (Amazon S3) 中的日志都不会受到影响。您仍可以在日志数据所在的 Simple Storage Service (Amazon S3) 存储桶中查询日志数据。

### Amazon S3 中的日志文件
<a name="db-auditing-manage-log-files"></a>

Simple Storage Service（Amazon S3）中的 Amazon Redshift 日志文件的数量和大小在很大程度上取决于您集群中的活动。如果您有一个活动的集群生成了大量日志，则 Amazon Redshift 可能会更频繁地生成日志文件。对于同一类活动，您可能有一系列日志文件，例如同一个小时有多个连接日志。

当 Amazon Redshift 使用 Simple Storage Service (Amazon S3) 存储日志时，您需要为在 Simple Storage Service (Amazon S3) 中使用的存储支付相应费用。在对 Simple Storage Service (Amazon S3) 配置日志记录之前，应计划需存储日志文件的时长。在此过程中，请确定何时可根据审计需求删除或归档日志文件。您制定的计划在很大程度上取决于您存储的数据类型，例如需满足合规性或法规要求的数据。有关 Simple Storage Service（Amazon S3）定价的更多信息，请转至 [Amazon Simple Storage Service（S3）定价](https://aws.amazon.com/s3/pricing/)。

#### 对 Amazon S3 启用日志记录时的限制
<a name="db-auditing-enable-logging-limitations"></a>

审计日志记录具有以下约束：
+ 您只能使用 Amazon S3 托管式密钥（SSE-S3）加密（AES-256）。
+ Amazon S3 桶必须关闭 S3 对象锁定功能。

#### Amazon Redshift 审计日志记录的存储桶权限
<a name="db-auditing-bucket-permissions"></a>

当您对 Simple Storage Service (Amazon S3) 启用日志记录时，Amazon Redshift 会收集日志记录信息并将其上载到 Simple Storage Service (Amazon S3) 中存储的日志文件。您可以使用现有存储桶或新存储桶。Amazon Redshift 需要对存储桶具备以下 IAM 权限：
+ `s3:GetBucketAcl` 该服务要求对 Simple Storage Service（Amazon S3）存储桶具备读取权限，以便可以识别存储桶拥有者。
+ `s3:PutObject` 该服务要求具备放置对象权限，以便上载日志。此外，开启日志记录的用户或 IAM 角色必须具有对 Amazon S3 桶的 `s3:PutObject` 权限。每次上传日志时，该服务就会确定当前存储桶拥有者与启用日志记录时的存储桶拥有者是否一致。如果这些拥有者不匹配，您将收到一条错误。

如果启用审计日志记录时，您选择了创建新存储桶的选项，则会对其应用正确的权限。不过，如果您在 Simple Storage Service（Amazon S3）中创建自己的存储桶或使用现有存储桶，请确保添加包含存储桶名称的存储桶策略。日志使用服务主体凭证传送。对于大多数 AWS 区域，您可添加 Redshift 服务主体名称，*redshift t.amazonaws.com*。

该存储桶策略使用以下格式。*ServiceName* 和 *BucketName* 是您自己的值的占位符。还可在存储桶策略中指定关联的操作和资源。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "Put bucket policy needed for audit logging",
            "Effect": "Allow",
            "Principal": {
                "Service": "ServiceName"
            },
            "Action": [
                "s3:PutObject",
                "s3:GetBucketAcl"
            ],
            "Resource": [
                "arn:aws:s3:::BucketName",
                "arn:aws:s3:::BucketName/*"
            ]
        }
    ]
}
```

------

以下示例就是针对美国东部（弗吉尼亚北部）区域的存储桶策略，该存储桶名为 `AuditLogs`。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "Put bucket policy needed for audit logging",
            "Effect": "Allow",
            "Principal": {
                "Service": "redshift.amazonaws.com"
            },
            "Action": [
                "s3:PutObject",
                "s3:GetBucketAcl"
            ],
            "Resource": [
                "arn:aws:s3:::AuditLogs",
                "arn:aws:s3:::AuditLogs/*"
            ]
        }
    ]
}
```

------

原定设置情况下未启用的区域（也称为“选择加入”区域）需要特定于区域的服务主体名称。对于这些内容，服务主体名称包括区域，格式为 `redshift.region.amazonaws.com`。例如，*redshift.ap-east-1.amazonaws.com* 针对亚太地区（香港）区域。有关默认情况下未启用的区域列表，请参阅《AWS 一般参考》**中的[管理 AWS 区域](https://docs.aws.amazon.com/general/latest/gr/rande-manage.html)。

**注意**  
特定于区域的服务主体名称与集群所在的区域对应。

##### 日志文件的最佳实践
<a name="db-auditing-bucket-permissions-confused-deputy"></a>

 当 Redshift 将日志文件上载到 Simple Storage Service（Amazon S3）时，可以分段上载大型文件。如果分段上载不成功，则文件的一部分可能会保留在 Simple Storage Service（Amazon S3）存储桶中。这可能会导致额外的存储成本，因此了解什么情况下分段上载会失败非常重要。有关审计日志的分段上载的详细说明，请参阅[使用分段上载来上载和复制对象](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html)和[中止分段上载](https://docs.aws.amazon.com/AmazonS3/latest/userguide/abort-mpu.html)。

有关创建 S3 存储桶和添加存储桶策略的更多信息，请参阅《Amazon Simple Storage Service 用户指南》**中的[创建通用存储桶](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)和 [Amazon S3 的存储桶策略](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html)。

#### Amazon Redshift 审计日志记录的存储桶结构
<a name="db-auditing-bucket-structure"></a>

预设情况下，Amazon Redshift 通过使用下列存储桶和对象结构在 Simple Storage Service（Amazon S3）存储桶中整理日志文件：``

`AWSLogs/AccountID/ServiceName/Region/Year/Month/Day/AccountID_ServiceName_Region_ClusterName_LogType_Timestamp.gz` 

例如：`AWSLogs/123456789012/redshift/us-east-1/2013/10/29/123456789012_redshift_us-east-1_mycluster_userlog_2013-10-29T18:01.gz`

如果您提供 Simple Storage Service（Amazon S3）键前缀，则该前缀放在密钥开头。

例如，如果指定前缀 myprefix：`myprefix/AWSLogs/123456789012/redshift/us-east-1/2013/10/29/123456789012_redshift_us-east-1_mycluster_userlog_2013-10-29T18:01.gz`

Simple Storage Service（Amazon S3）键前缀不得超过 512 个字符。其中不得包含空格（ ）、双引号（“）、单引号（‘）、反斜杠（\$1）。此外还有很多不得使用的特殊字符和控制字符。这些字符的十六进制代码如下：
+ x00 – x20
+ x 22
+ x 27
+ x5c
+ x7f 或更大

### Amazon S3 中的审计日志记录注意事项
<a name="db-auditing-failures"></a>

 Amazon Redshift 审计日志记录可能会因如下原因而中断：
+  Amazon Redshift 无权将日志上载到 Simple Storage Service（Amazon S3）存储桶中。验证相应存储桶是否配置了适当的 IAM 策略。有关更多信息，请参阅 [Amazon Redshift 审计日志记录的存储桶权限](#db-auditing-bucket-permissions)。
+  存储桶拥有者发生变化。当 Amazon Redshift 上载日志时，它会验证存储桶拥有者与启用日志记录时的存储桶拥有者是否相同。如果存储桶拥有者发生变化，则在您配置其他存储桶以用于审计日志记录之前，Amazon Redshift 不会上载日志。
+  找不到存储桶。如果相应存储桶在 Simple Storage Service（Amazon S3）中已被删除，则 Amazon Redshift 无法上载日志。您必须重新创建该存储桶，或对 Amazon Redshift 进行配置以将日志上载到其他存储桶。

### 使用 AWS CloudTrail 的 API 调用
<a name="rs-db-auditing-cloud-trail"></a>

Amazon Redshift 与 AWS CloudTrail 集成，后者是在 Amazon Redshift 中提供用户、角色或 AWS 服务所采取操作的记录的服务。CloudTrail 将 Amazon Redshift 的所有 API 调用作为事件捕获。有关 Amazon Redshift 与 AWS CloudTrail 集成的更多信息，请参阅[使用 CloudTrail 进行日志记录](https://docs.aws.amazon.com/redshift/latest/mgmt/logging-with-cloudtrail.html)。

您可以将 CloudTrail 与 Amazon Redshift 数据库审计日志记录一起使用，也可以单独使用前者。

要了解有关 CloudTrail 的更多信息，请参阅 [AWS CloudTrail 用户指南](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/)。

# 启用审计日志记录
<a name="db-auditing-console"></a>

配置 Amazon Redshift 以导出审计日志数据。日志可以导出到 CloudWatch，也可以作为文件导出到 Simple Storage Service (Amazon S3) 存储桶。

## 使用控制台启用审计日志记录
<a name="enable-auditing-logging-task"></a>

### 控制台步骤
<a name="cluster-audit-logging"></a>

**要启用集群的审计日志记录**

1. 登录到 AWS 管理控制台并打开 Amazon Redshift 控制台，网址：[https://console.aws.amazon.com/redshiftv2/](https://console.aws.amazon.com/redshiftv2/)。

1. 在导航菜单上，选择 **Clusters（集群）**，然后选择要更新的集群。

1. 选择 **Properties**（属性）选项卡。在 **Database configurations**（数据库配置）面板中，依次选择 **Edit**（编辑）和 **Edit audit logging**（编辑审计日志记录）。

1. 在 **Edit audit logging**（编辑审计日志记录）页上，选择 **Turn on**（打开）并选择 **S3 bucket**（S3 存储桶）或 **CloudWatch**。我们建议使用 CloudWatch，因为管理很简单，而且它具有实现数据可视化的有用功能。

1. 选择要导出的日志。

1. 要保存您的选择，请选择 **Save changes**（保存更改）。

# 安全日志记录
<a name="db-auditing-secure-logging"></a>

如果 Amazon Redshift 记录引用一个或多个 AWS Glue Data Catalog 视图的查询，则 Amazon Redshift 在记录有关该查询的元数据时，会自动屏蔽某些系统表列和视图列中的字段。

安全日志屏蔽适用于 Amazon Redshift 在运行符合屏蔽条件的查询时生成的所有系统表和视图条目。下表列出了应用了安全日志记录、用 `******` 屏蔽文本和用 `-1` 屏蔽数字的系统视图和列。用于屏蔽文本的星号数量与原始文本中的字符数相匹配，最多 6 个字符。长度超过 6 个字符的字符串仍显示为 6 个星号。


****  

| 系统表 | 敏感列 | 
| --- | --- | 
| [SYS\$1EXTERNAL\$1QUERY\$1DETAIL](https://docs.aws.amazon.com/redshift/latest/dg/SYS_EXTERNAL_QUERY_DETAIL.html) | **列：**source\$1type、total\$1partitions、qualified\$1partitions、scanned\$1files、returned\$1rows、returned\$1bytes、file\$1format、file\$1location、external\$1query\$1text、warning\$1message。 | 
| [SYS\$1EXTERNAL\$1QUERY\$1ERROR](https://docs.aws.amazon.com/redshift/latest/dg/SYS_EXTERNAL_QUERY_ERROR.html) | **列：**file\$1location、rowid、column\$1name、original\$1value、modified\$1value、trigger、action、action\$1value、error\$1code。 | 
| [SYS\$1QUERY\$1DETAIL](https://docs.aws.amazon.com/redshift/latest/dg/SYS_QUERY_DETAIL.html) | **列：**step\$1id、step\$1name、table\$1id、table\$1name、input\$1bytes、input\$1rows、output\$1bytes、output\$1rows、blocks\$1read、blocks\$1write、local\$1read\$1IO、remote\$1read\$1IO、spilled\$1block\$1local\$1disk、spilled\$1block\$1remote\$1disk、step\$1attribute。 | 
| [SYS\$1QUERY\$1HISTORY](https://docs.aws.amazon.com/redshift/latest/dg/SYS_QUERY_HISTORY.html) | **列：**returned\$1rows、returned\$1bytes。 | 
| [STL\$1AGGR](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_AGGR.html) | **列：**rows、bytes、tbl、type。 | 
| [STL\$1BCAST](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_BCAST.html) | **列：**rows、bytes、packets。 | 
| [STL\$1DDLTEXT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_DDLTEXT.html) | **列：**label、text。 | 
| [STL\$1DELETE](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_DELETE.html) | **列：**rows、tbl。 | 
| [STL\$1DIST](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_DIST.html) | **列：**rows、bytes、packets。 | 
| [STL\$1ERROR](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_ERROR.html) | **列：**file、linenum、context、error。 | 
| [STL\$1EXPLAIN](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_EXPLAIN.html) | **列：**plannode、info。 | 
| [STL\$1FILE\$1SCAN](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_FILE_SCAN.html) | **列：**name、line、bytes。 | 
| [STL\$1HASH](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_HASH.html) | **列：**rows、bytes、tbl、est\$1rows。 | 
| [STL\$1HASHJOIN](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_HASHJOIN.html) | **列：**rows、tbl、num\$1parts、join\$1type。 | 
| [STL\$1INSERT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_INSERT.html) | **列：**rows、tbl。 | 
| [STL\$1LIMIT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_LIMIT.html) | **列：**rows。 | 
| [STL\$1MERGE](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_MERGE.html) | **列：**rows。 | 
| [STL\$1MERGEJOIN](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_MERGEJOIN.html) | **列：**rows、tbl。 | 
| [STL\$1NESTLOOP](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_NESTLOOP.html) | **列：**rows、tbl。 | 
| [STL\$1PARSE](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_PARSE.html) | **列：**rows。 | 
| [STL\$1PLAN\$1INFO](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_PLAN_INFO.html) | **列：**startupcost、totalcost、rows、bytes。 | 
| [STL\$1PROJECT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_PROJECT.html) | **列：**rows、tbl。 | 
| [STL\$1QUERY](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_QUERY.html) | **列：**querytxt。 | 
| [STL\$1QUERY\$1METRICS](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_QUERY_METRICS.html) | **列：**max\$1rows、rows、max\$1blocks\$1read、blocks\$1read、max\$1blocks\$1to\$1disk、blocks\$1to\$1disk、max\$1query\$1scan\$1size、query\$1scan\$1size。 | 
| [STL\$1QUERYTEXT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_QUERYTEXT.html) | **列：**text。 | 
| [STL\$1RETURN](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_RETURN.html) | **列：**rows、bytes。 | 
| [STL\$1S3CLIENT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_S3CLIENT.html) | **列：**bucket、key、transfer\$1size、data\$1size。 | 
| [STL\$1S3CLIENT\$1ERROR](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_S3CLIENT_ERROR.html) | **列：**bucket、key、error、transfer\$1size。 | 
| [STL\$1SAVE](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_SAVE.html) | **列：**rows、bytes、tbl。 | 
| [STL\$1SCAN](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_SCAN.html) | **列：**rows、bytes、fetches、type、tbl、rows\$1pre\$1filter、rows\$1pre\$1user\$1filter、perm\$1table\$1name、scanned\$1mega\$1value。 | 
| [STL\$1SORT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_SORT.html) | **列：**rows、bytes、tbl。 | 
| [STL\$1SSHCLIENT\$1ERROR](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_SSHCLIENT_ERROR) | **列：**ssh\$1username、endpoint、command、error。 | 
| [STL\$1TR\$1CONFLICT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_TR_CONFLICT.html) | **列：**table\$1id。 | 
| [STL\$1UNDONE](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_UNDONE.html) | **列：**table\$1id。 | 
| [STL\$1UNIQUE](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_UNIQUE.html) | **列：**rows、type、bytes。 | 
| [STL\$1UTILITYTEXT](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_UTILITYTEXT.html) | **列：**label、text。 | 
| [STL\$1WINDOW](https://docs.aws.amazon.com/redshift/latest/dg/r_STL_WINDOW.html) | **列：**rows。 | 
| [STV\$1BLOCKLIST](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_BLOCKLIST.html) | **列：**col、tbl、num\$1values、minvalue、maxvalue。 | 
| [STV\$1EXEC\$1STATE](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_EXEC_STATE.html) | **列：**rows、bytes、label。 | 
| [STV\$1INFLIGHT](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_INFLIGHT.html) | **列：**label、text。 | 
| [STV\$1LOCKS](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_LOCKS.html) | **列：**table\$1id。 | 
| [STV\$1QUERY\$1METRICS](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_QUERY_METRICS.html) | **列：**rows、max\$1rows、blocks\$1read、max\$1blocks\$1read、max\$1blocks\$1to\$1disk、blocks\$1to\$1disk、max\$1query\$1scan\$1size、query\$1scan\$1size。 | 
| [STV\$1STARTUP\$1RECOVERY\$1STATE](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_STARTUP_RECOVERY_STATE.html) | **列：**table\$1id、table\$1name。 | 
| [STV\$1TBL\$1PERM](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_TBL_PERM.html) | **列：**id、name、rows、sorted\$1rows、temp、block\$1count、query\$1scan\$1size。 | 
| [STV\$1TBL\$1TRANS](https://docs.aws.amazon.com/redshift/latest/dg/r_STV_TBL_TRANS.html) | **列：**id、rows、size。 | 
| [SVCS\$1EXPLAIN](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_EXPLAIN.html) | **列：**plannode、info。 | 
| [SVCS\$1PLAN\$1INFO](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_PLAN_INFO.html) | **列：**rows、bytes。 | 
| [SVCS\$1QUERY\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_QUERY_SUMMARY.html) | **列：**step、rows、bytes、rate\$1row、rate\$1byte、label、rows\$1pre\$1filter。 | 
| [SVCS\$1S3LIST](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_S3LIST.html) | **列：**bucket、prefix、retrieved\$1files、max\$1file\$1size、avg\$1file\$1size。 | 
| [SVCS\$1S3LOG](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_S3LOG.html) | **列：**message。 | 
| [SVCS\$1S3PARTITION\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_S3PARTITION_SUMMARY.html) | **列：**total\$1partitions、qualified\$1partitions、min\$1assigned\$1partitions、max\$1assigned\$1partitions、avg\$1assigned\$1partitions。 | 
| [SVCS\$1S3QUERY\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVCS_S3QUERY_SUMMARY.html) | **列：**external\$1table\$1name、file\$1format、s3\$1scanned\$1rows、s3\$1scanned\$1bytes、s3query\$1returned\$1rows、s3query\$1returned\$1bytes。 | 
| [SVL\$1QUERY\$1METRICS](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_METRICS.html) | **列：**step\$1label、scan\$1row\$1count、join\$1row\$1count、nested\$1loop\$1join\$1row\$1count、return\$1row\$1count、spectrum\$1scan\$1row\$1count、spectrum\$1scan\$1size\$1mb。 | 
| [SVL\$1QUERY\$1METRICS\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_METRICS_SUMMARY.html) | **列：**step\$1label、scan\$1row\$1count、join\$1row\$1count、nested\$1loop\$1join\$1row\$1count、return\$1row\$1count、spectrum\$1scan\$1row\$1count、spectrum\$1scan\$1size\$1mb。 | 
| [SVL\$1QUERY\$1REPORT](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_REPORT.html) | **列：**rows、bytes、label、rows\$1pre\$1filter。 | 
| [SVL\$1QUERY\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_SUMMARY.html) | **列：**rows、bytes、rows\$1pre\$1filter。 | 
| [SVL\$1S3LIST](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3LIST.html) | **列：**bucket、prefix、retrieved\$1files、max\$1file\$1size、avg\$1file\$1size。 | 
| [SVL\$1S3LOG](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3LOG.html) | **列：**message。 | 
| [SVL\$1S3PARTITION](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3PARTITION.html) | **列：**rows、bytes、label、rows\$1pre\$1filter。 | 
| [SVL\$1S3PARTITION\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3PARTITION_SUMMARY.html) | **列：**total\$1partitions、qualified\$1partitions、min\$1assigned\$1partitions、max\$1assigned\$1partitions、avg\$1assigned\$1partitions。 | 
| [SVL\$1S3QUERY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3QUERY.html) | **列：**external\$1table\$1name、file\$1format、s3\$1scanned\$1rows、s3\$1scanned\$1bytes、s3query\$1returned\$1rows、s3query\$1returned\$1bytes、files。 | 
| [SVL\$1S3QUERY\$1SUMMARY](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3QUERY_SUMMARY.html) | **列：**external\$1table\$1name、file\$1format、s3\$1scanned\$1rows、s3\$1scanned\$1bytes、s3query\$1returned\$1rows、s3query\$1returned\$1bytes。 | 
| [SVL\$1S3RETRIES](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_S3RETRIES.html) | **列：**file\$1size、location、message。 | 
| [SVL\$1SPECTRUM\$1SCAN\$1ERROR](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_SPECTRUM_SCAN_ERROR.html) | **列：**location、rowid、colname、original\$1value、modified\$1value、trigger、action、action\$1value、error\$1code。 | 
| [SVL\$1STATEMENTTEXT](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_STATEMENTTEXT.html) | **列：**type、text。 | 
| [SVL\$1STORED\$1PROC\$1CALL](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_STORED_PROC_CALL.html) | **列：**querytxt。 | 
| [SVL\$1STORED\$1PROC\$1MESSAGES](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_STORED_PROC_MESSAGES.html) | **列：**message、linenum、querytext。 | 
| [SVL\$1UDF\$1LOG](https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_UDF_LOG.html) | **列：**message、funcname。 | 
| [SVV\$1DISKUSAGE](https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_DISKUSAGE.html) | **列：**name、col、tbl、blocknum、num\$1values、minvalue、maxvalue。 | 
| [SVV\$1QUERY\$1STATE](https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_QUERY_STATE.html) | **列：**rows、bytes、label。 | 
| [SVV\$1TABLE\$1INFO](https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_TABLE_INFO.html) | **列：**table\$1id、table。 | 
| [SVV\$1TRANSACTIONS](https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_TRANSACTIONS.html) | **列：**relation。 | 

有关系统表和视图的更多信息，请参阅《Amazon Redshift 数据库开发人员指南》**中的[系统表和视图参考](https://docs.aws.amazon.com/redshift/latest/dg/cm_chap_system-tables.html)。有关 Amazon Redshift 的动态屏蔽查询结果的功能的信息，请参阅《Amazon Redshift 数据库开发人员指南》**中的[动态数据掩蔽](https://docs.aws.amazon.com/redshift/latest/dg/t_ddm.html)。有关使用 Amazon Redshift 在 AWS Glue Data Catalog 中创建视图的信息，请参阅《Amazon Redshift 数据库开发人员指南》**中的 [AWS Glue Data Catalog 视图](https://docs.aws.amazon.com/redshift/latest/dg/data-catalog-views-overview.html)。

# 使用 Cloudtrail 进行日志记录
<a name="logging-with-cloudtrail"></a>

Amazon Redshift、数据共享、Amazon Redshift Serverless、Amazon Redshift 数据 API 和查询编辑器 v2 都与 AWS CloudTrail 集成。CloudTrail 服务提供用户、角色或 AWS 服务在 Amazon Redshift 中所执行的操作的记录。CloudTrail 将 Amazon Redshift 的所有 API 调用作为事件捕获。捕获的调用包括通过 Redshift 控制台进行的调用以及对 Redshift 操作的代码调用。

如果您创建 CloudTrail 跟踪记录，则可以让 CloudTrail 事件持续传送到 Amazon S3 桶（包括 Redshift 的事件）。如果您不配置跟踪记录，则仍可在 CloudTrail 控制台中的 **Event history（事件历史记录）**中查看最新事件。通过使用 CloudTrail 收集的信息，您可以确定某些事项。这些事项包括向 Redshift 发出的请求、发出请求的 IP 地址、何人发出的请求、请求的发出时间，以及其他详细信息。

您可以将 CloudTrail 与 Amazon Redshift 数据库审计日志记录一起使用，也可以单独使用前者。

要了解有关 CloudTrail 的更多信息，请参阅 [AWS CloudTrail 用户指南](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/)。

## CloudTrail 中的 信息
<a name="working-with-info-in-cloudtrail"></a>

在您创建账户时，您的 AWS 账户中已启用 CloudTrail。发生活动时，该活动将记录在 CloudTrail 事件中，并与其他 AWS 服务事件一同保存在 **Event history**（事件历史记录）中。您可以在 AWS 账户中查看、搜索和下载最新事件。有关更多信息，请参阅《AWS CloudTrail 用户指南》**中的[使用 CloudTrail 事件历史记录查看事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。

要持续记录 AWS 账户中的事件（包括 Redshift 的事件），请创建跟踪记录。CloudTrail 使用*跟踪记录* 将日志文件传送至 Amazon S3 桶。预设情况下，在控制台中创建跟踪时，此跟踪应用于所有 AWS 区域。此跟踪记录在 AWS 分区中记录所有区域中的事件，并将日志文件传送至您指定的 Amazon S3 存储桶。此外，您可以配置其他AWS服务，进一步分析在 CloudTrail 日志中收集的事件数据并采取行动。有关更多信息，请参阅《AWS CloudTrail 用户指南》**中的以下内容：
+ [创建跟踪概览](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)
+ [CloudTrail 支持的服务和集成](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-aws-service-specific-topics.html#cloudtrail-aws-service-specific-topics-integrations)
+ [为 CloudTrail 配置 Amazon SNS 通知](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/getting_notifications_top_level.html)
+ [从多个区域接收 CloudTrail 日志文件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html)和[从多个账户接收 CloudTrail 日志文件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html)

所有 Amazon Redshift、Amazon Redshift Serverless、数据 API、数据共享和查询编辑器 v2 操作都由 CloudTrail 记录。例如，对 `AuthorizeDatashare`、`CreateNamespace`、`ExecuteStatement` 和 `CreateConnection` 操作的调用将在 CloudTrail 日志文件中生成条目。

每个事件或日志条目都包含有关生成请求的人员信息。身份信息有助于您确定以下内容：
+ 请求是使用根凭证还是用户凭证发出的。
+ 请求是使用角色还是联合用户的临时安全凭证发出的。
+ 请求是否由其他AWS服务发出。

有关更多信息，请参阅《AWS CloudTrail 用户指南》**中的 [CloudTrail userIdentity 元素](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html)。

## 日志文件条目
<a name="understanding-cloudtrail-log-files"></a>

*跟踪记录* 是一种配置，允许将事件作为日志文件传送到您指定的 Amazon S3 桶。CloudTrail 日志文件包含一个或多个日记账条目。一个*事件*表示来自任何源的一个请求，包括有关所请求的操作、操作的日期和时间、请求参数等方面的信息。CloudTrail 日志文件不是公用 API 调用的有序堆栈跟踪，因此它们不会按任何特定顺序显示。

## Amazon Redshift 数据共享示例
<a name="datashare-cloudtrail-example"></a>

下面的示例显示了一个 CloudTrail 日志条目，该条目说明了 `AuthorizeDataShare` 操作。

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AKIAIOSFODNN7EXAMPLE:janedoe",
        "arn": "arn:aws:sts::111122223333:user/janedoe",
        "accountId": "111122223333",
        "accessKeyId": "AKIAI44QH8DHBEXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AKIAIOSFODNN7EXAMPLE:janedoe",
                "arn": "arn:aws:sts::111122223333:user/janedoe",
                "accountId": "111122223333",
                "userName": "janedoe"
            },
            "attributes": {
                "creationDate": "2021-08-02T23:40:45Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2021-08-02T23:40:58Z",
    "eventSource": "redshift.amazonaws.com",
    "eventName": "AuthorizeDataShare",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "3.227.36.75",
    "userAgent":"aws-cli/1.18.118 Python/3.6.10 Linux/4.9.217-0.1.ac.205.84.332.metal1.x86_64 botocore/1.17.41", 
    "requestParameters": {
        "dataShareArn": "arn:aws:redshift:us-east-1:111122223333:datashare:4c64c6ec-73d5-42be-869b-b7f7c43c7a53/testshare",
        "consumerIdentifier": "555555555555"
    },
    "responseElements": {
        "dataShareArn": "arn:aws:redshift:us-east-1:111122223333:datashare:4c64c6ec-73d5-42be-869b-b7f7c43c7a53/testshare",
        "producerNamespaceArn": "arn:aws:redshift:us-east-1:123456789012:namespace:4c64c6ec-73d5-42be-869b-b7f7c43c7a53",
        "producerArn": "arn:aws:redshift:us-east-1:111122223333:namespace:4c64c6ec-73d5-42be-869b-b7f7c43c7a53",
        "allowPubliclyAccessibleConsumers": true,
        "dataShareAssociations": [
            {
                "consumerIdentifier": "555555555555",
                "status": "AUTHORIZED",
                "createdDate": "Aug 2, 2021 11:40:56 PM",
                "statusChangeDate": "Aug 2, 2021 11:40:57 PM"
            }
        ]
    },
    "requestID": "87ee1c99-9e41-42be-a5c4-00495f928422",
    "eventID": "03a3d818-37c8-46a6-aad5-0151803bdb09",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "111122223333",
    "eventCategory": "Management"
}
```

## Amazon Redshift Serverless 示例
<a name="serverless-cloudtrail-example"></a>

Amazon Redshift Serverless 与 AWS CloudTrail 集成，以提供在 Amazon Redshift Serverless 中执行的操作的记录。CloudTrail 将 Amazon Redshift Serverless 的所有 API 调用作为事件捕获。有关 Amazon Redshift Serverless 功能的更多信息，请参阅 [Amazon Redshift Serverless 功能概览](https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-considerations.html)。

下面的示例显示了一个 CloudTrail 日志条目，该条目演示了 `CreateNamespace` 操作。

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AAKEOFPINEXAMPLE:admin",
        "arn": "arn:aws:sts::111111111111:assumed-role/admin/admin",
        "accountId": "111111111111",
        "accessKeyId": "AAKEOFPINEXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AAKEOFPINEXAMPLE",
                "arn": "arn:aws:iam::111111111111:role/admin",
                "accountId": "111111111111",
                "userName": "admin"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2022-03-21T20:51:58Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2022-03-21T23:15:40Z",
    "eventSource": "redshift-serverless.amazonaws.com",
    "eventName": "CreateNamespace",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "56.23.155.33",
    "userAgent": "aws-cli/2.4.14 Python/3.8.8 Linux/5.4.181-109.354.amzn2int.x86_64 exe/x86_64.amzn.2 prompt/off command/redshift-serverless.create-namespace",
    "requestParameters": {
        "adminUserPassword": "HIDDEN_DUE_TO_SECURITY_REASONS",
        "adminUsername": "HIDDEN_DUE_TO_SECURITY_REASONS",
        "dbName": "dev",
        "namespaceName": "testnamespace"
    },
    "responseElements": {
        "namespace": {
            "adminUsername": "HIDDEN_DUE_TO_SECURITY_REASONS",
            "creationDate": "Mar 21, 2022 11:15:40 PM",
            "defaultIamRoleArn": "",
            "iamRoles": [],
            "logExports": [],
            "namespaceArn": "arn:aws:redshift-serverless:us-east-1:111111111111:namespace/befa5123-16c2-4449-afca-1d27cb40fc99",
            "namespaceId": "8b726a0c-16ca-4799-acca-1d27cb403599",
            "namespaceName": "testnamespace",
            "status": "AVAILABLE"
        }
    },
    "requestID": "ed4bb777-8127-4dae-aea3-bac009999163",
    "eventID": "1dbee944-f889-4beb-b228-7ad0f312464",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "111111111111",
    "eventCategory": "Management",
}
```

## Amazon Redshift 数据 API 示例
<a name="data-api-cloudtrail"></a>

下面的示例显示了一个 CloudTrail 日志条目，该条目演示了 `ExecuteStatement` 操作。

```
{
    "eventVersion":"1.05",
    "userIdentity":{
        "type":"IAMUser",
        "principalId":"AKIAIOSFODNN7EXAMPLE:janedoe",
        "arn":"arn:aws:sts::123456789012:user/janedoe",
        "accountId":"123456789012",
        "accessKeyId":"AKIAI44QH8DHBEXAMPLE",
        "userName": "janedoe"
    },
    "eventTime":"2020-08-19T17:55:59Z",
    "eventSource":"redshift-data.amazonaws.com",
    "eventName":"ExecuteStatement",
    "awsRegion":"us-east-1",
    "sourceIPAddress":"192.0.2.0",
    "userAgent":"aws-cli/1.18.118 Python/3.6.10 Linux/4.9.217-0.1.ac.205.84.332.metal1.x86_64 botocore/1.17.41",
    "requestParameters":{
        "clusterIdentifier":"example-cluster-identifier",
        "database":"example-database-name",
        "dbUser":"example_db_user_name",
        "sql":"***OMITTED***"
    },
    "responseElements":{
        "clusterIdentifier":"example-cluster-identifier",
        "createdAt":"Aug 19, 2020 5:55:58 PM",
        "database":"example-database-name",
        "dbUser":"example_db_user_name",
        "id":"5c52b37b-9e07-40c1-98de-12ccd1419be7"
    },
    "requestID":"00c924d3-652e-4939-8a7a-cd0612eeb8ac",
    "eventID":"c1fb7076-102f-43e5-9ec9-40820bcc1175",
    "readOnly":false,
    "eventType":"AwsApiCall",
    "recipientAccountId":"123456789012"
}
```

下面的示例显示了一个 CloudTrail 日志条目，该条目说明了 `ExecuteStatement` 操作，显示了幂等性所用的 `clientToken`。

```
{
    "eventVersion":"1.05",
    "userIdentity":{
        "type":"IAMUser",
        "principalId":"AKIAIOSFODNN7EXAMPLE:janedoe",
        "arn":"arn:aws:sts::123456789012:user/janedoe",
        "accountId":"123456789012",
        "accessKeyId":"AKIAI44QH8DHBEXAMPLE",
        "userName": "janedoe"
    },
    "eventTime":"2020-08-19T17:55:59Z",
    "eventSource":"redshift-data.amazonaws.com",
    "eventName":"ExecuteStatement",
    "awsRegion":"us-east-1",
    "sourceIPAddress":"192.0.2.0",
    "userAgent":"aws-cli/1.18.118 Python/3.6.10 Linux/4.9.217-0.1.ac.205.84.332.metal1.x86_64 botocore/1.17.41",
    "requestParameters":{
        "clusterIdentifier":"example-cluster-identifier",
        "database":"example-database-name",
        "dbUser":"example_db_user_name",
        "sql":"***OMITTED***",
        "clientToken":"32db2e10-69ac-4534-b3fc-a191052616ce"
    },
    "responseElements":{
        "clusterIdentifier":"example-cluster-identifier",
        "createdAt":"Aug 19, 2020 5:55:58 PM",
        "database":"example-database-name",
        "dbUser":"example_db_user_name",
        "id":"5c52b37b-9e07-40c1-98de-12ccd1419be7"
    },
    "requestID":"00c924d3-652e-4939-8a7a-cd0612eeb8ac",
    "eventID":"c1fb7076-102f-43e5-9ec9-40820bcc1175",
    "readOnly":false,
    "eventType":"AwsApiCall",
    "recipientAccountId":"123456789012"
}
```

## Amazon Redshift 查询编辑器 v2 示例
<a name="query-editor-cloudtrail"></a>

下面的示例显示了一个 CloudTrail 日志条目，该条目演示了 `CreateConnection` 操作。

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AAKEOFPINEXAMPLE:session",
        "arn": "arn:aws:sts::123456789012:assumed-role/MyRole/session",
        "accountId": "123456789012",
        "accessKeyId": "AKIAI44QH8DHBEXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AAKEOFPINEXAMPLE",
                "arn": "arn:aws:iam::123456789012:role/MyRole",
                "accountId": "123456789012",
                "userName": "MyRole"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2022-09-21T17:19:02Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2022-09-21T22:22:05Z",
    "eventSource": "sqlworkbench.amazonaws.com",
    "eventName": "CreateConnection",
    "awsRegion": "ca-central-1",
    "sourceIPAddress": "192.2.0.2",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0",
    "requestParameters": {
        "password": "***",
        "databaseName": "***",
        "isServerless": false,
        "name": "***",
        "host": "redshift-cluster-2.c8robpbxvbf9.ca-central-1.redshift.amazonaws.com",
        "authenticationType": "***",
        "clusterId": "redshift-cluster-2",
        "username": "***",
        "tags": {
            "sqlworkbench-resource-owner": "AAKEOFPINEXAMPLE:session"
        }
    },
    "responseElements": {
        "result": true,
        "code": "",
        "data": {
            "id": "arn:aws:sqlworkbench:ca-central-1:123456789012:connection/ce56b1be-dd65-4bfb-8b17-12345123456",
            "name": "***",
            "authenticationType": "***",
            "databaseName": "***",
            "secretArn": "arn:aws:secretsmanager:ca-central-1:123456789012:secret:sqlworkbench!7da333b4-9a07-4917-b1dc-12345123456-qTCoFm",
            "clusterId": "redshift-cluster-2",
            "dbUser": "***",
            "userSettings": "***",
            "recordDate": "2022-09-21 22:22:05",
            "updatedDate": "2022-09-21 22:22:05",
            "accountId": "123456789012",
            "tags": {
                "sqlworkbench-resource-owner": "AAKEOFPINEXAMPLE:session"
            },
            "isServerless": false
        }
    },
    "requestID": "9b82f483-9c03-4cdd-bb49-a7009e7da714",
    "eventID": "a7cdd442-e92f-46a2-bc82-2325588d41c3",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "eventCategory": "Management"
}
```

## AWS CloudTrail 日志中的 Amazon Redshift 账户 ID
<a name="cloudtrail-rs-acct-ids"></a>

当 Amazon Redshift 为您调用其他 AWS 服务时，该次调用将以属于 Amazon Redshift 的账户 ID 记录下来。它未以您的账户 ID 记录。例如，假设 Amazon Redshift 调用 AWS Key Management Service（AWS KMS）操作（如 `CreateGrant`、`Decrypt`、`Encrypt` 和 `RetireGrant`）以管理集群上的加密。在这种情况下，调用由 AWS CloudTrail 使用 Amazon Redshift 账户 ID 记录。

当调用其他 AWS 服务时，Amazon Redshift 使用下表中的账户 ID。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/redshift/latest/mgmt/logging-with-cloudtrail.html)

以下示例显示了 Amazon Redshift 所调用的 AWS KMS Decrypt 操作的 CloudTrail 日志条目。

```
{

    "eventVersion": "1.05",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AROAI5QPCMKLTL4VHFCYY:i-0f53e22dbe5df8a89",
        "arn": "arn:aws:sts::790247189693:assumed-role/prod-23264-role-wp/i-0f53e22dbe5df8a89",
        "accountId": "790247189693",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "sessionContext": {
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2017-03-03T16:24:54Z"
            },
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AROAI5QPCMKLTL4VHFCYY",
                "arn": "arn:aws:iam::790247189693:role/prod-23264-role-wp",
                "accountId": "790247189693",
                "userName": "prod-23264-role-wp"
            }
        }
    },
    "eventTime": "2017-03-03T17:16:51Z",
    "eventSource": "kms.amazonaws.com",
    "eventName": "Decrypt",
    "awsRegion": "us-east-2",
    "sourceIPAddress": "52.14.143.61",
    "userAgent": "aws-internal/3",
    "requestParameters": {
        "encryptionContext": {
            "aws:redshift:createtime": "20170303T1710Z",
            "aws:redshift:arn": "arn:aws:redshift:us-east-2:123456789012:cluster:my-dw-instance-2"
        }
    },
    "responseElements": null,
    "requestID": "30d2fe51-0035-11e7-ab67-17595a8411c8",
    "eventID": "619bad54-1764-4de4-a786-8898b0a7f40c",
    "readOnly": true,
    "resources": [
        {
            "ARN": "arn:aws:kms:us-east-2:123456789012:key/f8f4f94f-e588-4254-b7e8-078b99270be7",
            "accountId": "123456789012",
            "type": "AWS::KMS::Key"
        }
    ],
    "eventType": "AwsApiCall",
    "recipientAccountId": "123456789012",
    "sharedEventID": "c1daefea-a5c2-4fab-b6f4-d8eaa1e522dc"

}
```