다음을 통해 공유


Microsoft Fabric의 Cosmos DB에서 TTL(Time to Live) 구성(미리 보기)

중요합니다

이 기능은 프리뷰 상태입니다.

Cosmos DB의 TTL(Time-to-Live) 기능을 사용하면 지정된 기간 후에 항목을 자동으로 삭제하여 데이터의 수명 주기를 관리할 수 있습니다. 이 가이드에서는 패브릭 포털 또는 Azure SDK를 사용하여 컨테이너 및 항목 수준에서 TTL 값을 수정합니다.

필수 조건

  • Python 3.12 이상
  • Node.js 22 이상
  • .NET SDK 9.0 이상

패브릭 포털을 사용하여 컨테이너 수준에서 설정

먼저 패브릭 포털을 사용하여 컨테이너 수준 TTL을 설정합니다.

  1. Fabric 포털(https://app.fabric.microsoft.com)을 엽니다.

  2. 기존 Cosmos DB 데이터베이스로 이동합니다.

  3. 기존 컨테이너를 선택하고 확장합니다. 그런 다음 설정을 선택합니다.

  4. 설정 섹션에서 중복 설정 탭을 선택합니다.

  5. TL(Time to Live) 설정을 찾습니다.

    패브릭 포털의 데이터베이스 내 컨테이너에 대한 '설정' 섹션의 스크린샷.

  6. 설정을 새 값으로 업데이트합니다. 예를 들어 값을 On(기본값 없음)으로 설정하여 컨테이너 수준에서 기본 TTL을 -1(무한대)로 설정할 수 있으며, 이 경우 TTL이 활성화되지만 항목은 기본적으로 만료되지 않습니다.

  7. 저장을 선택하여 변경 내용을 유지합니다.

    팁 (조언)

    다양한 TTL(Time to Live) 구성 값에 대한 자세한 내용은 TTL( Time to Live)을 참조하세요.

항목 수준에서 설정

다음으로 항목을 업데이트하여 항목 수준에서 TTL 값을 설정합니다. Cosmos DB 내의 항목은 JSON 문서로 표시됩니다. ttl 각 문서의 속성은 각 특정 항목의 TSL(Time to Live)을 설정하는 데 사용됩니다. 속성을 ttl 설정하거나 설정할 수 없으며 해당 값은 TTL 만료 동작에 영향을 줍니다.

[
  {
    "name": "Heatker Women's Jacket",
    "category": "apparel"
  },
  {
    "name": "Vencon Kid's Coat",
    "category": "apparel",
    "ttl": -1
  },
  {
    "name": "Pila Swimsuit",
    "category": "apparel",
    "ttl": 3600
  }
]

Azure SDK를 사용하여 컨테이너 수준에서 설정

이제 Azure SDK를 사용하여 컨테이너 수준에서 TTL을 설정하여 모든 항목에 적용합니다.

database = client.get_database_client("<database-name>")

container = database.get_container_client("<container-name>")

# Set the container-level TTL to 7 days
database.replace_container(container, partition_key=PartitionKey(path='/<partition-key-path>'), default_ttl=60 * 60 * 24 * 7)
const container: Container = client.database('<database-name>').container('<container-name>');

const { resource: containerProperties } = await container.read();

if (!containerProperties) {
    return;
}

// Set the container-level TTL to 7 days
containerProperties.defaultTtl = 60 * 60 * 24 * 7;

await container.replace(containerProperties);
Container container = client
    .GetDatabase("<database-name>")
    .GetContainer("<container-name>");

ContainerProperties properties = await container.ReadContainerAsync();

// Set the container-level TTL to 7 days
properties.DefaultTimeToLive = 60 * 60 * 24 * 7;

await container.ReplaceContainerAsync(properties);

Azure SDK를 사용하여 항목 수준에서 설정

마지막으로 Azure SDK를 다시 사용하여 컨테이너 수준 값을 재정의하도록 항목 수준 TTL 값을 설정합니다.

container = client.get_database_client("<database-name>").get_container_client("<container-name>")

# Set the item-level TTL to 1 day
item = {
    "id": "ffffffff-5555-6666-7777-aaaaaaaaaaaa",
    "name": "Pila Swimsuit",
    "category": "apparel",
    "ttl": 60 * 60 * 24
}

container.upsert_item(item)
const container: Container = client.database('<database-name>').container('<container-name>');

// Set the item-level TTL to 1 day
let item = {
    id: 'ffffffff-5555-6666-7777-aaaaaaaaaaaa',
    name: 'Pila Swimsuit',
    category: 'apparel',
    ttl: 60 * 60 * 24
};

await container.items.upsert(item);
Container container = client
    .GetDatabase("<database-name>")
    .GetContainer("<container-name>");

// Set the item-level TTL to 1 day
var item = new {
    id = "ffffffff-5555-6666-7777-aaaaaaaaaaaa",
    name = "Pila Swimsuit",
    category = "apparel",
    ttl = 60 * 60 * 24
};

await container.UpsertItemAsync(item);