使用自定义生存时间(TTL)更新表 - Amazon Keyspaces(Apache Cassandra 兼容)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用自定义生存时间(TTL)更新表

要在不为整个表设置 TTL 默认值的情况下为表启用生存时间自定义设置,以便 TTL 值可应用于各个行和列,可以使用以下命令。

注意

为表启用 ttl 后便无法禁用该设置。

Cassandra Query Language (CQL)
使用 CQL 为表启用自定义 TTL 设置
  • ALTER TABLE my_table WITH CUSTOM_PROPERTIES={'ttl':{'status': 'enabled'}};
CLI
使用 Amazon CLI 为表启用自定义 TTL 设置
  1. 可以使用以下命令来更新表的自定义 TTL 设置。

    aws keyspaces update-table --keyspace-name 'myKeyspace' --table-name 'myTable' --ttl 'status=ENABLED'
  2. 要确认现已为表启用 TTL,可以使用以下语句。

    aws keyspaces get-table --keyspace-name 'myKeyspace' --table-name 'myTable'

    语句输出应类似于以下示例。

    { "keyspaceName": "myKeyspace", "tableName": "myTable", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/myKeyspace/table/myTable", "creationTimestamp": "2024-09-02T11:32:27.349000+00:00", "status": "ACTIVE", "schemaDefinition": { "allColumns": [ { "name": "id", "type": "int" }, { "name": "date", "type": "timestamp" }, { "name": "name", "type": "text" } ], "partitionKeys": [ { "name": "id" } ], "clusteringKeys": [], "staticColumns": [] }, "capacitySpecification": { "throughputMode": "PAY_PER_REQUEST", "lastUpdateToPayPerRequestTimestamp": "2024-09-02T11:32:27.349000+00:00" }, "encryptionSpecification": { "type": "AWS_OWNED_KMS_KEY" }, "pointInTimeRecovery": { "status": "DISABLED" }, "ttl": { "status": "ENABLED" }, "defaultTimeToLive": 0, "comment": { "message": "" }, "replicaSpecifications": [] }