

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 將查詢歷史記錄保留 45 天以上
<a name="querying-keeping-query-history"></a>

若要將查詢歷史記錄保留 45 天以上，您可以擷取查詢歷史記錄，並將其儲存至資料存放區，例如 Amazon S3。若要自動執行此程序，您可以使用 Athena 和 Amazon S3 API 動作以及 CLI 命令。下列程序概述這些步驟。

**使用程式擷取和儲存查詢歷史記錄的步驟**

1. 使用 Athena [ListQueryExecutions](https://docs.aws.amazon.com/athena/latest/APIReference/API_ListQueryExecutions.html) API 動作或 [list-query-executions](https://docs.aws.amazon.com/cli/latest/reference/athena/list-query-executions.html) CLI 命令來擷取查詢 ID。

1. 使用 Athena [GetQueryExecution](https://docs.aws.amazon.com/athena/latest/APIReference/API_GetQueryExecution.html) API 動作或 [get-query-execution](https://docs.aws.amazon.com/cli/latest/reference/athena/get-query-execution.html) CLI 命令，根據其 ID 擷取每個查詢的相關資訊。

1. 使用 Amazon S3 [PutObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html) API 動作或 [put-object](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html) CLI 命令，將資訊儲存在 Amazon S3 中。