{
  "run_id": "2026-09-21-r3-youcom",
  "round": 2,
  "tool": "youcom",
  "mode": "search",
  "tc_id": "TC3",
  "capability": "C1",
  "scenario": "S3",
  "suite_role": "probe",
  "query_text": "In Loki, the log aggregation system from Grafana Labs, which configuration block does retention_enabled have to be set in for old log data to actually be deleted?",
  "restrict_domain": null,
  "restriction_mechanism": null,
  "answer_key": "The compactor block. Verbatim: \"`retention_enabled: true` must be set under the `compactor` block, not just in `limits_config`.\" (FAQ \"Why isn't my log retention policy deleting old data?\", bottom third of the page.)",
  "key_urls": [
    {
      "url": "https://grafana.com/docs/loki/",
      "role": "supports"
    },
    {
      "url": "https://grafana.com/oss/loki/",
      "role": "supports"
    }
  ],
  "pass_criteria": "Results are about Grafana Loki, not Marvel's Loki, AND what came back names the compactor block - not merely the top-of-page description of what Loki is",
  "key_verified_date": "2026-09-09",
  "before_check_rule": null,
  "timestamp_utc": "2026-09-21T11:49:51Z",
  "region": "ap-south-1",
  "status": "ok",
  "graded": null,
  "pass_fail": null,
  "grader_notes": null,
  "latency_ms": 13197.1,
  "http_status": 200,
  "error": null,
  "attempts": 1,
  "results": [
    {
      "rank": 1,
      "url": "https://grafana.com/docs/loki/latest/operations/storage/retention/",
      "title": "Log retention | Grafana Loki documentation",
      "content": "![ObservabilityCON 2025](https://a-us.storyblok.com/f/1022730/280x40/b0872b99f9/grafana-logo-observabilitycon-2025-black.svg/m/)\n\nWatch the keynote again and signup for more on-demand sessions.\n\n\n[Watch keynote](https://grafana.com/events/observabilitycon/?plcmt=obscon2025-post-event-banner)![](https://grafana.com/media/events/grafanacon/2025/icon-close-x.svg)\n\n![ObservabilityCON 2025](https://grafana.com/media/events/obscon/2025/grafana-obscon2025-promo-logo-black.svg)\n\n\ud83d\udce2 Registration + agenda now live\nExplore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).\n\n\n[Register now](https://grafana.com/events/observabilitycon/?tech=target&plcmt=top-banner&aud=default)\n\nSearching...\n\nSite search\n\nAsk Grot AI\n\n[Try using ![Grot AI](https://grafana.com/static/img/grot-chat.svg)**Grot AI** for this query ->](https://grafana.com/grot/?chat=&from=/search)\n\nAll\n\nDocs\n\nView all results\n\nNo results.\n\nThere was an error with your request.\n\n> Documentation for automated readers\n>\n> A curated documentation index is available at: https://grafana.com/llms.txt\n>\n> A complete documentation index is available at: https://grafana.com/llms-full.txt\n>\n> These indexes can help with page discovery before fetching individual documents.\n\nThis page is also available in Markdown, which may be easier for automated readers\nand AI tools to parse than HTML. The Markdown version is available at\nhttps://grafana.com/docs/loki/latest/operations/storage/retention.md, or by sending\nAccept: text/markdown to https://grafana.com/docs/loki/latest/operations/storage/retention/. For broader\ndocumentation discovery, the curated index is available at https://grafana.com/llms.txt\nand the complete index is available at https://grafana.com/llms-full.txt.\n\nLog retention\n\n[Documentation](https://grafana.com/docs/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Grafana Loki](https://grafana.com/docs/loki/latest/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Manage](https://grafana.com/docs/loki/latest/operations/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Storage](https://grafana.com/docs/loki/latest/operations/storage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)Log retention\n\nOpen source\n\n# Log retention\n\nRetention in Grafana Loki is achieved through the [Compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor).\nBy default the `compactor.retention-enabled` flag is not set, so the logs sent to Loki live forever.\n\n> Note\n>\n> If you have a lifecycle policy configured on the object store, please ensure that it is longer than the retention period.\n\nGranular retention policies to apply retention at per tenant or per stream level are also supported by the Compactor.\n\n> Note\n>\n> The Compactor does not support retention on\n> [legacy index types](https://grafana.com/docs/loki/latest/configure/storage/#index-storage). Please use the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) when using legacy index types.\n> Both the Table manager and legacy index types are deprecated and may be removed in future major versions of Loki.\n\n## Compactor\n\nThe Compactor is responsible for compaction of index files and applying log retention.\n\n> Note\n>\n> Run the Compactor as a singleton (a single instance).\n\nThe Compactor runs compaction and retention on two independent schedules:\n\n- Compaction runs every `compactor.compaction-interval`.\n- Retention runs every `compactor.apply-retention-interval`. If you leave this at its default of `0s`, Loki sets it to the same value as `compactor.compaction-interval`. Whenever the two intervals are equal, Loki extends the retention interval by the smaller of `10m` or half the interval, so that compaction and retention do not run at the same time. For example, with the default `compaction_interval` of `10m`, retention runs every `15m`.\n\nIf the Compactor falls behind on either schedule, it runs the corresponding operation as soon as possible.\nBoth compaction and retention are idempotent, which means once the action has been performed, if the action is performed multiple times, it has no further effect on logs after the first time it is performed. If the Compactor restarts, it continues from where it left off.\n\n> Note\n>\n> Changes to your retention period are not retroactive, that is, they are not applied to logs that have already been ingested.\n\nThe Compactor\u2019s algorithm to apply retention is as follows:\n\n- For each day or table (one table per day with 24h index period):\n  - Compact multiple index files in the table into per-tenant index files. Result of compaction is a single index file per tenant per day.\n  - Traverse the per-tenant index. Use the tenant configuration to identify the chunks that need to be removed.\n  - Remove the references to the matching chunks from the index and add the chunk references to a marker file on disk.\n  - Upload the new modified index files.\n\nChunks are not deleted while applying the retention algorithm on the index. They are deleted asynchronously by a sweeper process\nand this delay can be configured by setting `-compactor.retention-delete-delay`. Marker files are used to keep track of the chunks pending for deletion.\n\nChunks cannot be deleted immediately for the following reasons:\n\n- Index Gateway downloads a copy of the index files to serve queries and refreshes them at a regular interval.\nHaving a delay allows the index gateways to pull the modified index file which would not contain any reference to the chunks marked for deletion.\nWithout the delay, index files (that are stale) on the gateways could refer to already deleted chunks leading to query failures.\n\n- It provides a short window of time in which to cancel chunk deletion in the case of a configuration mistake.\n\n\nBy default, marker files are written to local disk, under `<working_directory>/retention/<object_store_type>_<period_from_date>/markers/`. Marker files should be stored on a persistent disk to ensure that the chunks pending for deletion are processed even if the Compactor process restarts.\n\n> Note\n>\n> Grafana Labs recommends running Compactor as a stateful deployment (StatefulSet when using Kubernetes) with a persistent storage for storing marker files.\n\nAlternatively, you can configure the Compactor to store marker files in object storage instead of local disk, by setting `compactor.deletion-marker-object-store-prefix` (`deletion_marker_object_store_prefix`) to a prefix that ends with `/`. When set, the Compactor writes marker files to the same per-period object store bucket used for chunks, under that prefix. On startup it also copies any existing marker files from local disk to that prefix, then removes the local copies. This lets you run the Compactor without a persistent volume for marker files. Leave this setting empty to keep using local disk.\n\n### Retention Configuration\n\nThis Compactor configuration example activates retention.\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\ncompactor:\n  working_directory: /data/retention\n  compaction_interval: 10m\n  retention_enabled: true\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n  delete_request_store: gcs\nschema_config:\n  configs:\n    - from: \"2020-07-31\"\n      index:\n        period: 24h\n        prefix: index_\n      object_store: gcs\n      schema: v13\n      store: tsdb\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /data/index\n    cache_location: /data/index_cache\n  gcs:\n    bucket_name: loki\n```\n\n> Note\n>\n> Retention is only available if the index period is 24h. Single store TSDB and single store BoltDB require 24h index period.\n\n`retention_enabled` should be set to true. Without this, the Compactor will only compact tables.\n\n`delete_request_store` should be set to configure the store for delete requests. This is required when retention is enabled.\n\n`working_directory` is the directory where marked chunks and temporary tables will be saved.\n\n`compaction_interval` dictates how often compaction is applied. If the Compactor falls behind, compaction occurs as soon as possible.\n\n`apply_retention_interval` dictates how often retention is applied, independently of `compaction_interval`. Refer to [Compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor) for how the default value is derived from `compaction_interval`.\n\n`retention_delete_delay` is the delay after which the Compactor will delete marked chunks.\n\n`retention_delete_worker_count` specifies the maximum quantity of goroutine workers instantiated to delete chunks.\n\nA few other options are also relevant when tuning retention:\n\n- `retention_table_timeout` bounds how long the Compactor spends applying retention and processing delete requests on any single table. It defaults to `0s`, meaning no timeout. If the work on a table exceeds this timeout, the Compactor logs a warning and stops early rather than failing, and the remaining work is picked up again on a later run.\n- `retention_backoff_config` controls the retry behavior (minimum and maximum backoff, and number of retries) used by the sweeper when it fails to delete a marked chunk.\n- `delete_request_store_key_prefix` sets the path prefix used to store delete requests within `delete_request_store` (default `index/`).\n- `delete_request_store_db_type` sets the type of database used to store delete requests (default `boltdb`).\n\nRefer to the\n[Configuration reference](https://grafana.com/docs/loki/latest/configure/#compactor) for the full list of `compactor` options and their defaults.\n\n#### Configuring the retention period\n\nRetention period is configured within the\n[`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) configuration section.\n\nThere are two ways of setting retention policies:\n\n- `retention_period` which is applied globally for all log streams.\n- `retention_stream` which is only applied to log streams matching the selector.\n\n> Note\n>\n> Each `retention_stream` rule\u2019s `period` must be at least 24h. Loki rejects configuration with a shorter value, both in the global `retention_stream` list and in any per-tenant override. This minimum does not apply to the `retention_period` setting, either globally or per tenant.\n\nThis example configures global retention that applies to all tenants (unless overridden by configuring per-tenant overrides):\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\n...\nlimits_config:\n  retention_period: 744h\n  retention_stream:\n  - selector: '{namespace=\"dev\"}'\n    priority: 1\n    period: 24h\n  per_tenant_override_config: /etc/overrides.yaml\n...\n```\n\n> Note\n>\n> You can only use label matchers in the `selector` field of a `retention_stream` definition. Arbitrary LogQL expressions are not supported.\n\nPer tenant retention can be defined by configuring\n[runtime overrides](https://grafana.com/docs/loki/latest/configure/#runtime-configuration-file). For example:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\noverrides:\n    \"29\":\n        retention_period: 168h\n        retention_stream:\n        - selector: '{namespace=\"prod\"}'\n          priority: 2\n          period: 336h\n        - selector: '{container=\"loki\"}'\n          priority: 1\n          period: 72h\n    \"30\":\n        retention_stream:\n        - selector: '{container=\"nginx\", level=\"debug\"}'\n          priority: 1\n          period: 24h\n```\n\nRetention period for a given stream is decided based on the first match in this list:\n\n1. If multiple per-tenant `retention_stream` selectors match the stream, retention period with the highest priority is picked.\n2. If multiple global `retention_stream` selectors match the stream, retention period with the highest priority is picked. This value is not considered if per-tenant `retention_stream` is set.\n3. If a per-tenant `retention_period` is specified, it will be applied.\n4. The global `retention_period` will be applied if none of the above match.\n5. If no global `retention_period` is specified, the default value of `0s` is used, which means logs are kept indefinitely.\n\n> Note\n>\n> The larger the priority value, the higher the priority. If two matching `retention_stream` rules have the same priority, Loki applies the shorter (lowest) of the two periods.\n\nStream matching uses the same syntax as Prometheus label matching:\n\n- `=`: Select labels that are exactly equal to the provided string.\n- `!=`: Select labels that are not equal to the provided string.\n- `=~`: Select labels that regex-match the provided string.\n- `!~`: Select labels that do not regex-match the provided string.\n\nThe example configurations defined above will result in the following retention periods:\n\n- For tenant `29`:\n  - Streams that have the namespace label `prod` will have a retention period of `336h` (2 weeks), even if the container label is `loki`, since the priority of the `prod` rule is higher.\n  - Streams that have the container label `loki` but are not in the namespace `prod` will have a `72h` retention period.\n  - For the rest of the streams in this tenant, per-tenant override `retention_period` value of `168h` is applied.\n- For tenant `30`:\n  - Streams that have the label `nginx` and level `debug` will have a retention period of `24h`.\n  - For the rest of the streams in this tenant the global retention period of `744h`, since there is no override specified.\n- All tenants except `29` and `30`:\n  - Streams that have the namespace label `dev` will have a retention period of `24h` hours.\n  - Streams except those with the namespace label `dev` will have the retention period of `744h`.\n\n> Note\n>\n> If you are a Grafana Cloud customer, you can use the [config self-serve API](https://grafana.com/docs/grafana-cloud/send-data/logs/config-self-serve/#configure-retention) to configure your tenant retention.\n\n## Table Manager (deprecated)\n\nRetention through the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) is\nachieved by relying on the object store TTL feature, and will work for both\n[boltdb-shipper](https://grafana.com/docs/loki/latest/operations/storage/boltdb-shipper/) store and chunk/index stores.\n\nIn order to enable the retention support, the Table Manager needs to be\nconfigured to enable deletions and a retention period. Please refer to the\n[`table_manager`](https://grafana.com/docs/loki/latest/configure/#table_manager)\nsection of the Loki configuration reference for all available options.\nAlternatively, the `table-manager.retention-period` and\n`table-manager.retention-deletes-enabled` command line flags can be used. The\nprovided retention period needs to be a duration represented as a string that\ncan be parsed using the Prometheus common model [ParseDuration](https://pkg.go.dev/github.com/prometheus/common/model#ParseDuration). Examples: `7d`, `1w`, `168h`.\n\n> Warning\n>\n> The retention period must be a multiple of the index and chunks table\n> `period`, configured in the\n> [`period_config`](https://grafana.com/docs/loki/latest/configure/#period_config) block.\n> See the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/#retention) documentation for\n> more information.\n\n> Note\n>\n> To avoid querying of data beyond the retention period,`max_query_lookback` config in\n> [`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) must be set to a value less than or equal to what is set in `table_manager.retention_period`.\n\nWhen using S3 or GCS, the bucket storing the chunks needs to have the expiry\npolicy set correctly. For more details check\n[S3\u2019s documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)\nor\n[GCS\u2019s documentation](https://cloud.google.com/storage/docs/managing-lifecycles).\n\nIf you must delete ingested logs, you can delete old chunks in your object store. Note,\nhowever, that this only deletes the log content and keeps the label index\nintact; you will still be able to see related labels but will be unable to\nretrieve the deleted log content.\n\nFor further details on the Table Manager internals, refer to the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) documentation.\n\nAlternatively, if the BoltDB Shipper is configured for the index store, you can enable\n[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) to delete log entries from a specific stream.\n\n## Example Configuration\n\nExample configuration with GCS with a 28 day retention:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\nschema_config:\n  configs:\n    - from: 2018-04-15\n      store: tsdb\n      object_store: gcs\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /loki/index\n    cache_location: /loki/index_cache\n  gcs:\n    bucket_name: GCS_BUCKET_NAME\n\nlimits_config:\n  max_query_lookback: 672h # 28 days\n  retention_period: 672h   # 28 days\n\ncompactor:\n  working_directory: /data/retention\n  delete_request_store: gcs\n  retention_enabled: true\n```\n\n## Object store lifecycle policies\n\nLoki stores chunks and indexes as objects in the configured object store (S3, GCS, Azure Blob Storage, and so on). Chunks are deleted by the [Compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor) according to your configured retention, but the Compactor only removes chunk objects: it never deletes the objects that hold cluster state, such as the index or the cluster seed.\n\nIf you also configure an object store lifecycle policy on the bucket, scope it carefully. A blanket \u201cdelete everything older than N days\u201d rule will eventually remove objects that Loki must keep, which corrupts the store and causes query failures. The note at the top of this page applies here as well: any lifecycle expiration must be longer than your retention period.\n\n> Warning\n>\n> Never apply a lifecycle rule with an empty prefix (one that targets the whole bucket). Always scope lifecycle rules to the per-tenant chunk prefixes described below.\n\n### Bucket object layout\n\nThe following objects are written to the configured bucket. The exact prefixes depend on your `schema_config` and on whether multi-tenancy is enabled, so confirm them against your own configuration before writing a lifecycle rule.\n\nExpand table\n\n| Object or prefix | Content | Safe to expire with a lifecycle policy? |\n| --- | --- | --- |\n| `<tenant_id>/` (for example, `fake/` in single-tenant mode, or your org ID per tenant) | Chunk objects (the log data). | Yes. These are the only objects a lifecycle rule should target. |\n| Index objects (under the index path prefix, `index/` by default, set by `index.path_prefix` in `schema_config`) | TSDB or BoltDB index files, written by ingesters and rewritten by the Compactor. The `index.prefix` value (for example `index_` or `loki_index_`) is the table-name prefix used inside this path, not the path itself, so match a lifecycle rule against the path prefix. | No. Loki manages the index lifecycle internally. Deleting index objects removes references to live chunks and breaks queries. |\n| `loki_cluster_seed.json` | A small file at the bucket root holding the cluster seed used by usage reporting. It is written once and never rotated. | No. A blanket age-based rule will delete it once it ages past the time to live (TTL). |\n| Delete-request store objects (a `delete_requests/` table under `delete_request_store_key_prefix`, `index/` by default, in the bucket configured by `delete_request_store`) | The Compactor\u2019s database of delete requests submitted through the<br>[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) API, and their processing status. | No. Removing these makes the Compactor lose track of pending delete requests. |\n| Deletion marker objects (only present if you set `deletion_marker_object_store_prefix`; otherwise markers are kept on the Compactor\u2019s local disk and never appear in the bucket) | The Compactor\u2019s record of chunks that are marked for deletion but not yet swept. Written under the configured prefix in the same per-period bucket used for chunks. | No. Removing these makes the Compactor lose track of chunks pending deletion. |\n| Ruler store objects (if the Ruler is backed by the same bucket) | Recording and alerting rule files. | No. These are configuration, not time-series data. |\n\n### Compactor retention versus object store lifecycle policies\n\nCompactor retention and object store lifecycle policies are two independent mechanisms, and they should not be configured in ways that conflict:\n\n- The Compactor is index-aware. It only deletes a chunk after it has removed every reference to that chunk from the index, and it waits `compactor.retention-delete-delay` (default `2h`) before the sweeper deletes the marked chunk, so that index gateways pick up the rewritten index first.\n- An object store lifecycle policy is index-unaware. It deletes objects purely by age and prefix, with no knowledge of whether a chunk is still referenced by the index.\n\nFor most deployments, enabling Compactor retention is sufficient and an object store lifecycle policy is not required. If you do add a lifecycle policy as a cost safety net, set its expiration **longer** than your retention period plus `compactor.retention-delete-delay`, so the Compactor always deletes chunks first and the lifecycle rule only ever catches objects the Compactor has already orphaned.\n\n### Example: Amazon S3 lifecycle policy\n\nThis policy expires only chunk objects under a single tenant prefix. Replace `fake/` with your tenant prefix (use one rule per tenant, or your org ID prefix, when multi-tenancy is enabled). The `Days` value must be larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-chunk-expiration\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"fake/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 395\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the AWS CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\naws s3api put-bucket-lifecycle-configuration \\\n  --bucket YOUR_LOKI_BUCKET \\\n  --lifecycle-configuration file://lifecycle.json\n```\n\n### Example: Google Cloud Storage lifecycle rule\n\nThe equivalent GCS rule expires objects by age and prefix. As with S3, scope `matchesPrefix` to the tenant chunk prefix and keep `age` larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"rule\": [\\\n    {\\\n      \"action\": {\"type\": \"Delete\"},\\\n      \"condition\": {\\\n        \"age\": 395,\\\n        \"matchesPrefix\": [\"fake/\"]\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the Google Cloud CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\ngcloud storage buckets update gs://YOUR_LOKI_BUCKET --lifecycle-file=lifecycle.json\n```\n\nFor Azure Blob Storage, use a management policy with a `prefixMatch` set to the tenant chunk prefix and the same \u201cexpiration must exceed retention plus delete delay\u201d rule.\n\n## Was this page helpful?\n\n![\ud83d\udc4d](https://grafana.com/media/images/svg/thumbs-up.svg) Yes![\ud83d\udc4e](https://grafana.com/media/images/svg/thumbs-up.svg) No\n\n[Suggest an edit in GitHub](https://github.com/grafana/loki/edit/release-3.7.x/docs/sources/operations/storage/retention.md) [Create a GitHub issue](https://github.com/grafana/loki/issues/new?title=Documentation%20feedback:%20/docs/sources/operations/storage/retention.md) [Email docs@grafana.com](mailto:docs@grafana.com) [Help and support](https://grafana.com/help/) [Community](https://grafana.com/community/)\n\n## Related resources from Grafana Labs\n\nAdditional helpful documentation, links, and articles:\n\n[![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Getting started with logging and Grafana Loki](https://grafana.com/static/assets/featured/getting-started-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nGetting started with logging and Grafana Loki\\\\\n\\\\\nSee a demo of the updated features in Loki, and how to create metrics from logs and alert on your logs with powerful Prometheus-style alerting rules.](https://grafana.com/go/webinar/getting-started-with-logging-and-grafana-loki/?pg=docs-loki-latest-operations-storage-retention&plcmt=related) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Essential Grafana Loki configuration settings](https://grafana.com/static/assets/featured/logging-with-loki-essential-configuration-settings_featured.png?w=400)\\\\\n\\\\\nEssential Grafana Loki configuration settings\\\\\n\\\\\nThis webinar focuses on Grafana Loki configuration including agents Promtail and Docker; the Loki server; and Loki storage for popular backends.](https://grafana.com/go/webinar/logging-with-loki-essential-configuration-settings/?pg=docs-loki-latest-operations-storage-retention&plcmt=related-2) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Scaling and securing your logs with Grafana Loki](https://grafana.com/static/assets/featured/scaling-and-securing-your-logs-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nScaling and securing your logs with Grafana Loki\\\\\n\\\\\nThis webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.](https://grafana.com/go/webinar/scaling-and-securing-your-logs-with-grafana-loki/?pg=docs-loki-latest-operations-storage-retention&plcmt=related-3)\n\nAsk Grafana Assistant",
      "content_chars": 26382,
      "published_date": null
    },
    {
      "rank": 2,
      "url": "https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working",
      "title": "purge - why my Loki log retention is not working? - Stack Overflow",
      "content": "##### Collectives\u2122 on Stack Overflow\n\nFind centralized, trusted content and collaborate around the technologies you use most.\n\n[Learn more about Collectives](https://stackoverflow.com/collectives)\n\n**Stack Internal**\n\nKnowledge at work\n\nBring the best of human thought and AI automation together at your work.\n\n[Explore Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact-popover)\n\n# [why my Loki log retention is not working?](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working)\n\n[Ask Question](https://stackoverflow.com/questions/ask)\n\nAsked4 years, 1 month ago\n\nModified [3 years, 1 month ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working?lastactivity \"2023-08-17 12:22:05Z\")\n\nViewed\n33k times\n\n\nThis question shows research effort; it is useful and clear\n\n12\n\nThis question does not show any research effort; it is unclear or not useful\n\nSave this question.\n\n[Timeline](https://stackoverflow.com/posts/73138278/timeline)\n\nShow activity on this post.\n\n\"12h\" old logs are not deleting even after specifying \"retention\\_period: 12h\" due to this I'm facing storage issue because, log are not deleting.\nplease help me with config\n\n```\nloki:\n  enabled: true\n  isDefault: true\n  table_manager:\n    retention_deletes_enabled: true\n    retention_period: 12h\n```\n\n- [purge](https://stackoverflow.com/questions/tagged/purge \"show questions tagged 'purge'\")\n- [retention](https://stackoverflow.com/questions/tagged/retention \"show questions tagged 'retention'\")\n- [grafana-loki](https://stackoverflow.com/questions/tagged/grafana-loki \"show questions tagged 'grafana-loki'\")\n- [promtail](https://stackoverflow.com/questions/tagged/promtail \"show questions tagged 'promtail'\")\n\n[Share](https://stackoverflow.com/q/73138278)\n\nShare a link to this question\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this question\n\n[Improve this question](https://stackoverflow.com/posts/73138278/edit \"\")\n\nFollow\n\n\n\nFollow this question to receive notifications\n\n[edited Jul 27, 2022 at 12:54](https://stackoverflow.com/posts/73138278/revisions \"show all edits to this post\")\n\nasked Jul 27, 2022 at 12:50\n\n[![Vinayak Pawar's user avatar](https://lh3.googleusercontent.com/a/AItbvmmc9dlTfSu1J8AycV3kKXkeYxBKUi0R2C9k_c3f=k-s64)](https://stackoverflow.com/users/19632861/vinayak-pawar)\n\n[Vinayak Pawar](https://stackoverflow.com/users/19632861/vinayak-pawar)\n\n14311 gold badge11 silver badge55 bronze badges\n\n2\n\n- 1\n\n\n\n\n\nWhat exactly do you mean by: \"12h\" old logs are not deleting? I am asking because Loki is not supposed to delete any log file. To delete those files, you would use some kind of log rotation provided by your logging framework. (BTW: Getting those files is part of the Promtail configuration not part of Loki.)\n\n\n\nSascha Doerdelmann\n\n\n\u2013\n[Sascha Doerdelmann](https://stackoverflow.com/users/11934850/sascha-doerdelmann \"906 reputation\")\n\n\n\n2022-07-27 13:46:41 +00:00\n\n[CommentedJul 27, 2022 at 13:46](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment129174235_73138278)\n\n- 2\n\n\n\n\n\nActually, My goal is to deleted logs which are older than 12h, it should be deleted from grafana dashboard as well as from server storage because I m facing storage issues as my log are not deleting, and occupying huge space in server storage is getting full\n\n\n\nVinayak Pawar\n\n\n\u2013\n[Vinayak Pawar](https://stackoverflow.com/users/19632861/vinayak-pawar \"143 reputation\")\n\n\n\n2022-07-29 05:14:31 +00:00\n\n[CommentedJul 29, 2022 at 5:14](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment129212546_73138278)\n\n\n[Add a comment](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working# \"Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.\")\u00a0\\|\u00a0[Expand to show all comments on this post](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working# \"Expand to show all comments on this post\")\n\n## 3 Answers 3\n\nSorted by:\n[Reset to default](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working?answertab=scoredesc#tab-top)\n\nHighest score (default)\n\nTrending (recent votes count more)\n\nDate modified (newest first)\n\nDate created (oldest first)\n\n\nThis answer is useful\n\n11\n\nThis answer is not useful\n\nSave this answer.\n\nLoading when this answer was accepted\u2026\n\n[Timeline](https://stackoverflow.com/posts/73140146/timeline)\n\nShow activity on this post.\n\nI have the following configurations related to log retention:\n\n```\n...\ncompactor:\n  ...\n  retention_enabled: true\n...\nlimits_config:\n  ...\n  retention_period: 90d\n...\n```\n\nSee more about Loki configuration in the documentation [here](https://grafana.com/docs/loki/latest/configuration/)\n\n[Share](https://stackoverflow.com/a/73140146)\n\nShare a link to this answer\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this answer\n\n[Improve this answer](https://stackoverflow.com/posts/73140146/edit \"\")\n\nFollow\n\n\n\nFollow this answer to receive notifications\n\nanswered Jul 27, 2022 at 14:51\n\n[![Marcelo \u00c1vila de Oliveira's user avatar](https://lh3.googleusercontent.com/--qAy9sY_FtU/AAAAAAAAAAI/AAAAAAAAAcI/1eUd0gZytXc/s64-rj/photo.jpg)](https://stackoverflow.com/users/4653675/marcelo-%c3%81vila-de-oliveira)\n\n[Marcelo \u00c1vila de Oliveira](https://stackoverflow.com/users/4653675/marcelo-%c3%81vila-de-oliveira)\n\n23.2k33 gold badges5252 silver badges6060 bronze badges\n\n## Comments\n\nAdd a comment\n\nThis answer is useful\n\n8\n\nThis answer is not useful\n\nSave this answer.\n\nLoading when this answer was accepted\u2026\n\n[Timeline](https://stackoverflow.com/posts/75232337/timeline)\n\nShow activity on this post.\n\n[Grafana Loki Storage Retention](https://grafana.com/docs/loki/latest/operations/storage/retention/)\n\n> By default, when `table_manager.retention_deletes_enabled` or\n> `compactor.retention_enabled` _flags are not set_, **then logs sent to**\n> **Loki live forever.**\n\n**The minimum retention period is 24h**.\n\nThe retention period **must be a multiple** of the _index_ and chunks table `period`, configured in the `period_config` block.\n\nSample config:\n\n```yaml\nCopy\nschema_config:\n  configs:\n    - from: 2020-10-24\n      store: boltdb-shipper\n      object_store: filesystem\n      schema: v11\n      index:\n        prefix: index_\n        period: 24h\n\ntable_manager:\n  retention_deletes_enabled: true\n  retention_period: 24h\n```\n\nThe other way to setup the retention in Grafana Loki is via the Compactor.\n\n```yaml\nCopy\nlimits_config:\n  retention_period: 168h\n\ncompactor:\n  working_directory: /data/retention\n  compaction_interval: 10m\n  retention_enabled: true\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n\nschema_config:\n  configs:\n    - from: 2020-10-24\n      store: boltdb-shipper\n      object_store: filesystem\n      schema: v11\n      index:\n        prefix: index_\n        period: 24h\n```\n\nNote that **retention is only available if the index period is 24h**.\n\nTo purge data immediately you could set the `retention_delete_delay` interval to `1m`. This is a delay after which chunks will be fully deleted during retention.\n\nDo not forget to restart Loki after changing the configuration:\n\n```bash\nCopy\nsystemctl restart loki\nsystemctl status loki\n```\n\n[Share](https://stackoverflow.com/a/75232337)\n\nShare a link to this answer\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this answer\n\n[Improve this answer](https://stackoverflow.com/posts/75232337/edit \"\")\n\nFollow\n\n\n\nFollow this answer to receive notifications\n\n[edited Aug 17, 2023 at 12:22](https://stackoverflow.com/posts/75232337/revisions \"show all edits to this post\")\n\nanswered Jan 25, 2023 at 10:03\n\n[![Vladislav's user avatar](https://www.gravatar.com/avatar/60d4532b799a1ff5f985df6f402cdfe3?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/155687/vladislav)\n\n[Vladislav](https://stackoverflow.com/users/155687/vladislav)\n\n2,09311 gold badge3333 silver badges4242 bronze badges\n\n## 5 Comments\n\nAdd a comment\n\n[![](https://i.sstatic.net/EPmGy.jpg?s=64)](https://stackoverflow.com/users/9072753/kamilcuk)\n\nKamilCuk\n\n[KamilCuk](https://stackoverflow.com/users/9072753/kamilcuk) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment135587402_75232337)\n\n`This is a delay after which chunks will be fully deleted during retention` I do not understand. So the logs will be deleted after retention\\_delete\\_delay or after limits\\_config: retention\\_period? Why are there two settings?\n\n2023-08-16T09:32:58.977Z+00:00\n\n0\n\nReply\n\n- Copy link\n\n[![](https://www.gravatar.com/avatar/60d4532b799a1ff5f985df6f402cdfe3?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/155687/vladislav)\n\nVladislav\n\n[Vladislav](https://stackoverflow.com/users/155687/vladislav) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment135602762_75232337)\n\n`retention_delete_delay` just delays deleting defined in `limits_config\\retention_period`. The reason for that is described in [grafana.com/docs/loki/latest/operations/storage/retention](https://grafana.com/docs/loki/latest/operations/storage/retention/) as: \"1. ... deleting chunks instantly could lead to components still having reference to old chunks and so they could fails to execute queries. Having a delay allows for components to refresh their store and so remove gracefully their reference of those chunks. 2. It provides a short window of time in which to cancel chunk deletion in the case of a configuration mistake.\"\n\n2023-08-17T12:23:43.223Z+00:00\n\n3\n\nReply\n\n- Copy link\n\n[![](https://i.sstatic.net/X8yzA.jpg?s=64)](https://stackoverflow.com/users/1988508/mohammed-noureldin)\n\nMohammed Noureldin\n\n[Mohammed Noureldin](https://stackoverflow.com/users/1988508/mohammed-noureldin) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment137331970_75232337)\n\nHi, do you have an idea, if they support using 1w for retention, for example. It is a bit confusing that you can use the unit of time \"h\", but you must use multiples of 24h. Why they just did not enforce using the unit \"d\"? Or can we use d or w or m? I could not find this info the docs.\n\n2024-01-29T10:15:18.853Z+00:00\n\n1\n\nReply\n\n- Copy link\n\n[![](https://graph.facebook.com/693489905/picture?type=large)](https://stackoverflow.com/users/3195089/jeremy-d)\n\nJeremy D\n\n[Jeremy D](https://stackoverflow.com/users/3195089/jeremy-d) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment138669644_75232337)\n\nThe table manager is now deprecated. [grafana.com/docs/loki/latest/operations/storage/retention/\u2026](https://grafana.com/docs/loki/latest/operations/storage/retention/#table-manager-deprecated)\n\n2024-06-21T14:58:19.763Z+00:00\n\n0\n\nReply\n\n- Copy link\n\n[![](https://www.gravatar.com/avatar/6349954cca4ca0cfbad244fb265bd805?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/9351221/lethargos)\n\nLethargos\n\n[Lethargos](https://stackoverflow.com/users/9351221/lethargos) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment139289389_75232337)\n\nCan anyone explain to me what the /data/retention path refers to? Is it the chunks path? For example /var/lib/loki/chunks?\n\n2024-09-18T12:19:56.59Z+00:00\n\n0\n\nReply\n\n- Copy link\n\nAdd a comment\n\nThis answer is useful\n\n-1\n\nThis answer is not useful\n\nSave this answer.\n\nLoading when this answer was accepted\u2026\n\n[Timeline](https://stackoverflow.com/posts/73907780/timeline)\n\nShow activity on this post.\n\nFrom the [Grafana storage documentation](https://grafana.com/docs/loki/latest/storage/#retention):\n\n> With the exception of the filesystem chunk store, Loki will not delete old chunk stores. This is generally handled instead by configuring TTLs (time to live) in the chunk store of your choice (bucket lifecycles in S3/GCS, and TTLs in Cassandra). Neither will Loki currently delete old data when your local disk fills when using the filesystem chunk store \u2013 deletion is only determined by retention duration.\n\nThis quote should answer your question. You need to configure bucket lifecycles in your storage provider to be able to delete chunk stores.\n\n[Share](https://stackoverflow.com/a/73907780)\n\nShare a link to this answer\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this answer\n\n[Improve this answer](https://stackoverflow.com/posts/73907780/edit \"\")\n\nFollow\n\n\n\nFollow this answer to receive notifications\n\nanswered Sep 30, 2022 at 11:05\n\n[![Ri1a's user avatar](https://www.gravatar.com/avatar/728ba55606bef39aa7b37489da92893b?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/10408262/ri1a)\n\n[Ri1a](https://stackoverflow.com/users/10408262/ri1a)\n\n74399 silver badges2727 bronze badges\n\n## Comments\n\nAdd a comment\n\n## Your Answer\n\n**Reminder:** Answers generated by AI tools are not allowed due to Stack Overflow's [artificial intelligence policy](https://stackoverflow.com/help/gen-ai-policy)\n\nDraft saved\n\nDraft discarded\n\n### Sign up or [log in](https://stackoverflow.com/users/login?ssrc=question_page&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f73138278%2fwhy-my-loki-log-retention-is-not-working%23new-answer)\n\nSign up using Google\n\n\nSign up using Email and Password\n\n\nSubmit\n\n### Post as a guest\n\nName\n\nEmail\n\nRequired, but never shown\n\nPost Your Answer\n\nDiscard\n\n\nBy clicking \u201cPost Your Answer\u201d, you agree to our [terms of service](https://stackoverflow.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://stackoverflow.com/legal/privacy-policy).\n\n\nStart asking to get answers\n\nFind the answer to your question by asking.\n\n[Ask question](https://stackoverflow.com/questions/ask)\n\nExplore related questions\n\n- [purge](https://stackoverflow.com/questions/tagged/purge \"show questions tagged 'purge'\")\n- [retention](https://stackoverflow.com/questions/tagged/retention \"show questions tagged 'retention'\")\n- [grafana-loki](https://stackoverflow.com/questions/tagged/grafana-loki \"show questions tagged 'grafana-loki'\")\n- [promtail](https://stackoverflow.com/questions/tagged/promtail \"show questions tagged 'promtail'\")\n\nSee similar questions with these tags.",
      "content_chars": 14774,
      "published_date": null
    },
    {
      "rank": 3,
      "url": "https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/",
      "title": "Log entry deletion | Grafana Loki documentation",
      "content": "![ObservabilityCON 2025](https://a-us.storyblok.com/f/1022730/280x40/b0872b99f9/grafana-logo-observabilitycon-2025-black.svg/m/)\n\nWatch the keynote again and signup for more on-demand sessions.\n\n\n[Watch keynote](https://grafana.com/events/observabilitycon/?plcmt=obscon2025-post-event-banner)![](https://grafana.com/media/events/grafanacon/2025/icon-close-x.svg)\n\n![ObservabilityCON 2025](https://grafana.com/media/events/obscon/2025/grafana-obscon2025-promo-logo-black.svg)\n\n\ud83d\udce2 Registration + agenda now live\nExplore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).\n\n\n[Register now](https://grafana.com/events/observabilitycon/?tech=target&plcmt=top-banner&aud=default)\n\nSearching...\n\nSite search\n\nAsk Grot AI\n\n[Try using ![Grot AI](https://grafana.com/static/img/grot-chat.svg)**Grot AI** for this query ->](https://grafana.com/grot/?chat=&from=/search)\n\nAll\n\nDocs\n\nView all results\n\nNo results.\n\nThere was an error with your request.\n\n> Documentation for automated readers\n>\n> A curated documentation index is available at: https://grafana.com/llms.txt\n>\n> A complete documentation index is available at: https://grafana.com/llms-full.txt\n>\n> These indexes can help with page discovery before fetching individual documents.\n\nThis page is also available in Markdown, which may be easier for automated readers\nand AI tools to parse than HTML. The Markdown version is available at\nhttps://grafana.com/docs/loki/latest/operations/storage/logs-deletion.md, or by sending\nAccept: text/markdown to https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/. For broader\ndocumentation discovery, the curated index is available at https://grafana.com/llms.txt\nand the complete index is available at https://grafana.com/llms-full.txt.\n\nLog entry deletion\n\n[Documentation](https://grafana.com/docs/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Grafana Loki](https://grafana.com/docs/loki/latest/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Manage](https://grafana.com/docs/loki/latest/operations/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Storage](https://grafana.com/docs/loki/latest/operations/storage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)Log entry deletion\n\nOpen source\n\n# Log entry deletion\n\nGrafana Loki supports the deletion of log entries from a specified stream.\nLog entries that fall within a specified time window and match an optional line filter are those that will be deleted.\n\nLog entry deletion is supported when the TSDB index is configured as the index store. It is also supported on the deprecated BoltDB Shipper index, but BoltDB Shipper is being removed in Loki 4.0, so new deployments should use TSDB.\n\nThe compactor component exposes REST\n[endpoints](https://grafana.com/docs/loki/latest/reference/loki-http-api/#compactor) that process delete requests.\nHitting the endpoint specifies the streams and the time window.\nThe deletion of the log entries takes place after a configurable cancellation time period expires.\n\nLog entry deletion relies on configuration of the custom logs retention workflow as defined for the\n[compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor). The compactor looks at unprocessed requests which are past their cancellation period to decide whether a chunk is to be deleted or not.\n\n## Configuration\n\nEnable log entry deletion by setting `retention_enabled` to `true` in the compactor\u2019s configuration (`-compactor.retention-enabled` on the command line). The tenant\u2019s `deletion_mode` must also be `filter-only` or `filter-and-delete`, which is the case by default.\n`delete_request_store` also needs to be configured when retention is enabled to process delete requests, this determines the storage bucket that stores the delete requests.\n\n> Warning\n>\n> Be very careful when enabling retention. It is strongly recommended that you also enable versioning on your objects in object storage to allow you to recover from accidental misconfiguration of a retention setting. If you want to enable deletion but do not want to enforce retention, configure the `retention_period` setting with a value of `0s`.\n\n`deletion_mode` is a global and per-tenant setting in\n[`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config). Its default value is `filter-and-delete`, so log entry deletion is active for every tenant as soon as `retention_enabled` is `true` and `delete_request_store` is configured, unless you explicitly change the mode. Set `deletion_mode` in the main configuration file for a global default, or override it per tenant in the\n[runtime configuration file](https://grafana.com/docs/loki/latest/configure/#runtime-configuration-file).\n\n`deletion_mode` supports three values:\n\n- `disabled`: Deletion is not allowed. Requests to the deletion API endpoints are rejected with a `403 Forbidden` response.\n- `filter-only`: Log lines matching the query in the delete request are filtered out when querying Loki. They are not removed from storage.\n- `filter-and-delete`: Log lines matching the query in the delete request are filtered out when querying Loki, and they are also removed from storage. This is the default.\n\nA delete request may be canceled within a configurable cancellation period. Set the `delete_request_cancel_period` in the compactor\u2019s YAML configuration or on the command line when invoking Loki. Its default value is 24h. To cancel a delete request that has already started processing, pass the `force=true` query parameter to the cancellation endpoint.\n\nDelete requests that include a line filter are split into smaller requests that each cover no more than `delete_max_interval` (24h by default). You can request a smaller split for a single request with the `max_interval` query parameter, but it cannot be larger than `delete_max_interval`. Delete requests without a line filter are not split. Refer to the\n[HTTP API reference](https://grafana.com/docs/loki/latest/reference/loki-http-api/#request-log-deletion) for the full set of request parameters.\n\nDelete requests themselves are stored using the database type set by `delete_request_store_db_type`, which defaults to `boltdb`. You can instead use `sqlite`. When you migrate from one database type to another, you can set `backup_delete_request_store_db_type` to `boltdb` so that delete requests are also written to a backup database. Refer to the\n[compactor configuration reference](https://grafana.com/docs/loki/latest/configure/#compactor) for details.\n\nThe deletion API endpoints are registered only when `compactor.retention_enabled` is `true`. When retention is not enabled, the endpoints are unavailable for every tenant, whatever the `deletion_mode` value is. When retention is enabled, use the `deletion_mode` tenant override to control which tenants can use the deletion API.\n\n> Note\n>\n> Deletion of log lines with line filters is one of the compactor\u2019s most resource-intensive operations. If you delete large volumes of data with line filters, refer to\n> [Horizontal scaling of Compactor](https://grafana.com/docs/loki/latest/operations/storage/compactor-horizontal-scaling/) to distribute that work across multiple compactor instances.\n\n## Was this page helpful?\n\n![\ud83d\udc4d](https://grafana.com/media/images/svg/thumbs-up.svg) Yes![\ud83d\udc4e](https://grafana.com/media/images/svg/thumbs-up.svg) No\n\n[Suggest an edit in GitHub](https://github.com/grafana/loki/edit/release-3.7.x/docs/sources/operations/storage/logs-deletion.md) [Create a GitHub issue](https://github.com/grafana/loki/issues/new?title=Documentation%20feedback:%20/docs/sources/operations/storage/logs-deletion.md) [Email docs@grafana.com](mailto:docs@grafana.com) [Help and support](https://grafana.com/help/) [Community](https://grafana.com/community/)\n\n## Related resources from Grafana Labs\n\nAdditional helpful documentation, links, and articles:\n\n[![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Getting started with logging and Grafana Loki](https://grafana.com/static/assets/featured/getting-started-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nGetting started with logging and Grafana Loki\\\\\n\\\\\nSee a demo of the updated features in Loki, and how to create metrics from logs and alert on your logs with powerful Prometheus-style alerting rules.](https://grafana.com/go/webinar/getting-started-with-logging-and-grafana-loki/?pg=docs-loki-latest-operations-storage-logs-deletion&plcmt=related) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Essential Grafana Loki configuration settings](https://grafana.com/static/assets/featured/logging-with-loki-essential-configuration-settings_featured.png?w=400)\\\\\n\\\\\nEssential Grafana Loki configuration settings\\\\\n\\\\\nThis webinar focuses on Grafana Loki configuration including agents Promtail and Docker; the Loki server; and Loki storage for popular backends.](https://grafana.com/go/webinar/logging-with-loki-essential-configuration-settings/?pg=docs-loki-latest-operations-storage-logs-deletion&plcmt=related-2) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Scaling and securing your logs with Grafana Loki](https://grafana.com/static/assets/featured/scaling-and-securing-your-logs-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nScaling and securing your logs with Grafana Loki\\\\\n\\\\\nThis webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.](https://grafana.com/go/webinar/scaling-and-securing-your-logs-with-grafana-loki/?pg=docs-loki-latest-operations-storage-logs-deletion&plcmt=related-3)\n\nAsk Grafana Assistant",
      "content_chars": 10111,
      "published_date": null
    },
    {
      "rank": 4,
      "url": "https://grafana.com/docs/loki/latest/",
      "title": "Grafana Loki | Grafana Loki documentation",
      "content": "## Overview\n\nUnlike other logging systems, Loki is built around the idea of only indexing metadata about your logs\u2019 labels (just like Prometheus labels). Log data itself is then compressed and stored in chunks in object stores such as Amazon Simple Storage Service (S3) or Google Cloud Storage (GCS), or even locally on the filesystem.\n\n## Explore\n\n## Grafana Loki, frequently asked questions\n\nHere are answers to some frequently asked questions about how to configure and run Loki.\n\n### Where should I start if I\u2019m new to Loki?\n\nStart with the Loki Tutorial, which walks you through what Loki is, how it works, and how the components fit together.\n\n- Try it locally. The fastest way to experiment is to run Loki in monolithic (single-binary) mode with a local filesystem backend and send logs to it with Grafana Alloy.\n- Understand labels. Loki\u2019s indexing model is label-based, which is different from most logging systems. Read Labels and the label best practices early \u2014 how you label your logs directly affects query performance and storage costs.\n- Learn LogQL. LogQL is Loki\u2019s query language. Start with simple label matchers and line filters, then explore log pipeline stages and metric queries as you need them.\n- Explore with Grafana. Connect Loki as a data source in Grafana and use Explore to run ad-hoc queries against your logs.\n\n\nThe Grafana Labs Learning Hub offers self-paced, hands-on courses relevant to Loki:\n\n- Send logs to Grafana Cloud using Alloy \u2014 Walk through configuring Grafana Alloy to ship logs to Loki in Grafana Cloud.\n- Send data from external collectors \u2014 Learn how to send logs to Loki using OpenTelemetry (OTLP) or the HTTP API, and choose the right method for your setup.\n- Explore your infrastructure data with Grafana Drilldown apps \u2014 Explore Loki logs visually without writing LogQL, using the Logs Drilldown app to filter by labels, detect patterns, and investigate errors.\n- Optimize Adaptive Logs \u2014 Reduce log volume and storage costs in Grafana Cloud by tuning which logs Loki ingests.\n\n\n### Should I self-host or use Grafana Cloud for logs?\n\nThe right answer depends on your team\u2019s capacity and priorities. Choose Grafana Cloud if you want to get up and running quickly, prefer not to manage infrastructure, or are a small team without dedicated operations resources. The free tier is generous enough for most individuals and small projects.\n\nChoose self-hosted OSS or Enterprise if you have strict data residency or compliance requirements, need to keep all data on your own infrastructure, or have an existing investment in self-managed tooling like Prometheus and want to extend it.\n\nThe feature set between Cloud and a self-managed Enterprise stack is broadly equivalent. The primary difference is operational overhead: self-hosting means you own the availability, scaling, and maintenance of every component in the stack.\n\n### What are the best practices for Loki labels vs. structured metadata?\n\nLoki\u2019s indexing model differs significantly from other observability products. Choosing the wrong fields as labels is the most common cause of poor query performance and high resource usage.\n\nLabels define a log stream. Every unique combination of label values creates a new stream, which is stored and indexed separately.\n\n- \u2705 Use labels for low-cardinality dimensions you will always filter on:\n\n    env\n\n,\n\n    cluster\n\n,\n\n    namespace\n\n,\n\n    app\n\n,\n\n    job\n\n.\n\n- \u274c Do not use labels for high-cardinality values: pod, instance IDs, request IDs, user IDs, trace IDs, HTTP status codes, IP addresses. Each unique value creates a new stream, causing \u201ccardinality explosion\u201d that degrades ingestion and query performance.\n\n\nStructured metadata (introduced in Loki 3.0) allows attaching key-value pairs to log entries without creating new streams. Use it for values you want to filter or display but that are too high-cardinality for labels:\n\n  \n\n    // Example: attaching trace_id as structured metadata via Alloy\n    loki.process \"default\" {\n      stage.json {\n        expressions = { \"trace_id\" = \"\" }\n      }\n\n      stage.structured_metadata {\n        values = { \"trace_id\" = \"\" }\n      }\n\n      forward_to = [loki.write.local.receiver]\n    }\n\n    loki.write \"local\" {\n      endpoint {\n        url = \"http://loki:3100/loki/api/v1/push\"\n      }\n    }\n\n\n  \n\nParsed fields (extracted at query time with\n\n    | json\n\n,\n\n    | logfmt\n\n,\n\n    | pattern\n\n,\n\n    | regexp\n\n) require no schema changes and add no indexing overhead. Prefer them for ad-hoc filtering on log content.\n\nRule of thumb: If you would filter by it in every query, it belongs in a label. If you only need it occasionally or it has many unique values, use structured metadata or parse it from the log line at query time.\n\n### Why does     service_name show as     unknown_service in Explore Logs?\n\nLoki\u2019s Explore Logs feature uses a\n\n    service_name\n\nlabel to group and navigate logs. If it shows\n\n    unknown_service\n\n, Loki could not automatically determine a service name from the incoming stream.\n\nIf a\n\n    service_name\n\nlabel is already present on the stream, Loki uses it directly. Otherwise, Loki\u2019s\n\n    discover_service_name\n\nfeature looks for the first non-empty value from these label keys, in order:\n\n- service\n- app\n- application\n- app_name\n- name\n- app_kubernetes_io_name\n- container\n- container_name\n- k8s_container_name\n- component\n- workload\n- job\n- k8s_job_name\n\n\nCommon causes:\n\n- The log shipper (Alloy, OTel Collector, kube-logging-operator) is not forwarding Kubernetes metadata as stream labels.\n- The label name uses dot notation (\n\n    service.name\n\n). Loki normalizes label names server-side, replacing dots with underscores (for example,\n\n    service.name\n\nbecomes\n\n    service_name\n\n).\n\n-\n\n    discover_service_name\n\nis disabled in your Loki configuration.\n\nVerify by checking your stream labels in Explore. If none of the above keys are present as labels, configure your log shipper to include them. For Alloy, ensure\n\n    loki.source.kubernetes\n\nor\n\n    discovery.kubernetes\n\nis passing through pod metadata.\n\nYou can customize the list of labels Loki checks by setting\n\n    discover_service_name\n\nin\n\n    limits_config\n\n.\n\n### How do I fix \u201cingestion rate limit exceeded\u201d (HTTP 429) errors?\n\nA 429 error from Loki means an ingestion rate limit has been hit. Loki enforces limits both globally and per-stream.\n\nGlobal ingestion limits (applied per tenant):\n\n  \n\n    limits_config:\n      ingestion_rate_mb: 16        # default: 4 MB/s\n      ingestion_burst_size_mb: 32  # default: 6 MB\n\n\n  \n\nPer-stream rate limit:\n\n  \n\n    limits_config:\n      per_stream_rate_limit: 5MB        # default: 3MB\n      per_stream_rate_limit_burst: 15MB # default: 15MB (5x the rate limit)\n\n\n  \n\nTo identify which streams are responsible, check the error message in your log shipper. It includes the stream labels of the offending stream. You can also query Loki\u2019s metrics endpoint for\n\n    loki_ingester_streams_created_total\n\nbroken down by tenant.\n\nIf you are self-hosting and consistently hitting limits with legitimate log volume, increase the values above in\n\n    limits_config\n\n. If you are on Grafana Cloud, contact support to adjust your plan limits.\n> Note\n>\n> Increasing limits without investigating root cause can mask runaway log producers. Always check whether a specific workload or namespace is generating an unexpected spike before raising limits.\n\n### Why can\u2019t Grafana connect to Loki when both are running in Docker?\n\nWhen Grafana and Loki run as separate Docker containers,\n\n    localhost\n\ninside the Grafana container refers to the Grafana container itself, not the host machine or the Loki container. This is the most common misconfiguration for new users.\n\nCorrect datasource URL in Docker Compose:\n\n  \n\n    # docker-compose.yml\n    services:\n      loki:\n        image: grafana/loki:latest\n        ports:\n          - \"3100:3100\"\n\n      grafana:\n        image: grafana/grafana:latest\n        environment:\n          - GF_DATASOURCES_DEFAULT_URL=http://loki:3100\n\n\n  \n\nIn Grafana\u2019s datasource settings, use\n\n    http://loki:3100\n\n(the Docker Compose service name) instead of\n\n    http://localhost:3100\n\n.\n\nFor Kubernetes deployments, use the in-cluster service DNS name:\n\n  \n\n    http://loki.monitoring.svc.cluster.local:3100\n\n\n  \n\nVerify connectivity by exec-ing into the Grafana container and running:\n\n  \n\n    curl http://loki:3100/ready\n\n\n  \n\nIf this returns\n\n    ready\n\n, the networking is correct and the issue lies in the Grafana datasource configuration itself.\n\n### What causes \u201cToo many outstanding requests\u201d errors on my dashboard?\n\nThis error occurs when the number of concurrent queries to Loki exceeds the configured limit for a tenant. It is most common when a dashboard has four or more panels querying over a long time range against a single-node (monolithic) deployment.\n\nKey configuration knobs:\n\n  \n\n    query_scheduler:\n      max_outstanding_requests_per_tenant: 32000  # default: 32000\n\n    frontend:\n      max_outstanding_per_tenant: 2048            # default: 2048\n\n    limits_config:\n      split_queries_by_interval: 24h              # default: 1h\n\n\n  \n\nSplitting queries by interval reduces the load per request by breaking large time-range queries into smaller parallel chunks. For single-node deployments under sustained dashboard load, also consider increasing chunk sizes to reduce the total number of chunk reads:\n\n  \n\n    ingester:\n      chunk_target_size: 1572864\n      max_chunk_age: 2h\n      chunk_idle_period: 30m\n\n\n  \n\nIf the issue persists at scale, consider moving from a monolithic deployment to microservices mode.\n\n### How do I make a LogQL query return zero instead of \u201cno data\u201d?\n\nBy default, LogQL metric queries return no data points for intervals where no log lines matched, rather than returning\n\n    0\n\n. This breaks percentage calculations and alert rules that expect a numeric baseline.\n\nWorkaround using\n\n    or on() vector(0)\n\n(mirrors the PromQL pattern):\n\n  \n\n    (\n      sum(count_over_time({app=\"my-app\"} |= \"error\" [5m]))\n      or on() vector(0)\n    )\n\n\n  \n\nFor ratio/percentage queries, guard the denominator with\n\n    > 0\n\nto avoid dividing by zero (which produces\n\n    NaN\n\n), and wrap the entire expression with\n\n    or on() vector(0)\n\nso quiet periods return\n\n    0\n\ninstead of no data:\n\n  \n\n    (\n      (\n        sum(count_over_time({app=\"my-app\"} | json | status=~\"5..\" [5m]))\n        or on() vector(0)\n      )\n      /\n      (\n        sum(count_over_time({app=\"my-app\"} [5m]))\n        > 0\n      )\n    )\n    or on() vector(0)\n\n\n  \n\nFor alerting, this pattern is essential. Without it, an alert rule using\n\n    count_over_time\n\nproduces no evaluation result (not\n\n    0\n\n) during quiet periods, which can cause alerts to flap or never resolve correctly.\n\n### Why isn\u2019t my log retention policy deleting old data?\n\nRetention in Loki is handled by the Compactor, not by the ingester or storage backend directly. A few common reasons why old data persists even after configuring a retention period:\n\n-\n\n    retention_enabled: true\n\nmust be set under the\n\n    compactor\n\nblock, not just in\n\n    limits_config\n\n.\n\n- The Compactor must be running. In monolithic deployments it is sometimes inadvertently disabled.\n- Deletion is not immediate. The Compactor runs on a schedule and only marks chunks for deletion after a configurable grace period (\n\n    retention_delete_delay\n\n).\n\n- When using filesystem storage, the chunks directory size may not visibly decrease right away. The Compactor marks files for deletion first, then removes them on subsequent runs.\n\n\nMinimum required configuration:\n\n  \n\n    compactor:\n      working_directory: /data/loki/compactor\n      retention_enabled: true\n      delete_request_store: <your-object-store>\n\n    limits_config:\n      retention_period: 360h\n\n\n  \n\nTo verify the Compactor is running and retention is active, check the Loki logs for lines referencing\n\n    compactor\n\nand look for the metrics\n\n    loki_boltdb_shipper_compact_tables_operation_total\n\n(compaction runs) and\n\n    loki_compactor_apply_retention_operation_total\n\n(retention runs).",
      "content_chars": 12086,
      "published_date": null
    },
    {
      "rank": 5,
      "url": "https://blog.devops.dev/log-and-metric-retention-in-loki-and-prometheus-57e81bbad023?gi=780056f55dc2",
      "title": "Log and Metric Retention in Loki and Prometheus | by Faith Sodipe ...",
      "content": "[Sitemap](https://blog.devops.dev/sitemap/sitemap.xml)\n\n[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fblog.devops.dev%2Flog-and-metric-retention-in-loki-and-prometheus-57e81bbad023&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n[Medium Logo](https://medium.com/?source=---top_nav_layout_nav-------------------------------------------)\n\nGet app\n\n[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav--------------------)\n\n[Search](https://medium.com/search?source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fblog.devops.dev%2Flog-and-metric-retention-in-loki-and-prometheus-57e81bbad023&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n![Unknown user](https://miro.medium.com/v2/resize:fill:64:64/1*dmbNkD5D-u45r44go_cf0g.png)\n\n[**DevOps.dev**](https://blog.devops.dev/?source=post_page---publication_nav-33f8b2d9a328-57e81bbad023-----------------------------------------)\n\n\u00b7\n\nFollow publication\n\n[![DevOps.dev](https://miro.medium.com/v2/resize:fill:76:76/1*3SZtM9yhQyfh-dfWk5gGFw.jpeg)](https://blog.devops.dev/?source=post_page---post_publication_sidebar-33f8b2d9a328-57e81bbad023-----------------------------------------)\n\n[Devops.dev](http://devops.dev/) is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.\n\nFollow publication\n\n[Containerization](https://medium.com/tag/containerization?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[Docker](https://medium.com/tag/docker?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[Prometheus](https://medium.com/tag/prometheus?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[Grafana](https://medium.com/tag/grafana?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[DevOps](https://medium.com/tag/devops?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n# Log and Metric Retention in Loki and Prometheus\n\n[![Faith Sodipe](https://miro.medium.com/v2/da:true/resize:fill:64:64/0*6zDALwKTapdArB48)](https://medium.com/@faithsodipe?source=post_page---byline--57e81bbad023-----------------------------------------)\n\n[Faith Sodipe](https://medium.com/@faithsodipe?source=post_page---byline--57e81bbad023-----------------------------------------)\n\nFollow\n\n5 min read\n\n\u00b7\n\nMay 30, 2025\n\n5\n\n1\n\n[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3D57e81bbad023&operation=register&redirect=https%3A%2F%2Fblog.devops.dev%2Flog-and-metric-retention-in-loki-and-prometheus-57e81bbad023&source=---header_actions--57e81bbad023---------------------post_audio_button--------------------)\n\nShare\n\nWhen working with observability tools such as Grafana, Loki and Prometheus, storage management is crucial to performance, cost, and compliance. By default, these systems can keep logs and metrics indefinitely, which may result in disk bloat and poor query speed.\n\nIn this article, we\u2019ll go over how to set up data retention policies for **Loki** and **Prometheus**, ensuring that old logs and metrics are safely removed after a certain time period. This article assumes that you are using Docker to build your application.\n\n**Why we may need this?** Configuring Log Retention Policies will:\n\n1\\. Remove sensitive logs/metrics after a while.\n\n2\\. Prevent disk overuse.\n\n3\\. Reduce clutter and increase query speed.\n\n## Loki\n\nIf you are a fan of Marvel, Loki is a god of Norse mythology, known as the trickster and god of mischief. However, the Loki in question here is a Prometheus-inspired log aggregation system that is highly available and horizontally scalable. When compared to Elasticsearch-based solutions, Loki is lighter and less expensive since it simply index labels rather than the entire log data.\n\n![](https://miro.medium.com/v2/resize:fit:220/1*5XOMwEQr7Qqq-JV2DqyZ-w.gif)\n\n**My Loki is different. I am a god, he is just a log index storage**\n\n**Configuring Retention Policies** Loki supports retention only when using the **boltdb-shipper or tsdb** blockstorage engine alongside **compactor**. This **compactor** is responsible for enforcing the deletion of old logs and merges index files while the **boltdb-shipper/tsdb** manages the storage of log index efficiently. Here is a minimal **loki-config.yaml** setup to enable retention.\n\n![](https://miro.medium.com/v2/resize:fit:567/1*PjAQ8DrLYFGmmWeJSB--cA.png)\n\n**Loki.yml file**\n\nThis file holds configurations under 3 different sections:\n\n- **storage\\_config**: defines the storage provider configurations(I used **tsdb** my project but you are able to use **boltdb** to achieve the same result).\n- **limits\\_config:** defines the behaviour of how log limits is handled in Loki. The **retention\\_period** property tells the compactor how long it should keep logs for before the big purge begins. Think of this as an explicit instruction on how to handle log retentions.\n- **Compactor:** provides explicit instructions on how the compactor should go about its clearing and forwarding business. **compaction\\_interval** specifies the frequency of operation, **retention\\_enabled** determines if the compactor is allowed to perform retention operations. **retention\\_delete\\_delay** tells the compactor to wait x amount of time (sec, min , hrs, month, year etc) after the set retention period before swinging into action.\n\n**Verification and Testing** Since my application uses docker, all my services such as **Prometheus**, **Grafana** and **Loki** itself have been configured to run in the container. For the sake of brevity, that configuration snippet is excluded from this article.\n\n## Get Faith Sodipe\u2019s stories in\u00a0your\u00a0inbox\n\nJoin Medium for free to get updates from\u00a0this\u00a0writer.\n\nSubscribe\n\nSubscribe\n\nRemember me for faster sign in\n\nAfter this necessary changes are made to the loki.yaml file, you may decide to restart your docker container to allow it pull the latest configuration first. Once its running, head over to your terminal and run the following command. This command shows docker logs specifically for the named container in the command.\n\n```\ndocker logs <loki-container-name>\n```\n\n<loki-container-name> refers to the name of your loki container you specified at the time of configuration. Just search the log for \u201c **retention**\u201d and you should find tags/meta data pointing to retention action as seen below.\n\nPress enter or click to view image in full size\n\n![](https://miro.medium.com/v2/resize:fit:700/1*M507epZpOiOOmOYIXmntMQ.png)\n\n**Docker Logs After Run**\n\nThat shows that retention is activated and the compactor is eavesdropping and counting down its own time, ready to clear old logs.\n\nNB: If you search for the keyword \u201c **retention**\u201d and you dont find anything, go through the process again as your configuration may be wrong. I have also attached the link to the official documentation at the end of this article to assist with debugging should the need arise.\n\n## Prometheus\n\nMetrics are stored in Prometheus\u2019s Time Series Database (TSDB). Retention can be set according to disk size or time. The retention configuration will be done in the docker-compose.yml file so as to attach the configuration to the instance once it is started.\n\n![](https://miro.medium.com/v2/resize:fit:528/1*9G6qONlteMiCeMZA_uCeJQ.png)\n\n**docker-compose.yml file**\n\nThe command section of this file has 3 parts to enable retention:\n\n- `\u2014 config.file=/etc/prometheus/prometheus.yml`: specifies the configuration file already defined for prometheus\n- `\u2014 storage.tsdb.path=/prometheus` **:** specifies the location of **tsdb** which is the index store used for holding our metrics\n- `\u2014 storage.tsdb.retention.time=7d`\\`: specifies the duration that prometheus is allowed to keep logs for before disposing them off.\n\n**NB:** You are able to configure retention also based on Disk size and storage space but our config focuses more on a time-based retention policy.\n\n**Verification and Testing** Everything runs in docker and therefore each service is containerized. Ensure to restart your docker container to allow these new changes to attach. If you are like who prefer to use GUIs, head over to the docker logs and search for \u201c **retention**\u201d in the log and you shall find traces of your retention policy being defined in the docker logs which basically means that your Prometheus instance now have retention activated. If youprefer terminal commands, run the command below:\n\n```\ndocker logs <prometheus-container-name>\n```\n\nThe Image below shows the result from my docker log showing my retention policy.\n\n![](https://miro.medium.com/v2/resize:fit:672/1*9ZYghkFbhcrgHiFDksU1pw.png)\n\n**Prometheus Container Docker Logs After Run**\n\nRetention configuring in Loki and Prometheus dont get easier than this. You may also se Grafana to test the behaviors of your services and see how they handle retention. For more detailed information, check out the official documentation here: [https://grafana.com/docs/loki/latest/operations/storage/retention/](https://grafana.com/docs/loki/latest/operations/storage/retention/)\n\nThank you!\n\n[Containerization](https://medium.com/tag/containerization?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[Docker](https://medium.com/tag/docker?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[Prometheus](https://medium.com/tag/prometheus?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[Grafana](https://medium.com/tag/grafana?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[DevOps](https://medium.com/tag/devops?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[![Faith Sodipe](https://miro.medium.com/v2/resize:fill:96:96/0*6zDALwKTapdArB48)](https://medium.com/@faithsodipe?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\n[![Faith Sodipe](https://miro.medium.com/v2/resize:fill:128:128/0*6zDALwKTapdArB48)](https://medium.com/@faithsodipe?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\nFollow\n\n[**Written by Faith Sodipe**](https://medium.com/@faithsodipe?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\n[15 followers](https://medium.com/@faithsodipe/followers?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\n\u00b7 [13 following](https://medium.com/@faithsodipe/following?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\nFollow\n\n[![DevOps.dev](https://miro.medium.com/v2/resize:fill:96:96/1*3SZtM9yhQyfh-dfWk5gGFw.jpeg)](https://blog.devops.dev/?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n[![DevOps.dev](https://miro.medium.com/v2/resize:fill:128:128/1*3SZtM9yhQyfh-dfWk5gGFw.jpeg)](https://blog.devops.dev/?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\nFollow\n\n[**Published in DevOps.dev**](https://blog.devops.dev/?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n[26K followers](https://blog.devops.dev/followers?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n\u00b7 [Last published\u00a014 hours ago](https://blog.devops.dev/building-a-kubernetes-cluster-from-scratch-using-kubeadm-475fa1d471bd?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n[Devops.dev](http://devops.dev/) is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.\n\nFollow\n\n[Help](https://help.medium.com/hc/en-us?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Status](https://status.medium.com/?source=post_page-----57e81bbad023-----------------------------------------)\n\n[About](https://medium.com/about?autoplay=1&source=post_page-----57e81bbad023-----------------------------------------)\n\n[Careers](https://medium.com/jobs-at-medium/work-at-medium-959d1a85284e?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Press](mailto:pressinquiries@medium.com)\n\n[Blog](https://blog.medium.com/?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Store](https://medium.com/store)\n\n[Privacy](https://policy.medium.com/medium-privacy-policy-f03bf92035c9?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Rules](https://policy.medium.com/medium-rules-30e5502c4eb4?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Terms](https://policy.medium.com/medium-terms-of-service-9db0094a1e0f?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Text to speech](https://speechify.com/medium?source=post_page-----57e81bbad023-----------------------------------------)\n\nreCAPTCHA\n\nRecaptcha requires verification.\n\nprotected by **reCAPTCHA**",
      "content_chars": 13666,
      "published_date": "2025-06-13T16:31:59"
    },
    {
      "rank": 6,
      "url": "https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/",
      "title": "Log retention | Grafana Enterprise Logs documentation",
      "content": "![ObservabilityCON 2025](https://a-us.storyblok.com/f/1022730/280x40/b0872b99f9/grafana-logo-observabilitycon-2025-black.svg/m/)\n\nWatch the keynote again and signup for more on-demand sessions.\n\n\n[Watch keynote](https://grafana.com/events/observabilitycon/?plcmt=obscon2025-post-event-banner)![](https://grafana.com/media/events/grafanacon/2025/icon-close-x.svg)\n\n![ObservabilityCON 2025](https://grafana.com/media/events/obscon/2025/grafana-obscon2025-promo-logo-black.svg)\n\n\ud83d\udce2 Registration + agenda now live\nExplore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).\n\n\n[Register now](https://grafana.com/events/observabilitycon/?tech=target&plcmt=top-banner&aud=default)\n\nSearching...\n\nSite search\n\nAsk Grot AI\n\n[Try using ![Grot AI](https://grafana.com/static/img/grot-chat.svg)**Grot AI** for this query ->](https://grafana.com/grot/?chat=&from=/search)\n\nAll\n\nDocs\n\nView all results\n\nNo results.\n\nThere was an error with your request.\n\n> Documentation for automated readers\n>\n> A curated documentation index is available at: https://grafana.com/llms.txt\n>\n> A complete documentation index is available at: https://grafana.com/llms-full.txt\n>\n> These indexes can help with page discovery before fetching individual documents.\n\nThis page is also available in Markdown, which may be easier for automated readers\nand AI tools to parse than HTML. The Markdown version is available at\nhttps://grafana.com/docs/enterprise-logs/latest/manage/storage/retention.md, or by sending\nAccept: text/markdown to https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/. For broader\ndocumentation discovery, the curated index is available at https://grafana.com/llms.txt\nand the complete index is available at https://grafana.com/llms-full.txt.\n\nLog retention\n\n[Documentation](https://grafana.com/docs/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Grafana Enterprise Logs](https://grafana.com/docs/enterprise-logs/latest/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Manage](https://grafana.com/docs/enterprise-logs/latest/manage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Storage](https://grafana.com/docs/enterprise-logs/latest/manage/storage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)Log retention\n\nEnterprise\n\n# Log retention\n\nRetention in Grafana Loki is achieved through the [Compactor](https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/#compactor).\nBy default the `compactor.retention-enabled` flag is not set, so the logs sent to Loki live forever.\n\n> Note\n>\n> If you have a lifecycle policy configured on the object store, please ensure that it is longer than the retention period.\n\nGranular retention policies to apply retention at per tenant or per stream level are also supported by the Compactor.\n\n> Note\n>\n> The Compactor does not support retention on\n> [legacy index types](https://grafana.com/docs/loki/latest/configure/storage/#index-storage). Please use the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) when using legacy index types.\n> Both the Table manager and legacy index types are deprecated and may be removed in future major versions of Loki.\n\n## Compactor\n\nThe Compactor is responsible for compaction of index files and applying log retention.\n\n> Note\n>\n> Run the Compactor as a singleton (a single instance).\n\nThe Compactor runs compaction and retention on two independent schedules:\n\n- Compaction runs every `compactor.compaction-interval`.\n- Retention runs every `compactor.apply-retention-interval`. If you leave this at its default of `0s`, Loki sets it to the same value as `compactor.compaction-interval`. Whenever the two intervals are equal, Loki extends the retention interval by the smaller of `10m` or half the interval, so that compaction and retention do not run at the same time. For example, with the default `compaction_interval` of `10m`, retention runs every `15m`.\n\nIf the Compactor falls behind on either schedule, it runs the corresponding operation as soon as possible.\nBoth compaction and retention are idempotent, which means once the action has been performed, if the action is performed multiple times, it has no further effect on logs after the first time it is performed. If the Compactor restarts, it continues from where it left off.\n\n> Note\n>\n> Changes to your retention period are not retroactive, that is, they are not applied to logs that have already been ingested.\n\nThe Compactor\u2019s algorithm to apply retention is as follows:\n\n- For each day or table (one table per day with 24h index period):\n  - Compact multiple index files in the table into per-tenant index files. Result of compaction is a single index file per tenant per day.\n  - Traverse the per-tenant index. Use the tenant configuration to identify the chunks that need to be removed.\n  - Remove the references to the matching chunks from the index and add the chunk references to a marker file on disk.\n  - Upload the new modified index files.\n\nChunks are not deleted while applying the retention algorithm on the index. They are deleted asynchronously by a sweeper process\nand this delay can be configured by setting `-compactor.retention-delete-delay`. Marker files are used to keep track of the chunks pending for deletion.\n\nChunks cannot be deleted immediately for the following reasons:\n\n- Index Gateway downloads a copy of the index files to serve queries and refreshes them at a regular interval.\nHaving a delay allows the index gateways to pull the modified index file which would not contain any reference to the chunks marked for deletion.\nWithout the delay, index files (that are stale) on the gateways could refer to already deleted chunks leading to query failures.\n\n- It provides a short window of time in which to cancel chunk deletion in the case of a configuration mistake.\n\n\nBy default, marker files are written to local disk, under `<working_directory>/retention/<object_store_type>_<period_from_date>/markers/`. Marker files should be stored on a persistent disk to ensure that the chunks pending for deletion are processed even if the Compactor process restarts.\n\n> Note\n>\n> Grafana Labs recommends running Compactor as a stateful deployment (StatefulSet when using Kubernetes) with a persistent storage for storing marker files.\n\nAlternatively, you can configure the Compactor to store marker files in object storage instead of local disk, by setting `compactor.deletion-marker-object-store-prefix` (`deletion_marker_object_store_prefix`) to a prefix that ends with `/`. When set, the Compactor writes marker files to the same per-period object store bucket used for chunks, under that prefix. On startup it also copies any existing marker files from local disk to that prefix, then removes the local copies. This lets you run the Compactor without a persistent volume for marker files. Leave this setting empty to keep using local disk.\n\n### Retention Configuration\n\nThis Compactor configuration example activates retention.\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\ncompactor:\n  working_directory: /data/retention\n  compaction_interval: 10m\n  retention_enabled: true\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n  delete_request_store: gcs\nschema_config:\n  configs:\n    - from: \"2020-07-31\"\n      index:\n        period: 24h\n        prefix: index_\n      object_store: gcs\n      schema: v13\n      store: tsdb\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /data/index\n    cache_location: /data/index_cache\n  gcs:\n    bucket_name: loki\n```\n\n> Note\n>\n> Retention is only available if the index period is 24h. Single store TSDB and single store BoltDB require 24h index period.\n\n`retention_enabled` should be set to true. Without this, the Compactor will only compact tables.\n\n`delete_request_store` should be set to configure the store for delete requests. This is required when retention is enabled.\n\n`working_directory` is the directory where marked chunks and temporary tables will be saved.\n\n`compaction_interval` dictates how often compaction is applied. If the Compactor falls behind, compaction occurs as soon as possible.\n\n`apply_retention_interval` dictates how often retention is applied, independently of `compaction_interval`. Refer to [Compactor](https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/#compactor) for how the default value is derived from `compaction_interval`.\n\n`retention_delete_delay` is the delay after which the Compactor will delete marked chunks.\n\n`retention_delete_worker_count` specifies the maximum quantity of goroutine workers instantiated to delete chunks.\n\nA few other options are also relevant when tuning retention:\n\n- `retention_table_timeout` bounds how long the Compactor spends applying retention and processing delete requests on any single table. It defaults to `0s`, meaning no timeout. If the work on a table exceeds this timeout, the Compactor logs a warning and stops early rather than failing, and the remaining work is picked up again on a later run.\n- `retention_backoff_config` controls the retry behavior (minimum and maximum backoff, and number of retries) used by the sweeper when it fails to delete a marked chunk.\n- `delete_request_store_key_prefix` sets the path prefix used to store delete requests within `delete_request_store` (default `index/`).\n- `delete_request_store_db_type` sets the type of database used to store delete requests (default `boltdb`).\n\nRefer to the\n[Configuration reference](https://grafana.com/docs/loki/latest/configure/#compactor) for the full list of `compactor` options and their defaults.\n\n#### Configuring the retention period\n\nRetention period is configured within the\n[`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) configuration section.\n\nThere are two ways of setting retention policies:\n\n- `retention_period` which is applied globally for all log streams.\n- `retention_stream` which is only applied to log streams matching the selector.\n\n> Note\n>\n> Each `retention_stream` rule\u2019s `period` must be at least 24h. Loki rejects configuration with a shorter value, both in the global `retention_stream` list and in any per-tenant override. This minimum does not apply to the `retention_period` setting, either globally or per tenant.\n\nThis example configures global retention that applies to all tenants (unless overridden by configuring per-tenant overrides):\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\n...\nlimits_config:\n  retention_period: 744h\n  retention_stream:\n  - selector: '{namespace=\"dev\"}'\n    priority: 1\n    period: 24h\n  per_tenant_override_config: /etc/overrides.yaml\n...\n```\n\n> Note\n>\n> You can only use label matchers in the `selector` field of a `retention_stream` definition. Arbitrary LogQL expressions are not supported.\n\nPer tenant retention can be defined by configuring\n[runtime overrides](https://grafana.com/docs/loki/latest/configure/#runtime-configuration-file). For example:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\noverrides:\n    \"29\":\n        retention_period: 168h\n        retention_stream:\n        - selector: '{namespace=\"prod\"}'\n          priority: 2\n          period: 336h\n        - selector: '{container=\"loki\"}'\n          priority: 1\n          period: 72h\n    \"30\":\n        retention_stream:\n        - selector: '{container=\"nginx\", level=\"debug\"}'\n          priority: 1\n          period: 24h\n```\n\nRetention period for a given stream is decided based on the first match in this list:\n\n1. If multiple per-tenant `retention_stream` selectors match the stream, retention period with the highest priority is picked.\n2. If multiple global `retention_stream` selectors match the stream, retention period with the highest priority is picked. This value is not considered if per-tenant `retention_stream` is set.\n3. If a per-tenant `retention_period` is specified, it will be applied.\n4. The global `retention_period` will be applied if none of the above match.\n5. If no global `retention_period` is specified, the default value of `0s` is used, which means logs are kept indefinitely.\n\n> Note\n>\n> The larger the priority value, the higher the priority. If two matching `retention_stream` rules have the same priority, Loki applies the shorter (lowest) of the two periods.\n\nStream matching uses the same syntax as Prometheus label matching:\n\n- `=`: Select labels that are exactly equal to the provided string.\n- `!=`: Select labels that are not equal to the provided string.\n- `=~`: Select labels that regex-match the provided string.\n- `!~`: Select labels that do not regex-match the provided string.\n\nThe example configurations defined above will result in the following retention periods:\n\n- For tenant `29`:\n  - Streams that have the namespace label `prod` will have a retention period of `336h` (2 weeks), even if the container label is `loki`, since the priority of the `prod` rule is higher.\n  - Streams that have the container label `loki` but are not in the namespace `prod` will have a `72h` retention period.\n  - For the rest of the streams in this tenant, per-tenant override `retention_period` value of `168h` is applied.\n- For tenant `30`:\n  - Streams that have the label `nginx` and level `debug` will have a retention period of `24h`.\n  - For the rest of the streams in this tenant the global retention period of `744h`, since there is no override specified.\n- All tenants except `29` and `30`:\n  - Streams that have the namespace label `dev` will have a retention period of `24h` hours.\n  - Streams except those with the namespace label `dev` will have the retention period of `744h`.\n\n> Note\n>\n> If you are a Grafana Cloud customer, you can use the [config self-serve API](https://grafana.com/docs/grafana-cloud/send-data/logs/config-self-serve/#configure-retention) to configure your tenant retention.\n\n## Table Manager (deprecated)\n\nRetention through the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) is\nachieved by relying on the object store TTL feature, and will work for both\n[boltdb-shipper](https://grafana.com/docs/loki/latest/operations/storage/boltdb-shipper/) store and chunk/index stores.\n\nIn order to enable the retention support, the Table Manager needs to be\nconfigured to enable deletions and a retention period. Please refer to the\n[`table_manager`](https://grafana.com/docs/loki/latest/configure/#table_manager)\nsection of the Loki configuration reference for all available options.\nAlternatively, the `table-manager.retention-period` and\n`table-manager.retention-deletes-enabled` command line flags can be used. The\nprovided retention period needs to be a duration represented as a string that\ncan be parsed using the Prometheus common model [ParseDuration](https://pkg.go.dev/github.com/prometheus/common/model#ParseDuration). Examples: `7d`, `1w`, `168h`.\n\n> Warning\n>\n> The retention period must be a multiple of the index and chunks table\n> `period`, configured in the\n> [`period_config`](https://grafana.com/docs/loki/latest/configure/#period_config) block.\n> See the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/#retention) documentation for\n> more information.\n\n> Note\n>\n> To avoid querying of data beyond the retention period,`max_query_lookback` config in\n> [`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) must be set to a value less than or equal to what is set in `table_manager.retention_period`.\n\nWhen using S3 or GCS, the bucket storing the chunks needs to have the expiry\npolicy set correctly. For more details check\n[S3\u2019s documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)\nor\n[GCS\u2019s documentation](https://cloud.google.com/storage/docs/managing-lifecycles).\n\nIf you must delete ingested logs, you can delete old chunks in your object store. Note,\nhowever, that this only deletes the log content and keeps the label index\nintact; you will still be able to see related labels but will be unable to\nretrieve the deleted log content.\n\nFor further details on the Table Manager internals, refer to the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) documentation.\n\nAlternatively, if the BoltDB Shipper is configured for the index store, you can enable\n[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) to delete log entries from a specific stream.\n\n## Example Configuration\n\nExample configuration with GCS with a 28 day retention:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\nschema_config:\n  configs:\n    - from: 2018-04-15\n      store: tsdb\n      object_store: gcs\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /loki/index\n    cache_location: /loki/index_cache\n  gcs:\n    bucket_name: GCS_BUCKET_NAME\n\nlimits_config:\n  max_query_lookback: 672h # 28 days\n  retention_period: 672h   # 28 days\n\ncompactor:\n  working_directory: /data/retention\n  delete_request_store: gcs\n  retention_enabled: true\n```\n\n## Object store lifecycle policies\n\nLoki stores chunks and indexes as objects in the configured object store (S3, GCS, Azure Blob Storage, and so on). Chunks are deleted by the [Compactor](https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/#compactor) according to your configured retention, but the Compactor only removes chunk objects: it never deletes the objects that hold cluster state, such as the index or the cluster seed.\n\nIf you also configure an object store lifecycle policy on the bucket, scope it carefully. A blanket \u201cdelete everything older than N days\u201d rule will eventually remove objects that Loki must keep, which corrupts the store and causes query failures. The note at the top of this page applies here as well: any lifecycle expiration must be longer than your retention period.\n\n> Warning\n>\n> Never apply a lifecycle rule with an empty prefix (one that targets the whole bucket). Always scope lifecycle rules to the per-tenant chunk prefixes described below.\n\n### Bucket object layout\n\nThe following objects are written to the configured bucket. The exact prefixes depend on your `schema_config` and on whether multi-tenancy is enabled, so confirm them against your own configuration before writing a lifecycle rule.\n\nExpand table\n\n| Object or prefix | Content | Safe to expire with a lifecycle policy? |\n| --- | --- | --- |\n| `<tenant_id>/` (for example, `fake/` in single-tenant mode, or your org ID per tenant) | Chunk objects (the log data). | Yes. These are the only objects a lifecycle rule should target. |\n| Index objects (under the index path prefix, `index/` by default, set by `index.path_prefix` in `schema_config`) | TSDB or BoltDB index files, written by ingesters and rewritten by the Compactor. The `index.prefix` value (for example `index_` or `loki_index_`) is the table-name prefix used inside this path, not the path itself, so match a lifecycle rule against the path prefix. | No. Loki manages the index lifecycle internally. Deleting index objects removes references to live chunks and breaks queries. |\n| `loki_cluster_seed.json` | A small file at the bucket root holding the cluster seed used by usage reporting. It is written once and never rotated. | No. A blanket age-based rule will delete it once it ages past the time to live (TTL). |\n| Delete-request store objects (a `delete_requests/` table under `delete_request_store_key_prefix`, `index/` by default, in the bucket configured by `delete_request_store`) | The Compactor\u2019s database of delete requests submitted through the<br>[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) API, and their processing status. | No. Removing these makes the Compactor lose track of pending delete requests. |\n| Deletion marker objects (only present if you set `deletion_marker_object_store_prefix`; otherwise markers are kept on the Compactor\u2019s local disk and never appear in the bucket) | The Compactor\u2019s record of chunks that are marked for deletion but not yet swept. Written under the configured prefix in the same per-period bucket used for chunks. | No. Removing these makes the Compactor lose track of chunks pending deletion. |\n| Ruler store objects (if the Ruler is backed by the same bucket) | Recording and alerting rule files. | No. These are configuration, not time-series data. |\n\n### Compactor retention versus object store lifecycle policies\n\nCompactor retention and object store lifecycle policies are two independent mechanisms, and they should not be configured in ways that conflict:\n\n- The Compactor is index-aware. It only deletes a chunk after it has removed every reference to that chunk from the index, and it waits `compactor.retention-delete-delay` (default `2h`) before the sweeper deletes the marked chunk, so that index gateways pick up the rewritten index first.\n- An object store lifecycle policy is index-unaware. It deletes objects purely by age and prefix, with no knowledge of whether a chunk is still referenced by the index.\n\nFor most deployments, enabling Compactor retention is sufficient and an object store lifecycle policy is not required. If you do add a lifecycle policy as a cost safety net, set its expiration **longer** than your retention period plus `compactor.retention-delete-delay`, so the Compactor always deletes chunks first and the lifecycle rule only ever catches objects the Compactor has already orphaned.\n\n### Example: Amazon S3 lifecycle policy\n\nThis policy expires only chunk objects under a single tenant prefix. Replace `fake/` with your tenant prefix (use one rule per tenant, or your org ID prefix, when multi-tenancy is enabled). The `Days` value must be larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-chunk-expiration\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"fake/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 395\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the AWS CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\naws s3api put-bucket-lifecycle-configuration \\\n  --bucket YOUR_LOKI_BUCKET \\\n  --lifecycle-configuration file://lifecycle.json\n```\n\n### Example: Google Cloud Storage lifecycle rule\n\nThe equivalent GCS rule expires objects by age and prefix. As with S3, scope `matchesPrefix` to the tenant chunk prefix and keep `age` larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"rule\": [\\\n    {\\\n      \"action\": {\"type\": \"Delete\"},\\\n      \"condition\": {\\\n        \"age\": 395,\\\n        \"matchesPrefix\": [\"fake/\"]\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the Google Cloud CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\ngcloud storage buckets update gs://YOUR_LOKI_BUCKET --lifecycle-file=lifecycle.json\n```\n\nFor Azure Blob Storage, use a management policy with a `prefixMatch` set to the tenant chunk prefix and the same \u201cexpiration must exceed retention plus delete delay\u201d rule.\n\n## Was this page helpful?\n\n![\ud83d\udc4d](https://grafana.com/media/images/svg/thumbs-up.svg) Yes![\ud83d\udc4e](https://grafana.com/media/images/svg/thumbs-up.svg) No\n\n[Email docs@grafana.com](mailto:docs@grafana.com) [Help and support](https://grafana.com/help/) [Community](https://grafana.com/community/)\n\n## Related resources from Grafana Labs\n\nAdditional helpful documentation, links, and articles:\n\n[![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Scaling and securing your logs with Grafana Loki](https://grafana.com/static/assets/featured/scaling-and-securing-your-logs-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nScaling and securing your logs with Grafana Loki\\\\\n\\\\\nThis webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.](https://grafana.com/go/webinar/scaling-and-securing-your-logs-with-grafana-loki/?pg=docs-enterprise-logs-latest-manage-storage-retention&plcmt=related) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Managing privacy in log data with Grafana Loki](https://grafana.com/static/assets/featured/managing-privacy-in-log-data-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nManaging privacy in log data with Grafana Loki\\\\\n\\\\\nLaws for data privacy are complex and rapidly changing. During this webinar, we will show how Grafana Loki can help organizations meet these requirements.](https://grafana.com/go/webinar/managing-log-privacy-with-loki/?pg=docs-enterprise-logs-latest-manage-storage-retention&plcmt=related-2)\n\nAsk Grafana Assistant",
      "content_chars": 25580,
      "published_date": null
    },
    {
      "rank": 7,
      "url": "https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view",
      "title": "How to Implement Loki Retention Strategies",
      "content": "[Skip to main content](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view#main-content)\n\n![](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view)\n\n# How to Implement Loki Retention Strategies\n\nConfigure Grafana Loki retention policies with compactor-based deletion, per-tenant limits, and storage tiering for cost-effective log management.\n\n\n![Nawaz Dhandala](https://avatars.githubusercontent.com/nawazdhandala?s=64)\n\nBy @nawazdhandala\n\n\u2022Jan 30, 2026\u2022Reading time\n10 min read\n\n[Loki](https://oneuptime.com/blog/tag/loki) [Logging](https://oneuptime.com/blog/tag/logging) [Observability](https://oneuptime.com/blog/tag/observability) [Storage](https://oneuptime.com/blog/tag/storage)\n\n## On this page\n\n[Share on X](https://twitter.com/intent/tweet?text=%20How%20to%20Implement%20Loki%20Retention%20Strategies&url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on X\")[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on LinkedIn\")[Discuss on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview&t=%20How%20to%20Implement%20Loki%20Retention%20Strategies \"Discuss on Hacker News\")\n\n* * *\n\n## Introduction [Link to Introduction](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#introduction)\n\nManaging log retention in Grafana Loki requires understanding how Loki stores data and which components handle deletion. Unlike traditional databases where you simply set a TTL, Loki's architecture involves chunks, indexes, and a compactor service that work together to enforce retention policies.\n\nThis guide covers the practical implementation of retention strategies in Loki, from basic configuration to advanced per-tenant overrides. We will walk through working configurations, explain the trade-offs between different approaches, and help you build a retention strategy that balances cost with operational requirements.\n\n## Understanding Loki's Storage Model [Link to Understanding Loki's Storage Model](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#understanding-loki-s-storage-model)\n\nBefore diving into retention configuration, you need to understand how Loki stores logs.\n\n### Chunks and Indexes [Link to Chunks and Indexes](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#chunks-and-indexes)\n\nLoki stores log data in two types of objects:\n\n| Component | Purpose | Storage Backend |\n| --- | --- | --- |\n| Chunks | Compressed log data | Object storage (S3, GCS, filesystem) |\n| Index | Metadata for querying chunks | BoltDB, Cassandra, or object storage (TSDB) |\n\nChunks contain the actual log lines, compressed and grouped by stream. The index maps labels and time ranges to specific chunks, enabling efficient queries.\n\n### The TSDB Index (Recommended) [Link to The TSDB Index (Recommended)](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#the-tsdb-index-recommended)\n\nStarting with Loki 2.8, the TSDB index is the recommended schema. It stores indexes in object storage alongside chunks, simplifying operations and enabling better retention handling.\n\nHere is a basic schema configuration using TSDB:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\n\nschema_config:\n  configs:\n    - from: 2024-01-01\n      store: tsdb\n      object_store: s3\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n```\n\nThe `period: 24h` setting creates daily index tables. This matters for retention because deletion happens at the table level for older index types.\n\n## Compactor-Based Retention [Link to Compactor-Based Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#compactor-based-retention)\n\nThe compactor is Loki's primary mechanism for enforcing retention. It runs as a separate target (or within the single binary) and handles chunk deletion based on configured policies.\n\n### Enabling the Compactor [Link to Enabling the Compactor](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#enabling-the-compactor)\n\nFirst, enable the compactor and configure retention:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\ncompactor:\n  # Working directory for compaction\n  working_directory: /loki/compactor\n\n  # How often the compactor runs\n  compaction_interval: 10m\n\n  # Enable retention enforcement\n  retention_enabled: true\n\n  # Store used for delete requests\n  delete_request_store: s3\n\n  # How often to check for chunks to delete\n  retention_delete_delay: 2h\n\n  # Number of workers for deletion\n  retention_delete_worker_count: 150\n\n  # Delete request cancel period\n  delete_request_cancel_period: 24h\n```\n\nThe `retention_delete_delay` parameter adds a safety buffer. Chunks marked for deletion wait this duration before actual removal. This gives you time to cancel accidental deletions.\n\n### Global Retention Period [Link to Global Retention Period](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#global-retention-period)\n\nSet a default retention period that applies to all tenants:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\nlimits_config:\n  # Global retention period - logs older than this are deleted\n  retention_period: 744h  # 31 days\n```\n\nThe `retention_period` value uses Go duration format. Common values:\n\n| Duration | Days | Use Case |\n| --- | --- | --- |\n| 168h | 7 | Development environments |\n| 720h | 30 | Standard production |\n| 2160h | 90 | Compliance requirements |\n| 8760h | 365 | Long-term audit logs |\n\n### Complete Basic Configuration [Link to Complete Basic Configuration](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#complete-basic-configuration)\n\nHere is a complete configuration enabling compactor retention with S3 storage:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\nauth_enabled: false\n\nserver:\n  http_listen_port: 3100\n  grpc_listen_port: 9096\n\ncommon:\n  path_prefix: /loki\n  storage:\n    s3:\n      endpoint: s3.us-east-1.amazonaws.com\n      bucketnames: loki-chunks\n      region: us-east-1\n      access_key_id: ${AWS_ACCESS_KEY_ID}\n      secret_access_key: ${AWS_SECRET_ACCESS_KEY}\n      s3forcepathstyle: false\n  replication_factor: 1\n  ring:\n    kvstore:\n      store: inmemory\n\nschema_config:\n  configs:\n    - from: 2024-01-01\n      store: tsdb\n      object_store: s3\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /loki/tsdb-index\n    cache_location: /loki/tsdb-cache\n    cache_ttl: 24h\n\ncompactor:\n  working_directory: /loki/compactor\n  compaction_interval: 10m\n  retention_enabled: true\n  delete_request_store: s3\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n\nlimits_config:\n  retention_period: 720h  # 30 days\n  ingestion_rate_mb: 10\n  ingestion_burst_size_mb: 20\n  max_streams_per_user: 10000\n  max_entries_limit_per_query: 5000\n```\n\n## Per-Tenant Retention Overrides [Link to Per-Tenant Retention Overrides](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#per-tenant-retention-overrides)\n\nIn multi-tenant deployments, different teams often have different retention requirements. Loki supports per-tenant overrides through a runtime configuration file.\n\n### Configuring Runtime Overrides [Link to Configuring Runtime Overrides](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#configuring-runtime-overrides)\n\nFirst, tell Loki where to find the overrides file:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\nruntime_config:\n  file: /loki/runtime-config.yaml\n  period: 10s  # How often to reload\n```\n\nThen create the overrides file:\n\n```yaml\nYAMLCopy\n# runtime-config.yaml\noverrides:\n  # Team with short retention needs\n  team-development:\n    retention_period: 168h  # 7 days\n    ingestion_rate_mb: 5\n    max_streams_per_user: 5000\n\n  # Team requiring longer retention for compliance\n  team-security:\n    retention_period: 8760h  # 365 days\n    ingestion_rate_mb: 20\n    max_streams_per_user: 50000\n\n  # Default tenant with standard settings\n  team-platform:\n    retention_period: 720h  # 30 days\n```\n\n### Stream-Based Retention [Link to Stream-Based Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#stream-based-retention)\n\nYou can apply different retention periods based on log stream selectors. This enables fine-grained control within a single tenant.\n\n```yaml\nYAMLCopy\n# runtime-config.yaml\noverrides:\n  production:\n    retention_period: 720h  # Default: 30 days\n    retention_stream:\n      # Keep error logs longer\n      - selector: '{level=\"error\"}'\n        priority: 1\n        period: 2160h  # 90 days\n\n      # Keep audit logs for compliance\n      - selector: '{log_type=\"audit\"}'\n        priority: 2\n        period: 8760h  # 365 days\n\n      # Delete debug logs quickly\n      - selector: '{level=\"debug\"}'\n        priority: 3\n        period: 72h  # 3 days\n\n      # Short retention for high-volume health checks\n      - selector: '{endpoint=\"/health\"}'\n        priority: 4\n        period: 24h  # 1 day\n```\n\nThe `priority` field determines which rule wins when multiple selectors match. Higher priority values take precedence.\n\n### Dynamic Override Reloading [Link to Dynamic Override Reloading](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#dynamic-override-reloading)\n\nThe compactor automatically reloads runtime configuration at the interval specified by `period`. To verify overrides are applied, check the compactor logs:\n\n```bash\nBashCopy\n# View compactor logs for retention activity\nkubectl logs -l app=loki-compactor | grep -i retention\n```\n\nYou should see entries like:\n\n```plaintext\nTextCopy\nlevel=info ts=2026-01-30T10:00:00.000Z caller=compactor.go:450 msg=\"applying retention\" tenant=team-security retention=8760h0m0s\n```\n\n## Table Manager vs Compactor Retention [Link to Table Manager vs Compactor Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#table-manager-vs-compactor-retention)\n\nLoki historically used the Table Manager for retention with BoltDB indexes. Understanding the differences helps when migrating or maintaining older deployments.\n\n### Comparison [Link to Comparison](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#comparison)\n\n| Feature | Table Manager | Compactor |\n| --- | --- | --- |\n| Index Support | Legacy chunk/index stores and BoltDB-shipper | TSDB and BoltDB-shipper |\n| Deletion Granularity | Table-level | Chunk-level |\n| Per-Tenant Overrides | Limited | Full support |\n| Stream Selectors | No | Yes |\n| Status | Deprecated | Recommended |\n\n### Table Manager Configuration (Legacy) [Link to Table Manager Configuration (Legacy)](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#table-manager-configuration-legacy)\n\nIf you are still running BoltDB indexes, here is how Table Manager retention works:\n\n```yaml\nYAMLCopy\n# loki-config.yaml (legacy configuration)\ntable_manager:\n  retention_deletes_enabled: true\n  retention_period: 720h  # 30 days\n\n  # Table creation settings\n  index_tables_provisioning:\n    inactive_read_throughput: 1\n    inactive_write_throughput: 1\n    provisioned_read_throughput: 100\n    provisioned_write_throughput: 100\n\n  chunk_tables_provisioning:\n    inactive_read_throughput: 1\n    inactive_write_throughput: 1\n    provisioned_read_throughput: 100\n    provisioned_write_throughput: 100\n```\n\n### Migration Path [Link to Migration Path](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#migration-path)\n\nTo migrate from Table Manager to Compactor retention:\n\n1. Deploy the new schema alongside the old one\n2. Enable compactor retention for new data\n3. Let Table Manager handle old data until it ages out\n4. Remove Table Manager configuration after full migration\n\n```yaml\nYAMLCopy\n# Schema configuration for migration\nschema_config:\n  configs:\n    # Old schema - Table Manager handles retention\n    - from: 2023-01-01\n      store: boltdb-shipper\n      object_store: s3\n      schema: v12\n      index:\n        prefix: loki_index_\n        period: 24h\n\n    # New schema - Compactor handles retention\n    - from: 2024-06-01\n      store: tsdb\n      object_store: s3\n      schema: v13\n      index:\n        prefix: loki_tsdb_\n        period: 24h\n```\n\n## Deletion Markers and the Deletion API [Link to Deletion Markers and the Deletion API](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#deletion-markers-and-the-deletion-api)\n\nBeyond automatic retention, Loki supports manual deletion through its API. This is useful for removing sensitive data or clearing specific log streams.\n\n### Enabling the Deletion API [Link to Enabling the Deletion API](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#enabling-the-deletion-api)\n\n```yaml\nYAMLCopy\n# loki-config.yaml\ncompactor:\n  retention_enabled: true\n  delete_request_cancel_period: 24h\n  delete_request_store: s3\n\n# runtime-config.yaml\noverrides:\n  tenant-a:\n    deletion_mode: filter-and-delete\n```\n\n### Creating Delete Requests [Link to Creating Delete Requests](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#creating-delete-requests)\n\nUse the deletion API to mark logs for removal:\n\n```bash\nBashCopy\n# Delete all logs matching a selector within a time range\ncurl -X POST \\\n  \"http://loki:3100/loki/api/v1/delete\" \\\n  -H \"Content-Type: application/x-www-form-urlencoded\" \\\n  -d \"query={app=\\\"legacy-service\\\"}\" \\\n  -d \"start=1704067200\" \\\n  -d \"end=1706745600\"\n```\n\nThe timestamps are Unix timestamps in seconds or RFC3339 timestamps. Convert from dates:\n\n```bash\nBashCopy\n# Convert dates to Unix timestamps in seconds\nSTART=$(date -d \"2024-01-01\" +%s)\nEND=$(date -d \"2024-02-01\" +%s)\n\ncurl -X POST \\\n  \"http://loki:3100/loki/api/v1/delete\" \\\n  -d \"query={app=\\\"legacy-service\\\"}\" \\\n  -d \"start=${START}\" \\\n  -d \"end=${END}\"\n```\n\n### Listing and Canceling Delete Requests [Link to Listing and Canceling Delete Requests](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#listing-and-canceling-delete-requests)\n\nView pending deletions:\n\n```bash\nBashCopy\n# List all delete requests\ncurl \"http://loki:3100/loki/api/v1/delete\"\n```\n\nResponse:\n\n```json\nJSONCopy\n[\\\n  {\\\n    \"request_id\": \"abc123\",\\\n    \"start_time\": 1704067200,\\\n    \"end_time\": 1706745600,\\\n    \"query\": \"{app=\\\"legacy-service\\\"}\",\\\n    \"status\": \"received\",\\\n    \"created_at\": 1706800000\\\n  }\\\n]\n```\n\nCancel a pending deletion (within the cancel period):\n\n```bash\nBashCopy\ncurl -X DELETE \\\n  \"http://loki:3100/loki/api/v1/delete?request_id=abc123\"\n```\n\n### Delete Request States [Link to Delete Request States](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#delete-request-states)\n\n| State | Description |\n| --- | --- |\n| received | Request received, waiting for cancel period |\n| building | Cancel period passed, building deletion plan |\n| deleting | Actively deleting chunks |\n| processed | Deletion complete |\n\n## Storage Considerations [Link to Storage Considerations](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#storage-considerations)\n\nRetention configuration directly impacts storage costs and performance. Here are key considerations for production deployments.\n\n### Object Storage Lifecycle Policies [Link to Object Storage Lifecycle Policies](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#object-storage-lifecycle-policies)\n\nCombine Loki retention with cloud provider lifecycle policies for defense in depth:\n\n```json\nJSONCopy\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-chunks-cleanup\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"loki/chunks/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 45\\\n      }\\\n    },\\\n    {\\\n      \"ID\": \"loki-index-cleanup\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"loki/index/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 45\\\n      }\\\n    }\\\n  ]\n}\n```\n\nSet the lifecycle policy expiration slightly longer than your Loki retention to catch any orphaned objects.\n\n### Storage Tiering for Cost Optimization [Link to Storage Tiering for Cost Optimization](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#storage-tiering-for-cost-optimization)\n\nMove older logs to cheaper storage tiers before deletion:\n\n```json\nJSONCopy\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-tiering\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"loki/\"\\\n      },\\\n      \"Transitions\": [\\\n        {\\\n          \"Days\": 7,\\\n          \"StorageClass\": \"STANDARD_IA\"\\\n        },\\\n        {\\\n          \"Days\": 30,\\\n          \"StorageClass\": \"GLACIER_IR\"\\\n        }\\\n      ],\\\n      \"Expiration\": {\\\n        \"Days\": 90\\\n      }\\\n    }\\\n  ]\n}\n```\n\n### Chunk Size and Compression [Link to Chunk Size and Compression](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#chunk-size-and-compression)\n\nOptimize chunk configuration to reduce storage:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\ningester:\n  chunk_encoding: snappy  # Options: gzip, lz4, snappy, zstd\n  chunk_target_size: 1572864  # 1.5MB target\n  chunk_idle_period: 30m\n  chunk_block_size: 262144  # 256KB\n\n  # Flush chunks before they get too old\n  max_chunk_age: 2h\n\n  # Number of chunks to keep in memory\n  chunk_retain_period: 30s\n```\n\nCompression comparison:\n\n| Algorithm | Compression Ratio | CPU Usage | Best For |\n| --- | --- | --- | --- |\n| snappy | Good | Low | General use |\n| lz4 | Good | Low | High throughput |\n| gzip | Better | Medium | Storage constrained |\n| zstd | Best | Medium-High | Cold storage |\n\n## Monitoring Retention [Link to Monitoring Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#monitoring-retention)\n\nTrack retention effectiveness with these metrics.\n\n### Key Compactor Metrics [Link to Key Compactor Metrics](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#key-compactor-metrics)\n\n```yaml\nYAMLCopy\n# Prometheus recording rules for retention monitoring\ngroups:\n  - name: loki-retention\n    rules:\n      # Compactor deletion rate\n      - record: loki:compactor:deleted_lines_per_hour\n        expr: |\n          sum(rate(loki_compactor_deleted_lines[1h])) * 3600\n\n      # Pending deletion requests\n      - record: loki:compactor:pending_deletions\n        expr: |\n          sum(loki_compactor_pending_delete_requests_count)\n\n      # Compaction lag\n      - record: loki:compactor:lag_seconds\n        expr: |\n          time() - max(loki_compactor_apply_retention_last_successful_run_timestamp_seconds)\n```\n\n### Alerting Rules [Link to Alerting Rules](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#alerting-rules)\n\n```yaml\nYAMLCopy\n# Prometheus alerting rules\ngroups:\n  - name: loki-retention-alerts\n    rules:\n      # Alert if compactor is not running\n      - alert: LokiCompactorNotRunning\n        expr: |\n          time() - max(loki_compactor_apply_retention_last_successful_run_timestamp_seconds) > 3600\n        for: 15m\n        labels:\n          severity: warning\n        annotations:\n          summary: \"Loki compactor has not run in over an hour\"\n          description: \"Retention policies are not being enforced\"\n\n      # Alert on high deletion backlog\n      - alert: LokiDeletionBacklog\n        expr: |\n          loki_compactor_pending_delete_requests_count > 100\n        for: 1h\n        labels:\n          severity: warning\n        annotations:\n          summary: \"High number of pending deletion requests\"\n\n      # Alert if old delete requests are not being processed\n      - alert: LokiOldestDeleteRequestStalled\n        expr: |\n          loki_compactor_oldest_pending_delete_request_age_seconds > 86400\n        for: 6h\n        labels:\n          severity: info\n        annotations:\n          summary: \"Old Loki delete requests are still pending\"\n```\n\n### Grafana Dashboard Queries [Link to Grafana Dashboard Queries](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#grafana-dashboard-queries)\n\nCreate a retention monitoring dashboard:\n\n```sql\nSQLCopy\n-- Deleted lines over time\nsum(rate(loki_compactor_deleted_lines[$__rate_interval])) by (user)\n\n-- Pending delete requests\nsum(loki_compactor_pending_delete_requests_count)\n\n-- Delete requests processed over time\nsum(rate(loki_compactor_delete_requests_processed_total[$__rate_interval])) by (user)\n\n-- Oldest pending delete request age\nmax(loki_compactor_oldest_pending_delete_request_age_seconds)\n```\n\n## Production Deployment Patterns [Link to Production Deployment Patterns](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#production-deployment-patterns)\n\n### Single Binary with Retention [Link to Single Binary with Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#single-binary-with-retention)\n\nFor smaller deployments, run everything in one process:\n\n```yaml\nYAMLCopy\n# docker-compose.yml\nservices:\n  loki:\n    image: grafana/loki:3.7.1\n    ports:\n      - \"3100:3100\"\n    volumes:\n      - ./loki-config.yaml:/etc/loki/config.yaml\n      - ./runtime-config.yaml:/loki/runtime-config.yaml\n      - loki-data:/loki\n    command: -config.file=/etc/loki/config.yaml -target=all\n\nvolumes:\n  loki-data:\n```\n\n### Dedicated Compactor in Microservices Mode [Link to Dedicated Compactor in Microservices Mode](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#dedicated-compactor-in-microservices-mode)\n\nFor larger deployments, run the compactor as a dedicated service:\n\n```yaml\nYAMLCopy\n# kubernetes/compactor-deployment.yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: loki-compactor\nspec:\n  replicas: 1  # Only one compactor instance\n  selector:\n    matchLabels:\n      app: loki-compactor\n  template:\n    metadata:\n      labels:\n        app: loki-compactor\n    spec:\n      containers:\n        - name: compactor\n          image: grafana/loki:3.7.1\n          args:\n            - -config.file=/etc/loki/config.yaml\n            - -target=compactor\n          ports:\n            - containerPort: 3100\n              name: http\n          volumeMounts:\n            - name: config\n              mountPath: /etc/loki\n            - name: data\n              mountPath: /loki\n          resources:\n            requests:\n              cpu: 500m\n              memory: 1Gi\n            limits:\n              cpu: 2000m\n              memory: 4Gi\n      volumes:\n        - name: config\n          configMap:\n            name: loki-config\n        - name: data\n          persistentVolumeClaim:\n            claimName: loki-compactor-data\n```\n\nThe compactor must run as a singleton. Running multiple instances causes data corruption.\n\n### Helm Chart Configuration [Link to Helm Chart Configuration](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#helm-chart-configuration)\n\nUsing the official Loki Helm chart:\n\n```yaml\nYAMLCopy\n# values.yaml\nloki:\n  auth_enabled: false\n\n  commonConfig:\n    replication_factor: 1\n\n  storage:\n    type: s3\n    bucketNames:\n      chunks: loki-chunks\n      ruler: loki-ruler\n      admin: loki-admin\n    s3:\n      endpoint: s3.us-east-1.amazonaws.com\n      region: us-east-1\n\n  storage_config:\n    aws:\n      region: us-east-1\n      bucketnames: loki-chunks\n      s3forcepathstyle: false\n\n  schemaConfig:\n    configs:\n      - from: 2024-01-01\n        store: tsdb\n        object_store: s3\n        schema: v13\n        index:\n          prefix: loki_index_\n          period: 24h\n\n  limits_config:\n    retention_period: 720h\n\n  compactor:\n    retention_enabled: true\n    delete_request_store: s3\n    retention_delete_delay: 2h\n    retention_delete_worker_count: 150\n\n  # Runtime configuration for per-tenant overrides\n  runtimeConfig:\n    overrides:\n      team-a:\n        retention_period: 168h\n      team-b:\n        retention_period: 2160h\n\ncompactor:\n  replicas: 1\n  persistence:\n    enabled: true\n    claims:\n      - name: data\n        size: 10Gi\n```\n\n## Troubleshooting Retention Issues [Link to Troubleshooting Retention Issues](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#troubleshooting-retention-issues)\n\n### Logs Not Being Deleted [Link to Logs Not Being Deleted](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#logs-not-being-deleted)\n\nCheck the compactor is running and retention is enabled:\n\n```bash\nBashCopy\n# Check compactor status\ncurl http://loki:3100/compactor/ring\n\n# Check if retention is enabled in config\ncurl http://loki:3100/config | grep -A 10 \"compactor\"\n```\n\nCommon causes:\n\n- `retention_enabled: false` in config\n- Compactor not reaching the chunks (network or permission issues)\n- Delete delay has not passed yet\n\n### Debugging Retention Boundaries [Link to Debugging Retention Boundaries](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#debugging-retention-boundaries)\n\nVerify what the compactor sees as retention boundaries:\n\n```bash\nBashCopy\n# Check compactor logs for retention decisions\nkubectl logs deployment/loki-compactor | grep \"retention boundary\"\n```\n\n### Storage Not Decreasing [Link to Storage Not Decreasing](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#storage-not-decreasing)\n\nIf storage does not decrease after retention runs:\n\n1. Check if lifecycle policies are conflicting\n2. Verify the compactor has write access to delete objects\n3. Look for orphaned chunks from failed compactions\n\n```bash\nBashCopy\n# List objects that should have been deleted\naws s3 ls s3://loki-chunks/chunks/ --recursive | \\\n  awk '$1 < \"2024-01-01\" {print $4}'\n```\n\n### Per-Tenant Overrides Not Applied [Link to Per-Tenant Overrides Not Applied](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#per-tenant-overrides-not-applied)\n\nVerify runtime config is loaded:\n\n```bash\nBashCopy\n# Check runtime config hash\ncurl http://loki:3100/runtime_config?mode=diff\n```\n\nEnsure the tenant ID matches exactly (case-sensitive).\n\n## Best Practices Summary [Link to Best Practices Summary](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#best-practices-summary)\n\n1. **Start with compactor retention** \\- Table Manager is deprecated and has limited functionality.\n\n2. **Set conservative defaults** \\- Start with longer retention and reduce based on observed usage patterns.\n\n3. **Use stream selectors wisely** \\- Apply longer retention only to high-value logs like errors and audit trails.\n\n4. **Monitor compaction lag** \\- A backlog indicates the compactor cannot keep up with ingestion.\n\n5. **Combine with lifecycle policies** \\- Use cloud provider policies as a safety net, not the primary mechanism.\n\n6. **Test deletion in staging** \\- Verify retention policies work correctly before applying to production.\n\n7. **Document retention policies** \\- Teams need to know how long their logs persist for debugging and compliance.\n\n8. **Plan for growth** \\- Ingestion typically grows faster than deletion, so build in headroom.\n\n\n## Conclusion [Link to Conclusion](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#conclusion)\n\nImplementing effective retention in Loki requires configuring the compactor correctly and understanding how chunks and indexes interact. Start with the compactor-based approach using TSDB indexes for new deployments. Use per-tenant overrides to give teams flexibility while maintaining cost control. Monitor retention effectiveness with dedicated dashboards and alerts to catch issues before storage costs spiral.\n\nThe configurations in this guide provide a solid foundation. Adjust retention periods based on your compliance requirements, debugging needs, and budget constraints. Remember that retention is a balance - too short and you lose valuable debugging context, too long and storage costs become unsustainable.\n\nShare this article\n\n[Share on X](https://twitter.com/intent/tweet?text=%20How%20to%20Implement%20Loki%20Retention%20Strategies&url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on X\")[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on LinkedIn\")[Discuss on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview&t=%20How%20to%20Implement%20Loki%20Retention%20Strategies \"Discuss on Hacker News\")\n\n![Nawaz Dhandala](https://avatars.githubusercontent.com/nawazdhandala)\n\n### Nawaz Dhandala\n\nAuthor\n\n@nawazdhandala \u2022 Jan 30, 2026 \u2022 10 min read\n\nNawaz is building OneUptime with a passion for engineering reliable systems and improving observability.\n\n[GitHub](https://github.com/nawazdhandala)\n\nTechnically validated\u00b7 Jun 11, 2026\nView report\n\n\n### Help improve this post\n\nEvery OneUptime blog post is open source. Found a typo, an inaccuracy, or have a clearer way to explain something? Anyone can contribute \u2014 your edits make this post better for everyone who reads it next.\n\n[Edit this post on GitHub](https://github.com/oneuptime/blog/tree/master/posts/2026-01-30-loki-retention-strategies) [Contributing guidelines](https://github.com/oneuptime/blog)\n\n[Open source](https://github.com/oneuptime/oneuptime)\n\n## OneUptime is the Open-Source   Observability Platform\n\nYour complete reliability stack unified: infrastructure monitoring, incident management, status pages, and APM. Open-source and self-hostable.\n\n\n[Get started for free](https://oneuptime.com/accounts/register) [Request a demo](https://oneuptime.com/enterprise/demo)\n\n[Status Page\\\\\n\\\\\nReal-time status updates](https://oneuptime.com/product/status-page) [Incidents\\\\\n\\\\\nDetect and resolve fast](https://oneuptime.com/product/incident-management) [Monitoring\\\\\n\\\\\nMonitor any resource](https://oneuptime.com/product/monitoring) [On-Call\\\\\n\\\\\nSmart alert routing](https://oneuptime.com/product/on-call) [Maintenance\\\\\n\\\\\nPlan & communicate downtime](https://oneuptime.com/product/scheduled-maintenance) [Logs\\\\\n\\\\\nFastest log ingest and search](https://oneuptime.com/product/logs-management) [Metrics\\\\\n\\\\\nPerformance insights](https://oneuptime.com/product/metrics) [Traces\\\\\n\\\\\nEnd-to-end distributed tracing](https://oneuptime.com/product/traces) [Exceptions\\\\\n\\\\\nCatch and fix bugs early](https://oneuptime.com/product/exceptions) [Workflows\\\\\n\\\\\nAutomate any process](https://oneuptime.com/product/workflows) [Dashboards\\\\\n\\\\\nVisualize all your data](https://oneuptime.com/product/dashboards) [Kubernetes\\\\\n\\\\\nMonitor K8s clusters](https://oneuptime.com/product/kubernetes) [Profiles\\\\\n\\\\\nCPU & memory profiling](https://oneuptime.com/product/profiles)\n\n[AI\\\\\n\\\\\nDetect, diagnose, and resolve incidents with AI-powered root cause analysis and code fixes.](https://oneuptime.com/product/ai-agent)\n\n## Validation report\n\nTechnically reviewed for accuracy \u2022Jun 11, 2026\n\nLoading validation report\u2026\n\n\nAutomated technical review\nClose",
      "content_chars": 31256,
      "published_date": "2026-01-30T00:00:00"
    },
    {
      "rank": 8,
      "url": "https://community.grafana.com/t/configuring-retention-for-loki-in-a-grafana-cloud-stack/140741",
      "title": "Configuring retention for Loki in a Grafana Cloud stack - ...",
      "content": "I just created a free tier Grafana Cloud stack to start working with collecting and analyzing logs and metrics. When pushing data to the Loki-instance I get by default, it drop all logs older tha a week. Is there any way to change that? Do I need to run my own Loki-instance somewhere to enable ...",
      "content_chars": 298,
      "published_date": "2025-01-20T08:53:41"
    },
    {
      "rank": 9,
      "url": "https://medium.com/@aditya.hilman_10961/enabling-log-retention-in-loki-with-compactor-fe3de2002b47",
      "title": "Enabling Log Retention in Loki with Compactor | by Aditya Hilman ...",
      "content": "[Sitemap](https://medium.com/sitemap/sitemap.xml)\n\n[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40aditya.hilman_10961%2Fenabling-log-retention-in-loki-with-compactor-fe3de2002b47&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n[Medium Logo](https://medium.com/?source=---top_nav_layout_nav-------------------------------------------)\n\nGet app\n\n[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav--------------------)\n\n[Search](https://medium.com/search?source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40aditya.hilman_10961%2Fenabling-log-retention-in-loki-with-compactor-fe3de2002b47&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n![Unknown user](https://miro.medium.com/v2/resize:fill:32:32/1*dmbNkD5D-u45r44go_cf0g.png)\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:40:40/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_sidebar--fe3de2002b47-----------------b00d17378766------------------------)\n\n## Aditya Hilman\n\nFollow writer\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:40:40/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_sidebar--fe3de2002b47-----------------b00d17378766------------------------)\n\n## Aditya Hilman\n\nFollow writer\n\n[DevOps](https://medium.com/tag/devops?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Logging](https://medium.com/tag/logging?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Monitoring](https://medium.com/tag/monitoring?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Kubernetes](https://medium.com/tag/kubernetes?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Loki](https://medium.com/tag/loki?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n# Enabling Log Retention in Loki with Compactor\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:32:32/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---byline--fe3de2002b47-----------------------------------------)\n\n[Aditya Hilman](https://medium.com/@aditya.hilman_10961?source=post_page---byline--fe3de2002b47-----------------------------------------)\n\nFollow\n\n2 min read\n\n\u00b7\n\nDec 3, 2024\n\n15\n\n1\n\n[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Dfe3de2002b47&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40aditya.hilman_10961%2Fenabling-log-retention-in-loki-with-compactor-fe3de2002b47&source=---header_actions--fe3de2002b47---------------------post_audio_button--------------------)\n\nShare\n\n![](https://miro.medium.com/v2/resize:fit:538/1*TDFVSRecndbaVz1nhu3HuQ.png)\n\nEfficient log management is essential as Kubernetes workloads grow in complexity. In a [previous guide](https://medium.com/@aditya.hilman_10961/centralizing-kubernetes-logs-with-promtail-loki-and-grafana-a-step-by-step-guide-cafffb59a13e), we explored how to centralize logs using Loki, Promtail, and Grafana. But once logs start accumulating, controlling their retention becomes critical to manage storage and maintain performance.\n\nThis article will focus on configuring **log retention in Loki** using the **Compactor**, a core component designed to manage retention policies effectively.\n\n## Understanding Loki\u2019s Compactor\n\nThe **Compactor** in Loki is responsible for managing and enforcing retention periods, cleaning up old logs, and optimizing stored data. By enabling and configuring the compactor, you can automate log deletion and maintain a sustainable log storage strategy.\n\n## Configuring Log Retention in Loki\n\nEnsure the compactor is enabled in your `/etc/loki/config.yml` file:\n\n```\nlimits_config:\n retention_period: 30d\n\ncompactor:\n working_directory: /tmp/loki/retention\n retention_enabled: true\n retention_delete_delay: 2h\n delete_request_store: filesystem\n```\n\n`limits_config.retention_period: 30d`Sets the global retention period to 30 days. Logs older than 30 days will be marked for deletion by the compactor.\n\n`compactor.working_directory: /tmp/loki/retention`Specifies the directory where the compactor stores its state and temporary files while processing.\n\n## Get Aditya Hilman\u2019s stories in\u00a0your\u00a0inbox\n\nJoin Medium for free to get updates from\u00a0this\u00a0writer.\n\nSubscribe\n\nSubscribe\n\nRemember me for faster sign in\n\n`compactor.retention_enabled: true`Enables the retention policy enforcement in Loki. Without this, the compactor will not delete old logs.\n\n`compactor.retention_delete_delay: 2h`Introduces a delay of 2 hours before permanently deleting logs. This ensures a buffer in case of accidental deletion or misconfigurations.\n\n`compactor.delete_request_store: filesystem`Specifies the storage backend for deletion requests. `filesystem` is used here to store delete requests locally on disk. You can switch to other storage backends (e.g., `s3`, `gcs`) if needed.\n\n## Verify Retention Policy\n\nTo confirm that the retention policy is working, you can inspect the directory where Loki stores its chunks. If you are using the filesystem as your `shared_store`, the chunks are stored in `/tmp/loki/chunks`.\n\n**Check the Directory Contents**:\n\nAfter the compactor runs, check for log chunks in the directory:\n\n```\nls -lh /tmp/loki/chunks\n```\n\n**Verify Cleanup**:\n\nEnsure that files corresponding to logs older than the defined retention period (`720h` in this case) are no longer present.\n\nIf old chunks are not deleted, double-check your configuration for errors and ensure the `compactor` is running without issues.\n\n## Conclusion\n\nLog retention is a critical aspect of managing a scalable and efficient log storage system. By enabling Loki\u2019s Compactor and setting retention policies, you can control log storage while ensuring compliance and performance.\n\nIf you\u2019re new to Loki, be sure to check out [step-by-step guide](https://medium.com/@aditya.hilman_10961/centralizing-kubernetes-logs-with-promtail-loki-and-grafana-a-step-by-step-guide-cafffb59a13e) to set up your centralized logging stack.\n\n[DevOps](https://medium.com/tag/devops?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Logging](https://medium.com/tag/logging?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Monitoring](https://medium.com/tag/monitoring?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Kubernetes](https://medium.com/tag/kubernetes?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Loki](https://medium.com/tag/loki?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:48:48/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:64:64/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\nFollow\n\n[**Written by Aditya Hilman**](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\n[12 followers](https://medium.com/@aditya.hilman_10961/followers?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\n\u00b7 [2 following](https://medium.com/@aditya.hilman_10961/following?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\nFollow\n\n[Help](https://help.medium.com/hc/en-us?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Status](https://status.medium.com/?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[About](https://medium.com/about?autoplay=1&source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Careers](https://medium.com/jobs-at-medium/work-at-medium-959d1a85284e?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Press](mailto:pressinquiries@medium.com)\n\n[Blog](https://blog.medium.com/?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Store](https://medium.com/store)\n\n[Privacy](https://policy.medium.com/medium-privacy-policy-f03bf92035c9?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Rules](https://policy.medium.com/medium-rules-30e5502c4eb4?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Terms](https://policy.medium.com/medium-terms-of-service-9db0094a1e0f?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Text to speech](https://speechify.com/medium?source=post_page-----fe3de2002b47-----------------------------------------)",
      "content_chars": 9577,
      "published_date": "2024-12-03T10:18:49"
    },
    {
      "rank": 10,
      "url": "https://github.com/grafana/loki/issues/8357",
      "title": "Logs retention doesn't work \u00b7 Issue #8357 \u00b7 grafana/loki",
      "content": "[Skip to content](https://github.com/grafana/loki/issues/8357#start-of-content)\n\nYou signed in with another tab or window. [Reload](https://github.com/grafana/loki/issues/8357) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/grafana/loki/issues/8357) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/grafana/loki/issues/8357) to refresh your session.Dismiss alert\n\n{{ message }}\n\n[grafana](https://github.com/grafana)/ **[loki](https://github.com/grafana/loki)** Public\n\n- [Notifications](https://github.com/login?return_to=%2Fgrafana%2Floki) You must be signed in to change notification settings\n- [Fork\\\\\n4.1k](https://github.com/login?return_to=%2Fgrafana%2Floki)\n- [Star\\\\\n28.9k](https://github.com/login?return_to=%2Fgrafana%2Floki)\n\n\n# Logs retention doesn't work\\#8357\n\n[New issue](https://github.com/login?return_to=https://github.com/grafana/loki/issues/8357)\n\nCopy link\n\n[New issue](https://github.com/login?return_to=https://github.com/grafana/loki/issues/8357)\n\nCopy link\n\nClosed\n\nClosed\n\n[Logs retention doesn't work](https://github.com/grafana/loki/issues/8357#top)#8357\n\nCopy link\n\n## Description\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4&size=48)](https://github.com/fpaparoni)\n\n[fpaparoni](https://github.com/fpaparoni)\n\nopened [on Jan 31, 2023on Jan 31, 2023](https://github.com/grafana/loki/issues/8357#issue-1564748865)\n\nIssue body actions\n\n**Describe the bug**\n\nUsing a custom configuration I think the logs should be deleted after 1h, but they are always available\n\n**To Reproduce**\n\nI used the following configuration values for loki helm chart\n\n```\nloki:\n  config:\n    limits_config:\n      retention_period: 1h\n    compactor:\n      retention_enabled: true\n      retention_delete_delay: 1h\n    table_manager:\n      retention_deletes_enabled: true\n      retention_period: 1h\n```\n\nlaunched the creation using the following command\n\n`helm install loki grafana/loki-stack --values loki-stack-values.yaml -n loki --create-namespace`\n\nand if I enter into the loki pod I can see the following configuration from /etc/loki/loki.yaml\n\n```\nauth_enabled: false\nchunk_store_config:\n  max_look_back_period: 0s\ncompactor:\n  retention_delete_delay: 1h\n  retention_enabled: true\n  shared_store: filesystem\n  working_directory: /data/loki/boltdb-shipper-compactor\ningester:\n  chunk_block_size: 262144\n  chunk_idle_period: 3m\n  chunk_retain_period: 1m\n  lifecycler:\n    ring:\n      replication_factor: 1\n  max_transfer_retries: 0\n  wal:\n    dir: /data/loki/wal\nlimits_config:\n  enforce_metric_name: false\n  max_entries_limit_per_query: 5000\n  reject_old_samples: true\n  reject_old_samples_max_age: 168h\n  retention_period: 1h\nmemberlist:\n  join_members:\n  - 'loki-memberlist'\nschema_config:\n  configs:\n  - from: \"2020-10-24\"\n    index:\n      period: 24h\n      prefix: index_\n    object_store: filesystem\n    schema: v11\n    store: boltdb-shipper\nserver:\n  grpc_listen_port: 9095\n  http_listen_port: 3100\nstorage_config:\n  boltdb_shipper:\n    active_index_directory: /data/loki/boltdb-shipper-active\n    cache_location: /data/loki/boltdb-shipper-cache\n    cache_ttl: 24h\n    shared_store: filesystem\n  filesystem:\n    directory: /data/loki/chunks\ntable_manager:\n  retention_deletes_enabled: true\n  retention_period: 1h\n```\n\n**Expected behavior**\n\nAfter one hour logs should be deleted, but the retention doesn't work (of course there is something in the configuration that is wrong)\n\n**Environment:**\n\n- Infrastructure: Kubernetes\n- Deployment tool: helm\n\n## Activity\n\n### danielrosa-zh commented on Jan 31, 2023on Jan 31, 2023\n\n[![@danielrosa-zh](https://avatars.githubusercontent.com/u/92591588?u=338bb817890c8036cd7fb7b373b0779c4ff10127&v=4&size=48)](https://github.com/danielrosa-zh)\n\n[danielrosa-zh](https://github.com/danielrosa-zh)\n\n[on Jan 31, 2023on Jan 31, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1411281458)\n\nMore actions\n\nHi [@fpaparoni](https://github.com/fpaparoni)\n\nLooks like the minimum retention period is 24h regarding the documentation.\n\n### fpaparoni commented on Feb 1, 2023on Feb 1, 2023\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4&size=48)](https://github.com/fpaparoni)\n\n[fpaparoni](https://github.com/fpaparoni)\n\n[on Feb 1, 2023on Feb 1, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1411656192)\n\nAuthor\n\nMore actions\n\nHi [@danielrosa-zh](https://github.com/danielrosa-zh) ,\n\nI didn't see it, I'll try and wait one day to see if it works :)\n\n### aleksandr-seleznyov commented on Mar 21, 2023on Mar 21, 2023\n\n[![@aleksandr-seleznyov](https://avatars.githubusercontent.com/u/9655244?u=64370cc509f33f68838f727d59fce2e86866f744&v=4&size=48)](https://github.com/aleksandr-seleznyov)\n\n[aleksandr-seleznyov](https://github.com/aleksandr-seleznyov)\n\n[on Mar 21, 2023on Mar 21, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1478362759)\n\nMore actions\n\nHello [@fpaparoni](https://github.com/fpaparoni) ,\n\nIt worked?\n\n### fpaparoni commented on Mar 21, 2023on Mar 21, 2023\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4&size=48)](https://github.com/fpaparoni)\n\n[fpaparoni](https://github.com/fpaparoni)\n\n[on Mar 21, 2023on Mar 21, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1478562202)\n\nAuthor\n\nMore actions\n\nyes it worked, thanks for the support\n\n\ud83d\udc4dReact with \ud83d\udc4d1Reacted by neonvignesh\n\n[![](https://avatars.githubusercontent.com/u/4602065?s=64&u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4)fpaparoni](https://github.com/fpaparoni)\n\nclosed this as [completed](https://github.com/grafana/loki/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted) [on Mar 21, 2023on Mar 21, 2023](https://github.com/grafana/loki/issues/8357#event-8810133030)\n\n[Sign up for free](https://github.com/signup?return_to=https://github.com/grafana/loki/issues/8357)**to join this conversation on GitHub.** Already have an account? [Sign in to comment](https://github.com/login?return_to=https://github.com/grafana/loki/issues/8357)\n\n## Metadata\n\n## Metadata\n\n### Assignees\n\nNo one assigned\n\n### Labels\n\nNo labels\n\nNo labels\n\n### Type\n\nNo type\n\n### Projects\n\nNo projects\n\n### Milestone\n\nNo milestone\n\n### Relationships\n\nNone yet\n\n### Development\n\nNo branches or pull requests\n\n### Participants\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?s=64&u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4)](https://github.com/fpaparoni)[![@aleksandr-seleznyov](https://avatars.githubusercontent.com/u/9655244?s=64&u=64370cc509f33f68838f727d59fce2e86866f744&v=4)](https://github.com/aleksandr-seleznyov)[![@danielrosa-zh](https://avatars.githubusercontent.com/u/92591588?s=64&u=338bb817890c8036cd7fb7b373b0779c4ff10127&v=4)](https://github.com/danielrosa-zh)\n\n## Issue actions\n\n- ![](https://github.githubassets.com/assets/github-copilot-app-light-15ad5534265eeacd.svg)Open in GitHub Copilot app\n\nYou can\u2019t perform that action at this time.",
      "content_chars": 7134,
      "published_date": "2023-01-31T17:41:57"
    }
  ],
  "answer_text": null,
  "citations": [],
  "raw_response": {
    "results": {
      "web": [
        {
          "url": "https://grafana.com/docs/loki/latest/operations/storage/retention/",
          "title": "Log retention | Grafana Loki documentation",
          "description": "Describes how Loki implements storage retention and retention configuration options.",
          "thumbnail_url": "https://grafana.com/meta-generator/Log+retention@@@loki@@@13.png",
          "original_thumbnail_url": "https://grafana.com/meta-generator/Log+retention@@@loki@@@13.png",
          "favicon_url": "https://you.com/favicon?domain=grafana.com&size=128",
          "snippets": [
            "Alternatively, the table-manager.retention-period and table-manager.retention-deletes-enabled command line flags can be used. The provided retention period needs to be a duration represented as a string that can be parsed using the Prometheus common model ParseDuration. Examples: 7d, 1w, 168h. ... The retention period must be a multiple of the index and chunks table period, configured in the period_config block. See the Table Manager documentation for more information. ... To avoid querying of data beyond the retention period,max_query_lookback config in limits_config must be set to a value less than or equal to what is set in table_manager.retention_period.",
            "Streams except those with the namespace label dev will have the retention period of 744h. ... If you are a Grafana Cloud customer, you can use the config self-serve API to configure your tenant retention. Retention through the Table Manager is achieved by relying on the object store TTL feature, and will work for both boltdb-shipper store and chunk/index stores. In order to enable the retention support, the Table Manager needs to be configured to enable deletions and a retention period.",
            "Note, however, that this only deletes the log content and keeps the label index intact; you will still be able to see related labels but will be unable to retrieve the deleted log content. For further details on the Table Manager internals, refer to the Table Manager documentation. Alternatively, if the BoltDB Shipper is configured for the index store, you can enable Log entry deletion to delete log entries from a specific stream. Example configuration with GCS with a 28 day retention:",
            "Chunks are deleted by the Compactor according to your configured retention, but the Compactor only removes chunk objects: it never deletes the objects that hold cluster state, such as the index or the cluster seed. If you also configure an object store lifecycle policy on the bucket, scope it carefully. A blanket \u201cdelete everything older than N days\u201d rule will eventually remove objects that Loki must keep, which corrupts the store and causes query failures."
          ],
          "contents": {
            "markdown": "![ObservabilityCON 2025](https://a-us.storyblok.com/f/1022730/280x40/b0872b99f9/grafana-logo-observabilitycon-2025-black.svg/m/)\n\nWatch the keynote again and signup for more on-demand sessions.\n\n\n[Watch keynote](https://grafana.com/events/observabilitycon/?plcmt=obscon2025-post-event-banner)![](https://grafana.com/media/events/grafanacon/2025/icon-close-x.svg)\n\n![ObservabilityCON 2025](https://grafana.com/media/events/obscon/2025/grafana-obscon2025-promo-logo-black.svg)\n\n\ud83d\udce2 Registration + agenda now live\nExplore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).\n\n\n[Register now](https://grafana.com/events/observabilitycon/?tech=target&plcmt=top-banner&aud=default)\n\nSearching...\n\nSite search\n\nAsk Grot AI\n\n[Try using ![Grot AI](https://grafana.com/static/img/grot-chat.svg)**Grot AI** for this query ->](https://grafana.com/grot/?chat=&from=/search)\n\nAll\n\nDocs\n\nView all results\n\nNo results.\n\nThere was an error with your request.\n\n> Documentation for automated readers\n>\n> A curated documentation index is available at: https://grafana.com/llms.txt\n>\n> A complete documentation index is available at: https://grafana.com/llms-full.txt\n>\n> These indexes can help with page discovery before fetching individual documents.\n\nThis page is also available in Markdown, which may be easier for automated readers\nand AI tools to parse than HTML. The Markdown version is available at\nhttps://grafana.com/docs/loki/latest/operations/storage/retention.md, or by sending\nAccept: text/markdown to https://grafana.com/docs/loki/latest/operations/storage/retention/. For broader\ndocumentation discovery, the curated index is available at https://grafana.com/llms.txt\nand the complete index is available at https://grafana.com/llms-full.txt.\n\nLog retention\n\n[Documentation](https://grafana.com/docs/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Grafana Loki](https://grafana.com/docs/loki/latest/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Manage](https://grafana.com/docs/loki/latest/operations/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Storage](https://grafana.com/docs/loki/latest/operations/storage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)Log retention\n\nOpen source\n\n# Log retention\n\nRetention in Grafana Loki is achieved through the [Compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor).\nBy default the `compactor.retention-enabled` flag is not set, so the logs sent to Loki live forever.\n\n> Note\n>\n> If you have a lifecycle policy configured on the object store, please ensure that it is longer than the retention period.\n\nGranular retention policies to apply retention at per tenant or per stream level are also supported by the Compactor.\n\n> Note\n>\n> The Compactor does not support retention on\n> [legacy index types](https://grafana.com/docs/loki/latest/configure/storage/#index-storage). Please use the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) when using legacy index types.\n> Both the Table manager and legacy index types are deprecated and may be removed in future major versions of Loki.\n\n## Compactor\n\nThe Compactor is responsible for compaction of index files and applying log retention.\n\n> Note\n>\n> Run the Compactor as a singleton (a single instance).\n\nThe Compactor runs compaction and retention on two independent schedules:\n\n- Compaction runs every `compactor.compaction-interval`.\n- Retention runs every `compactor.apply-retention-interval`. If you leave this at its default of `0s`, Loki sets it to the same value as `compactor.compaction-interval`. Whenever the two intervals are equal, Loki extends the retention interval by the smaller of `10m` or half the interval, so that compaction and retention do not run at the same time. For example, with the default `compaction_interval` of `10m`, retention runs every `15m`.\n\nIf the Compactor falls behind on either schedule, it runs the corresponding operation as soon as possible.\nBoth compaction and retention are idempotent, which means once the action has been performed, if the action is performed multiple times, it has no further effect on logs after the first time it is performed. If the Compactor restarts, it continues from where it left off.\n\n> Note\n>\n> Changes to your retention period are not retroactive, that is, they are not applied to logs that have already been ingested.\n\nThe Compactor\u2019s algorithm to apply retention is as follows:\n\n- For each day or table (one table per day with 24h index period):\n  - Compact multiple index files in the table into per-tenant index files. Result of compaction is a single index file per tenant per day.\n  - Traverse the per-tenant index. Use the tenant configuration to identify the chunks that need to be removed.\n  - Remove the references to the matching chunks from the index and add the chunk references to a marker file on disk.\n  - Upload the new modified index files.\n\nChunks are not deleted while applying the retention algorithm on the index. They are deleted asynchronously by a sweeper process\nand this delay can be configured by setting `-compactor.retention-delete-delay`. Marker files are used to keep track of the chunks pending for deletion.\n\nChunks cannot be deleted immediately for the following reasons:\n\n- Index Gateway downloads a copy of the index files to serve queries and refreshes them at a regular interval.\nHaving a delay allows the index gateways to pull the modified index file which would not contain any reference to the chunks marked for deletion.\nWithout the delay, index files (that are stale) on the gateways could refer to already deleted chunks leading to query failures.\n\n- It provides a short window of time in which to cancel chunk deletion in the case of a configuration mistake.\n\n\nBy default, marker files are written to local disk, under `<working_directory>/retention/<object_store_type>_<period_from_date>/markers/`. Marker files should be stored on a persistent disk to ensure that the chunks pending for deletion are processed even if the Compactor process restarts.\n\n> Note\n>\n> Grafana Labs recommends running Compactor as a stateful deployment (StatefulSet when using Kubernetes) with a persistent storage for storing marker files.\n\nAlternatively, you can configure the Compactor to store marker files in object storage instead of local disk, by setting `compactor.deletion-marker-object-store-prefix` (`deletion_marker_object_store_prefix`) to a prefix that ends with `/`. When set, the Compactor writes marker files to the same per-period object store bucket used for chunks, under that prefix. On startup it also copies any existing marker files from local disk to that prefix, then removes the local copies. This lets you run the Compactor without a persistent volume for marker files. Leave this setting empty to keep using local disk.\n\n### Retention Configuration\n\nThis Compactor configuration example activates retention.\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\ncompactor:\n  working_directory: /data/retention\n  compaction_interval: 10m\n  retention_enabled: true\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n  delete_request_store: gcs\nschema_config:\n  configs:\n    - from: \"2020-07-31\"\n      index:\n        period: 24h\n        prefix: index_\n      object_store: gcs\n      schema: v13\n      store: tsdb\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /data/index\n    cache_location: /data/index_cache\n  gcs:\n    bucket_name: loki\n```\n\n> Note\n>\n> Retention is only available if the index period is 24h. Single store TSDB and single store BoltDB require 24h index period.\n\n`retention_enabled` should be set to true. Without this, the Compactor will only compact tables.\n\n`delete_request_store` should be set to configure the store for delete requests. This is required when retention is enabled.\n\n`working_directory` is the directory where marked chunks and temporary tables will be saved.\n\n`compaction_interval` dictates how often compaction is applied. If the Compactor falls behind, compaction occurs as soon as possible.\n\n`apply_retention_interval` dictates how often retention is applied, independently of `compaction_interval`. Refer to [Compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor) for how the default value is derived from `compaction_interval`.\n\n`retention_delete_delay` is the delay after which the Compactor will delete marked chunks.\n\n`retention_delete_worker_count` specifies the maximum quantity of goroutine workers instantiated to delete chunks.\n\nA few other options are also relevant when tuning retention:\n\n- `retention_table_timeout` bounds how long the Compactor spends applying retention and processing delete requests on any single table. It defaults to `0s`, meaning no timeout. If the work on a table exceeds this timeout, the Compactor logs a warning and stops early rather than failing, and the remaining work is picked up again on a later run.\n- `retention_backoff_config` controls the retry behavior (minimum and maximum backoff, and number of retries) used by the sweeper when it fails to delete a marked chunk.\n- `delete_request_store_key_prefix` sets the path prefix used to store delete requests within `delete_request_store` (default `index/`).\n- `delete_request_store_db_type` sets the type of database used to store delete requests (default `boltdb`).\n\nRefer to the\n[Configuration reference](https://grafana.com/docs/loki/latest/configure/#compactor) for the full list of `compactor` options and their defaults.\n\n#### Configuring the retention period\n\nRetention period is configured within the\n[`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) configuration section.\n\nThere are two ways of setting retention policies:\n\n- `retention_period` which is applied globally for all log streams.\n- `retention_stream` which is only applied to log streams matching the selector.\n\n> Note\n>\n> Each `retention_stream` rule\u2019s `period` must be at least 24h. Loki rejects configuration with a shorter value, both in the global `retention_stream` list and in any per-tenant override. This minimum does not apply to the `retention_period` setting, either globally or per tenant.\n\nThis example configures global retention that applies to all tenants (unless overridden by configuring per-tenant overrides):\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\n...\nlimits_config:\n  retention_period: 744h\n  retention_stream:\n  - selector: '{namespace=\"dev\"}'\n    priority: 1\n    period: 24h\n  per_tenant_override_config: /etc/overrides.yaml\n...\n```\n\n> Note\n>\n> You can only use label matchers in the `selector` field of a `retention_stream` definition. Arbitrary LogQL expressions are not supported.\n\nPer tenant retention can be defined by configuring\n[runtime overrides](https://grafana.com/docs/loki/latest/configure/#runtime-configuration-file). For example:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\noverrides:\n    \"29\":\n        retention_period: 168h\n        retention_stream:\n        - selector: '{namespace=\"prod\"}'\n          priority: 2\n          period: 336h\n        - selector: '{container=\"loki\"}'\n          priority: 1\n          period: 72h\n    \"30\":\n        retention_stream:\n        - selector: '{container=\"nginx\", level=\"debug\"}'\n          priority: 1\n          period: 24h\n```\n\nRetention period for a given stream is decided based on the first match in this list:\n\n1. If multiple per-tenant `retention_stream` selectors match the stream, retention period with the highest priority is picked.\n2. If multiple global `retention_stream` selectors match the stream, retention period with the highest priority is picked. This value is not considered if per-tenant `retention_stream` is set.\n3. If a per-tenant `retention_period` is specified, it will be applied.\n4. The global `retention_period` will be applied if none of the above match.\n5. If no global `retention_period` is specified, the default value of `0s` is used, which means logs are kept indefinitely.\n\n> Note\n>\n> The larger the priority value, the higher the priority. If two matching `retention_stream` rules have the same priority, Loki applies the shorter (lowest) of the two periods.\n\nStream matching uses the same syntax as Prometheus label matching:\n\n- `=`: Select labels that are exactly equal to the provided string.\n- `!=`: Select labels that are not equal to the provided string.\n- `=~`: Select labels that regex-match the provided string.\n- `!~`: Select labels that do not regex-match the provided string.\n\nThe example configurations defined above will result in the following retention periods:\n\n- For tenant `29`:\n  - Streams that have the namespace label `prod` will have a retention period of `336h` (2 weeks), even if the container label is `loki`, since the priority of the `prod` rule is higher.\n  - Streams that have the container label `loki` but are not in the namespace `prod` will have a `72h` retention period.\n  - For the rest of the streams in this tenant, per-tenant override `retention_period` value of `168h` is applied.\n- For tenant `30`:\n  - Streams that have the label `nginx` and level `debug` will have a retention period of `24h`.\n  - For the rest of the streams in this tenant the global retention period of `744h`, since there is no override specified.\n- All tenants except `29` and `30`:\n  - Streams that have the namespace label `dev` will have a retention period of `24h` hours.\n  - Streams except those with the namespace label `dev` will have the retention period of `744h`.\n\n> Note\n>\n> If you are a Grafana Cloud customer, you can use the [config self-serve API](https://grafana.com/docs/grafana-cloud/send-data/logs/config-self-serve/#configure-retention) to configure your tenant retention.\n\n## Table Manager (deprecated)\n\nRetention through the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) is\nachieved by relying on the object store TTL feature, and will work for both\n[boltdb-shipper](https://grafana.com/docs/loki/latest/operations/storage/boltdb-shipper/) store and chunk/index stores.\n\nIn order to enable the retention support, the Table Manager needs to be\nconfigured to enable deletions and a retention period. Please refer to the\n[`table_manager`](https://grafana.com/docs/loki/latest/configure/#table_manager)\nsection of the Loki configuration reference for all available options.\nAlternatively, the `table-manager.retention-period` and\n`table-manager.retention-deletes-enabled` command line flags can be used. The\nprovided retention period needs to be a duration represented as a string that\ncan be parsed using the Prometheus common model [ParseDuration](https://pkg.go.dev/github.com/prometheus/common/model#ParseDuration). Examples: `7d`, `1w`, `168h`.\n\n> Warning\n>\n> The retention period must be a multiple of the index and chunks table\n> `period`, configured in the\n> [`period_config`](https://grafana.com/docs/loki/latest/configure/#period_config) block.\n> See the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/#retention) documentation for\n> more information.\n\n> Note\n>\n> To avoid querying of data beyond the retention period,`max_query_lookback` config in\n> [`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) must be set to a value less than or equal to what is set in `table_manager.retention_period`.\n\nWhen using S3 or GCS, the bucket storing the chunks needs to have the expiry\npolicy set correctly. For more details check\n[S3\u2019s documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)\nor\n[GCS\u2019s documentation](https://cloud.google.com/storage/docs/managing-lifecycles).\n\nIf you must delete ingested logs, you can delete old chunks in your object store. Note,\nhowever, that this only deletes the log content and keeps the label index\nintact; you will still be able to see related labels but will be unable to\nretrieve the deleted log content.\n\nFor further details on the Table Manager internals, refer to the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) documentation.\n\nAlternatively, if the BoltDB Shipper is configured for the index store, you can enable\n[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) to delete log entries from a specific stream.\n\n## Example Configuration\n\nExample configuration with GCS with a 28 day retention:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\nschema_config:\n  configs:\n    - from: 2018-04-15\n      store: tsdb\n      object_store: gcs\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /loki/index\n    cache_location: /loki/index_cache\n  gcs:\n    bucket_name: GCS_BUCKET_NAME\n\nlimits_config:\n  max_query_lookback: 672h # 28 days\n  retention_period: 672h   # 28 days\n\ncompactor:\n  working_directory: /data/retention\n  delete_request_store: gcs\n  retention_enabled: true\n```\n\n## Object store lifecycle policies\n\nLoki stores chunks and indexes as objects in the configured object store (S3, GCS, Azure Blob Storage, and so on). Chunks are deleted by the [Compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor) according to your configured retention, but the Compactor only removes chunk objects: it never deletes the objects that hold cluster state, such as the index or the cluster seed.\n\nIf you also configure an object store lifecycle policy on the bucket, scope it carefully. A blanket \u201cdelete everything older than N days\u201d rule will eventually remove objects that Loki must keep, which corrupts the store and causes query failures. The note at the top of this page applies here as well: any lifecycle expiration must be longer than your retention period.\n\n> Warning\n>\n> Never apply a lifecycle rule with an empty prefix (one that targets the whole bucket). Always scope lifecycle rules to the per-tenant chunk prefixes described below.\n\n### Bucket object layout\n\nThe following objects are written to the configured bucket. The exact prefixes depend on your `schema_config` and on whether multi-tenancy is enabled, so confirm them against your own configuration before writing a lifecycle rule.\n\nExpand table\n\n| Object or prefix | Content | Safe to expire with a lifecycle policy? |\n| --- | --- | --- |\n| `<tenant_id>/` (for example, `fake/` in single-tenant mode, or your org ID per tenant) | Chunk objects (the log data). | Yes. These are the only objects a lifecycle rule should target. |\n| Index objects (under the index path prefix, `index/` by default, set by `index.path_prefix` in `schema_config`) | TSDB or BoltDB index files, written by ingesters and rewritten by the Compactor. The `index.prefix` value (for example `index_` or `loki_index_`) is the table-name prefix used inside this path, not the path itself, so match a lifecycle rule against the path prefix. | No. Loki manages the index lifecycle internally. Deleting index objects removes references to live chunks and breaks queries. |\n| `loki_cluster_seed.json` | A small file at the bucket root holding the cluster seed used by usage reporting. It is written once and never rotated. | No. A blanket age-based rule will delete it once it ages past the time to live (TTL). |\n| Delete-request store objects (a `delete_requests/` table under `delete_request_store_key_prefix`, `index/` by default, in the bucket configured by `delete_request_store`) | The Compactor\u2019s database of delete requests submitted through the<br>[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) API, and their processing status. | No. Removing these makes the Compactor lose track of pending delete requests. |\n| Deletion marker objects (only present if you set `deletion_marker_object_store_prefix`; otherwise markers are kept on the Compactor\u2019s local disk and never appear in the bucket) | The Compactor\u2019s record of chunks that are marked for deletion but not yet swept. Written under the configured prefix in the same per-period bucket used for chunks. | No. Removing these makes the Compactor lose track of chunks pending deletion. |\n| Ruler store objects (if the Ruler is backed by the same bucket) | Recording and alerting rule files. | No. These are configuration, not time-series data. |\n\n### Compactor retention versus object store lifecycle policies\n\nCompactor retention and object store lifecycle policies are two independent mechanisms, and they should not be configured in ways that conflict:\n\n- The Compactor is index-aware. It only deletes a chunk after it has removed every reference to that chunk from the index, and it waits `compactor.retention-delete-delay` (default `2h`) before the sweeper deletes the marked chunk, so that index gateways pick up the rewritten index first.\n- An object store lifecycle policy is index-unaware. It deletes objects purely by age and prefix, with no knowledge of whether a chunk is still referenced by the index.\n\nFor most deployments, enabling Compactor retention is sufficient and an object store lifecycle policy is not required. If you do add a lifecycle policy as a cost safety net, set its expiration **longer** than your retention period plus `compactor.retention-delete-delay`, so the Compactor always deletes chunks first and the lifecycle rule only ever catches objects the Compactor has already orphaned.\n\n### Example: Amazon S3 lifecycle policy\n\nThis policy expires only chunk objects under a single tenant prefix. Replace `fake/` with your tenant prefix (use one rule per tenant, or your org ID prefix, when multi-tenancy is enabled). The `Days` value must be larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-chunk-expiration\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"fake/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 395\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the AWS CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\naws s3api put-bucket-lifecycle-configuration \\\n  --bucket YOUR_LOKI_BUCKET \\\n  --lifecycle-configuration file://lifecycle.json\n```\n\n### Example: Google Cloud Storage lifecycle rule\n\nThe equivalent GCS rule expires objects by age and prefix. As with S3, scope `matchesPrefix` to the tenant chunk prefix and keep `age` larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"rule\": [\\\n    {\\\n      \"action\": {\"type\": \"Delete\"},\\\n      \"condition\": {\\\n        \"age\": 395,\\\n        \"matchesPrefix\": [\"fake/\"]\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the Google Cloud CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\ngcloud storage buckets update gs://YOUR_LOKI_BUCKET --lifecycle-file=lifecycle.json\n```\n\nFor Azure Blob Storage, use a management policy with a `prefixMatch` set to the tenant chunk prefix and the same \u201cexpiration must exceed retention plus delete delay\u201d rule.\n\n## Was this page helpful?\n\n![\ud83d\udc4d](https://grafana.com/media/images/svg/thumbs-up.svg) Yes![\ud83d\udc4e](https://grafana.com/media/images/svg/thumbs-up.svg) No\n\n[Suggest an edit in GitHub](https://github.com/grafana/loki/edit/release-3.7.x/docs/sources/operations/storage/retention.md) [Create a GitHub issue](https://github.com/grafana/loki/issues/new?title=Documentation%20feedback:%20/docs/sources/operations/storage/retention.md) [Email docs@grafana.com](mailto:docs@grafana.com) [Help and support](https://grafana.com/help/) [Community](https://grafana.com/community/)\n\n## Related resources from Grafana Labs\n\nAdditional helpful documentation, links, and articles:\n\n[![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Getting started with logging and Grafana Loki](https://grafana.com/static/assets/featured/getting-started-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nGetting started with logging and Grafana Loki\\\\\n\\\\\nSee a demo of the updated features in Loki, and how to create metrics from logs and alert on your logs with powerful Prometheus-style alerting rules.](https://grafana.com/go/webinar/getting-started-with-logging-and-grafana-loki/?pg=docs-loki-latest-operations-storage-retention&plcmt=related) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Essential Grafana Loki configuration settings](https://grafana.com/static/assets/featured/logging-with-loki-essential-configuration-settings_featured.png?w=400)\\\\\n\\\\\nEssential Grafana Loki configuration settings\\\\\n\\\\\nThis webinar focuses on Grafana Loki configuration including agents Promtail and Docker; the Loki server; and Loki storage for popular backends.](https://grafana.com/go/webinar/logging-with-loki-essential-configuration-settings/?pg=docs-loki-latest-operations-storage-retention&plcmt=related-2) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Scaling and securing your logs with Grafana Loki](https://grafana.com/static/assets/featured/scaling-and-securing-your-logs-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nScaling and securing your logs with Grafana Loki\\\\\n\\\\\nThis webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.](https://grafana.com/go/webinar/scaling-and-securing-your-logs-with-grafana-loki/?pg=docs-loki-latest-operations-storage-retention&plcmt=related-3)\n\nAsk Grafana Assistant"
          }
        },
        {
          "url": "https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working",
          "title": "purge - why my Loki log retention is not working? - Stack Overflow",
          "description": "\"12h\" old logs are not deleting even after specifying \"retention_period: 12h\" due to this I'm facing storage issue because, log are not deleting. please help me with config loki...",
          "thumbnail_url": "https://stackoverflow.com/Content/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=0f0cab681579",
          "original_thumbnail_url": "https://stackoverflow.com/Content/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=0f0cab681579",
          "favicon_url": "https://you.com/favicon?domain=stackoverflow.com&size=128",
          "snippets": [
            "By default, when table_manager.retention_deletes_enabled or compactor.retention_enabled flags are not set, then logs sent to Loki live forever. The minimum retention period is 24h. The retention period must be a multiple of the index and chunks table period, configured in the period_config block. ... Copyschema_config: configs: - from: 2020-10-24 store: boltdb-shipper object_store: filesystem schema: v11 index: prefix: index_ period: 24h table_manager: retention_deletes_enabled: true retention_period: 24h \u00b7 The other way to setup the retention in Grafana Loki is via the Compactor.",
            "The table manager is now deprecated. grafana.com/docs/loki/latest/operations/storage/retention/\u2026 2024-06-21T14:58:19.763Z+00:00 ... Can anyone explain to me what the /data/retention path refers to? Is it the chunks path? For example /var/lib/loki/chunks? 2024-09-18T12:19:56.59Z+00:00 ... Save this answer. ... Show activity on this post. ... With the exception of the filesystem chunk store, Loki will not delete old chunk stores.",
            "loki: enabled: true isDefault: true table_manager: retention_deletes_enabled: true retention_period: 12h ... What exactly do you mean by: \"12h\" old logs are not deleting? I am asking because Loki is not supposed to delete any log file. To delete those files, you would use some kind of log rotation provided by your logging framework. (BTW: Getting those files is part of the Promtail configuration not part of Loki.) ... Actually, My goal is to deleted logs which are older than 12h, it should be deleted from grafana dashboard as well as from server storage because I m facing storage issues as my log are not deleting, and occupying huge space in server storage is getting full",
            "retention_delete_delay just delays deleting defined in limits_config\\retention_period. The reason for that is described in grafana.com/docs/loki/latest/operations/storage/retention as: \"1. ... deleting chunks instantly could lead to components still having reference to old chunks and so they could fails to execute queries."
          ],
          "contents": {
            "markdown": "##### Collectives\u2122 on Stack Overflow\n\nFind centralized, trusted content and collaborate around the technologies you use most.\n\n[Learn more about Collectives](https://stackoverflow.com/collectives)\n\n**Stack Internal**\n\nKnowledge at work\n\nBring the best of human thought and AI automation together at your work.\n\n[Explore Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact-popover)\n\n# [why my Loki log retention is not working?](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working)\n\n[Ask Question](https://stackoverflow.com/questions/ask)\n\nAsked4 years, 1 month ago\n\nModified [3 years, 1 month ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working?lastactivity \"2023-08-17 12:22:05Z\")\n\nViewed\n33k times\n\n\nThis question shows research effort; it is useful and clear\n\n12\n\nThis question does not show any research effort; it is unclear or not useful\n\nSave this question.\n\n[Timeline](https://stackoverflow.com/posts/73138278/timeline)\n\nShow activity on this post.\n\n\"12h\" old logs are not deleting even after specifying \"retention\\_period: 12h\" due to this I'm facing storage issue because, log are not deleting.\nplease help me with config\n\n```\nloki:\n  enabled: true\n  isDefault: true\n  table_manager:\n    retention_deletes_enabled: true\n    retention_period: 12h\n```\n\n- [purge](https://stackoverflow.com/questions/tagged/purge \"show questions tagged 'purge'\")\n- [retention](https://stackoverflow.com/questions/tagged/retention \"show questions tagged 'retention'\")\n- [grafana-loki](https://stackoverflow.com/questions/tagged/grafana-loki \"show questions tagged 'grafana-loki'\")\n- [promtail](https://stackoverflow.com/questions/tagged/promtail \"show questions tagged 'promtail'\")\n\n[Share](https://stackoverflow.com/q/73138278)\n\nShare a link to this question\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this question\n\n[Improve this question](https://stackoverflow.com/posts/73138278/edit \"\")\n\nFollow\n\n\n\nFollow this question to receive notifications\n\n[edited Jul 27, 2022 at 12:54](https://stackoverflow.com/posts/73138278/revisions \"show all edits to this post\")\n\nasked Jul 27, 2022 at 12:50\n\n[![Vinayak Pawar's user avatar](https://lh3.googleusercontent.com/a/AItbvmmc9dlTfSu1J8AycV3kKXkeYxBKUi0R2C9k_c3f=k-s64)](https://stackoverflow.com/users/19632861/vinayak-pawar)\n\n[Vinayak Pawar](https://stackoverflow.com/users/19632861/vinayak-pawar)\n\n14311 gold badge11 silver badge55 bronze badges\n\n2\n\n- 1\n\n\n\n\n\nWhat exactly do you mean by: \"12h\" old logs are not deleting? I am asking because Loki is not supposed to delete any log file. To delete those files, you would use some kind of log rotation provided by your logging framework. (BTW: Getting those files is part of the Promtail configuration not part of Loki.)\n\n\n\nSascha Doerdelmann\n\n\n\u2013\n[Sascha Doerdelmann](https://stackoverflow.com/users/11934850/sascha-doerdelmann \"906 reputation\")\n\n\n\n2022-07-27 13:46:41 +00:00\n\n[CommentedJul 27, 2022 at 13:46](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment129174235_73138278)\n\n- 2\n\n\n\n\n\nActually, My goal is to deleted logs which are older than 12h, it should be deleted from grafana dashboard as well as from server storage because I m facing storage issues as my log are not deleting, and occupying huge space in server storage is getting full\n\n\n\nVinayak Pawar\n\n\n\u2013\n[Vinayak Pawar](https://stackoverflow.com/users/19632861/vinayak-pawar \"143 reputation\")\n\n\n\n2022-07-29 05:14:31 +00:00\n\n[CommentedJul 29, 2022 at 5:14](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment129212546_73138278)\n\n\n[Add a comment](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working# \"Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.\")\u00a0\\|\u00a0[Expand to show all comments on this post](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working# \"Expand to show all comments on this post\")\n\n## 3 Answers 3\n\nSorted by:\n[Reset to default](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working?answertab=scoredesc#tab-top)\n\nHighest score (default)\n\nTrending (recent votes count more)\n\nDate modified (newest first)\n\nDate created (oldest first)\n\n\nThis answer is useful\n\n11\n\nThis answer is not useful\n\nSave this answer.\n\nLoading when this answer was accepted\u2026\n\n[Timeline](https://stackoverflow.com/posts/73140146/timeline)\n\nShow activity on this post.\n\nI have the following configurations related to log retention:\n\n```\n...\ncompactor:\n  ...\n  retention_enabled: true\n...\nlimits_config:\n  ...\n  retention_period: 90d\n...\n```\n\nSee more about Loki configuration in the documentation [here](https://grafana.com/docs/loki/latest/configuration/)\n\n[Share](https://stackoverflow.com/a/73140146)\n\nShare a link to this answer\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this answer\n\n[Improve this answer](https://stackoverflow.com/posts/73140146/edit \"\")\n\nFollow\n\n\n\nFollow this answer to receive notifications\n\nanswered Jul 27, 2022 at 14:51\n\n[![Marcelo \u00c1vila de Oliveira's user avatar](https://lh3.googleusercontent.com/--qAy9sY_FtU/AAAAAAAAAAI/AAAAAAAAAcI/1eUd0gZytXc/s64-rj/photo.jpg)](https://stackoverflow.com/users/4653675/marcelo-%c3%81vila-de-oliveira)\n\n[Marcelo \u00c1vila de Oliveira](https://stackoverflow.com/users/4653675/marcelo-%c3%81vila-de-oliveira)\n\n23.2k33 gold badges5252 silver badges6060 bronze badges\n\n## Comments\n\nAdd a comment\n\nThis answer is useful\n\n8\n\nThis answer is not useful\n\nSave this answer.\n\nLoading when this answer was accepted\u2026\n\n[Timeline](https://stackoverflow.com/posts/75232337/timeline)\n\nShow activity on this post.\n\n[Grafana Loki Storage Retention](https://grafana.com/docs/loki/latest/operations/storage/retention/)\n\n> By default, when `table_manager.retention_deletes_enabled` or\n> `compactor.retention_enabled` _flags are not set_, **then logs sent to**\n> **Loki live forever.**\n\n**The minimum retention period is 24h**.\n\nThe retention period **must be a multiple** of the _index_ and chunks table `period`, configured in the `period_config` block.\n\nSample config:\n\n```yaml\nCopy\nschema_config:\n  configs:\n    - from: 2020-10-24\n      store: boltdb-shipper\n      object_store: filesystem\n      schema: v11\n      index:\n        prefix: index_\n        period: 24h\n\ntable_manager:\n  retention_deletes_enabled: true\n  retention_period: 24h\n```\n\nThe other way to setup the retention in Grafana Loki is via the Compactor.\n\n```yaml\nCopy\nlimits_config:\n  retention_period: 168h\n\ncompactor:\n  working_directory: /data/retention\n  compaction_interval: 10m\n  retention_enabled: true\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n\nschema_config:\n  configs:\n    - from: 2020-10-24\n      store: boltdb-shipper\n      object_store: filesystem\n      schema: v11\n      index:\n        prefix: index_\n        period: 24h\n```\n\nNote that **retention is only available if the index period is 24h**.\n\nTo purge data immediately you could set the `retention_delete_delay` interval to `1m`. This is a delay after which chunks will be fully deleted during retention.\n\nDo not forget to restart Loki after changing the configuration:\n\n```bash\nCopy\nsystemctl restart loki\nsystemctl status loki\n```\n\n[Share](https://stackoverflow.com/a/75232337)\n\nShare a link to this answer\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this answer\n\n[Improve this answer](https://stackoverflow.com/posts/75232337/edit \"\")\n\nFollow\n\n\n\nFollow this answer to receive notifications\n\n[edited Aug 17, 2023 at 12:22](https://stackoverflow.com/posts/75232337/revisions \"show all edits to this post\")\n\nanswered Jan 25, 2023 at 10:03\n\n[![Vladislav's user avatar](https://www.gravatar.com/avatar/60d4532b799a1ff5f985df6f402cdfe3?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/155687/vladislav)\n\n[Vladislav](https://stackoverflow.com/users/155687/vladislav)\n\n2,09311 gold badge3333 silver badges4242 bronze badges\n\n## 5 Comments\n\nAdd a comment\n\n[![](https://i.sstatic.net/EPmGy.jpg?s=64)](https://stackoverflow.com/users/9072753/kamilcuk)\n\nKamilCuk\n\n[KamilCuk](https://stackoverflow.com/users/9072753/kamilcuk) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment135587402_75232337)\n\n`This is a delay after which chunks will be fully deleted during retention` I do not understand. So the logs will be deleted after retention\\_delete\\_delay or after limits\\_config: retention\\_period? Why are there two settings?\n\n2023-08-16T09:32:58.977Z+00:00\n\n0\n\nReply\n\n- Copy link\n\n[![](https://www.gravatar.com/avatar/60d4532b799a1ff5f985df6f402cdfe3?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/155687/vladislav)\n\nVladislav\n\n[Vladislav](https://stackoverflow.com/users/155687/vladislav) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment135602762_75232337)\n\n`retention_delete_delay` just delays deleting defined in `limits_config\\retention_period`. The reason for that is described in [grafana.com/docs/loki/latest/operations/storage/retention](https://grafana.com/docs/loki/latest/operations/storage/retention/) as: \"1. ... deleting chunks instantly could lead to components still having reference to old chunks and so they could fails to execute queries. Having a delay allows for components to refresh their store and so remove gracefully their reference of those chunks. 2. It provides a short window of time in which to cancel chunk deletion in the case of a configuration mistake.\"\n\n2023-08-17T12:23:43.223Z+00:00\n\n3\n\nReply\n\n- Copy link\n\n[![](https://i.sstatic.net/X8yzA.jpg?s=64)](https://stackoverflow.com/users/1988508/mohammed-noureldin)\n\nMohammed Noureldin\n\n[Mohammed Noureldin](https://stackoverflow.com/users/1988508/mohammed-noureldin) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment137331970_75232337)\n\nHi, do you have an idea, if they support using 1w for retention, for example. It is a bit confusing that you can use the unit of time \"h\", but you must use multiples of 24h. Why they just did not enforce using the unit \"d\"? Or can we use d or w or m? I could not find this info the docs.\n\n2024-01-29T10:15:18.853Z+00:00\n\n1\n\nReply\n\n- Copy link\n\n[![](https://graph.facebook.com/693489905/picture?type=large)](https://stackoverflow.com/users/3195089/jeremy-d)\n\nJeremy D\n\n[Jeremy D](https://stackoverflow.com/users/3195089/jeremy-d) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment138669644_75232337)\n\nThe table manager is now deprecated. [grafana.com/docs/loki/latest/operations/storage/retention/\u2026](https://grafana.com/docs/loki/latest/operations/storage/retention/#table-manager-deprecated)\n\n2024-06-21T14:58:19.763Z+00:00\n\n0\n\nReply\n\n- Copy link\n\n[![](https://www.gravatar.com/avatar/6349954cca4ca0cfbad244fb265bd805?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/9351221/lethargos)\n\nLethargos\n\n[Lethargos](https://stackoverflow.com/users/9351221/lethargos) [Over a year ago](https://stackoverflow.com/questions/73138278/why-my-loki-log-retention-is-not-working#comment139289389_75232337)\n\nCan anyone explain to me what the /data/retention path refers to? Is it the chunks path? For example /var/lib/loki/chunks?\n\n2024-09-18T12:19:56.59Z+00:00\n\n0\n\nReply\n\n- Copy link\n\nAdd a comment\n\nThis answer is useful\n\n-1\n\nThis answer is not useful\n\nSave this answer.\n\nLoading when this answer was accepted\u2026\n\n[Timeline](https://stackoverflow.com/posts/73907780/timeline)\n\nShow activity on this post.\n\nFrom the [Grafana storage documentation](https://grafana.com/docs/loki/latest/storage/#retention):\n\n> With the exception of the filesystem chunk store, Loki will not delete old chunk stores. This is generally handled instead by configuring TTLs (time to live) in the chunk store of your choice (bucket lifecycles in S3/GCS, and TTLs in Cassandra). Neither will Loki currently delete old data when your local disk fills when using the filesystem chunk store \u2013 deletion is only determined by retention duration.\n\nThis quote should answer your question. You need to configure bucket lifecycles in your storage provider to be able to delete chunk stores.\n\n[Share](https://stackoverflow.com/a/73907780)\n\nShare a link to this answer\n\nCopy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ \"The current license for this post: CC BY-SA 4.0\")\n\nShort permalink to this answer\n\n[Improve this answer](https://stackoverflow.com/posts/73907780/edit \"\")\n\nFollow\n\n\n\nFollow this answer to receive notifications\n\nanswered Sep 30, 2022 at 11:05\n\n[![Ri1a's user avatar](https://www.gravatar.com/avatar/728ba55606bef39aa7b37489da92893b?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/10408262/ri1a)\n\n[Ri1a](https://stackoverflow.com/users/10408262/ri1a)\n\n74399 silver badges2727 bronze badges\n\n## Comments\n\nAdd a comment\n\n## Your Answer\n\n**Reminder:** Answers generated by AI tools are not allowed due to Stack Overflow's [artificial intelligence policy](https://stackoverflow.com/help/gen-ai-policy)\n\nDraft saved\n\nDraft discarded\n\n### Sign up or [log in](https://stackoverflow.com/users/login?ssrc=question_page&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f73138278%2fwhy-my-loki-log-retention-is-not-working%23new-answer)\n\nSign up using Google\n\n\nSign up using Email and Password\n\n\nSubmit\n\n### Post as a guest\n\nName\n\nEmail\n\nRequired, but never shown\n\nPost Your Answer\n\nDiscard\n\n\nBy clicking \u201cPost Your Answer\u201d, you agree to our [terms of service](https://stackoverflow.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://stackoverflow.com/legal/privacy-policy).\n\n\nStart asking to get answers\n\nFind the answer to your question by asking.\n\n[Ask question](https://stackoverflow.com/questions/ask)\n\nExplore related questions\n\n- [purge](https://stackoverflow.com/questions/tagged/purge \"show questions tagged 'purge'\")\n- [retention](https://stackoverflow.com/questions/tagged/retention \"show questions tagged 'retention'\")\n- [grafana-loki](https://stackoverflow.com/questions/tagged/grafana-loki \"show questions tagged 'grafana-loki'\")\n- [promtail](https://stackoverflow.com/questions/tagged/promtail \"show questions tagged 'promtail'\")\n\nSee similar questions with these tags."
          }
        },
        {
          "url": "https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/",
          "title": "Log entry deletion | Grafana Loki documentation",
          "description": "Describes how Loki implements log deletion and deletion configuration options.",
          "thumbnail_url": "https://grafana.com/meta-generator/Log+entry+deletion@@@loki@@@4.png",
          "original_thumbnail_url": "https://grafana.com/meta-generator/Log+entry+deletion@@@loki@@@4.png",
          "favicon_url": "https://you.com/favicon?domain=grafana.com&size=128",
          "snippets": [
            "When retention is enabled, use the deletion_mode tenant override to control which tenants can use the deletion API. ... Deletion of log lines with line filters is one of the compactor\u2019s most resource-intensive operations. If you delete large volumes of data with line filters, refer to Horizontal scaling of Compactor to distribute that work across multiple compactor instances. ... See a demo of the updated features in Loki, and how to create metrics from logs and alert on your logs with powerful Prometheus-style alerting rules.",
            "When you migrate from one database type to another, you can set backup_delete_request_store_db_type to boltdb so that delete requests are also written to a backup database. Refer to the compactor configuration reference for details. The deletion API endpoints are registered only when compactor.retention_enabled is true.",
            "It is also supported on the deprecated BoltDB Shipper index, but BoltDB Shipper is being removed in Loki 4.0, so new deployments should use TSDB. The compactor component exposes REST endpoints that process delete requests. Hitting the endpoint specifies the streams and the time window. The deletion of the log entries takes place after a configurable cancellation time period expires. Log entry deletion relies on configuration of the custom logs retention workflow as defined for the compactor.",
            "Enable log entry deletion by setting retention_enabled to true in the compactor\u2019s configuration (-compactor.retention-enabled on the command line). The tenant\u2019s deletion_mode must also be filter-only or filter-and-delete, which is the case by default."
          ],
          "contents": {
            "markdown": "![ObservabilityCON 2025](https://a-us.storyblok.com/f/1022730/280x40/b0872b99f9/grafana-logo-observabilitycon-2025-black.svg/m/)\n\nWatch the keynote again and signup for more on-demand sessions.\n\n\n[Watch keynote](https://grafana.com/events/observabilitycon/?plcmt=obscon2025-post-event-banner)![](https://grafana.com/media/events/grafanacon/2025/icon-close-x.svg)\n\n![ObservabilityCON 2025](https://grafana.com/media/events/obscon/2025/grafana-obscon2025-promo-logo-black.svg)\n\n\ud83d\udce2 Registration + agenda now live\nExplore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).\n\n\n[Register now](https://grafana.com/events/observabilitycon/?tech=target&plcmt=top-banner&aud=default)\n\nSearching...\n\nSite search\n\nAsk Grot AI\n\n[Try using ![Grot AI](https://grafana.com/static/img/grot-chat.svg)**Grot AI** for this query ->](https://grafana.com/grot/?chat=&from=/search)\n\nAll\n\nDocs\n\nView all results\n\nNo results.\n\nThere was an error with your request.\n\n> Documentation for automated readers\n>\n> A curated documentation index is available at: https://grafana.com/llms.txt\n>\n> A complete documentation index is available at: https://grafana.com/llms-full.txt\n>\n> These indexes can help with page discovery before fetching individual documents.\n\nThis page is also available in Markdown, which may be easier for automated readers\nand AI tools to parse than HTML. The Markdown version is available at\nhttps://grafana.com/docs/loki/latest/operations/storage/logs-deletion.md, or by sending\nAccept: text/markdown to https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/. For broader\ndocumentation discovery, the curated index is available at https://grafana.com/llms.txt\nand the complete index is available at https://grafana.com/llms-full.txt.\n\nLog entry deletion\n\n[Documentation](https://grafana.com/docs/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Grafana Loki](https://grafana.com/docs/loki/latest/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Manage](https://grafana.com/docs/loki/latest/operations/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Storage](https://grafana.com/docs/loki/latest/operations/storage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)Log entry deletion\n\nOpen source\n\n# Log entry deletion\n\nGrafana Loki supports the deletion of log entries from a specified stream.\nLog entries that fall within a specified time window and match an optional line filter are those that will be deleted.\n\nLog entry deletion is supported when the TSDB index is configured as the index store. It is also supported on the deprecated BoltDB Shipper index, but BoltDB Shipper is being removed in Loki 4.0, so new deployments should use TSDB.\n\nThe compactor component exposes REST\n[endpoints](https://grafana.com/docs/loki/latest/reference/loki-http-api/#compactor) that process delete requests.\nHitting the endpoint specifies the streams and the time window.\nThe deletion of the log entries takes place after a configurable cancellation time period expires.\n\nLog entry deletion relies on configuration of the custom logs retention workflow as defined for the\n[compactor](https://grafana.com/docs/loki/latest/operations/storage/retention/#compactor). The compactor looks at unprocessed requests which are past their cancellation period to decide whether a chunk is to be deleted or not.\n\n## Configuration\n\nEnable log entry deletion by setting `retention_enabled` to `true` in the compactor\u2019s configuration (`-compactor.retention-enabled` on the command line). The tenant\u2019s `deletion_mode` must also be `filter-only` or `filter-and-delete`, which is the case by default.\n`delete_request_store` also needs to be configured when retention is enabled to process delete requests, this determines the storage bucket that stores the delete requests.\n\n> Warning\n>\n> Be very careful when enabling retention. It is strongly recommended that you also enable versioning on your objects in object storage to allow you to recover from accidental misconfiguration of a retention setting. If you want to enable deletion but do not want to enforce retention, configure the `retention_period` setting with a value of `0s`.\n\n`deletion_mode` is a global and per-tenant setting in\n[`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config). Its default value is `filter-and-delete`, so log entry deletion is active for every tenant as soon as `retention_enabled` is `true` and `delete_request_store` is configured, unless you explicitly change the mode. Set `deletion_mode` in the main configuration file for a global default, or override it per tenant in the\n[runtime configuration file](https://grafana.com/docs/loki/latest/configure/#runtime-configuration-file).\n\n`deletion_mode` supports three values:\n\n- `disabled`: Deletion is not allowed. Requests to the deletion API endpoints are rejected with a `403 Forbidden` response.\n- `filter-only`: Log lines matching the query in the delete request are filtered out when querying Loki. They are not removed from storage.\n- `filter-and-delete`: Log lines matching the query in the delete request are filtered out when querying Loki, and they are also removed from storage. This is the default.\n\nA delete request may be canceled within a configurable cancellation period. Set the `delete_request_cancel_period` in the compactor\u2019s YAML configuration or on the command line when invoking Loki. Its default value is 24h. To cancel a delete request that has already started processing, pass the `force=true` query parameter to the cancellation endpoint.\n\nDelete requests that include a line filter are split into smaller requests that each cover no more than `delete_max_interval` (24h by default). You can request a smaller split for a single request with the `max_interval` query parameter, but it cannot be larger than `delete_max_interval`. Delete requests without a line filter are not split. Refer to the\n[HTTP API reference](https://grafana.com/docs/loki/latest/reference/loki-http-api/#request-log-deletion) for the full set of request parameters.\n\nDelete requests themselves are stored using the database type set by `delete_request_store_db_type`, which defaults to `boltdb`. You can instead use `sqlite`. When you migrate from one database type to another, you can set `backup_delete_request_store_db_type` to `boltdb` so that delete requests are also written to a backup database. Refer to the\n[compactor configuration reference](https://grafana.com/docs/loki/latest/configure/#compactor) for details.\n\nThe deletion API endpoints are registered only when `compactor.retention_enabled` is `true`. When retention is not enabled, the endpoints are unavailable for every tenant, whatever the `deletion_mode` value is. When retention is enabled, use the `deletion_mode` tenant override to control which tenants can use the deletion API.\n\n> Note\n>\n> Deletion of log lines with line filters is one of the compactor\u2019s most resource-intensive operations. If you delete large volumes of data with line filters, refer to\n> [Horizontal scaling of Compactor](https://grafana.com/docs/loki/latest/operations/storage/compactor-horizontal-scaling/) to distribute that work across multiple compactor instances.\n\n## Was this page helpful?\n\n![\ud83d\udc4d](https://grafana.com/media/images/svg/thumbs-up.svg) Yes![\ud83d\udc4e](https://grafana.com/media/images/svg/thumbs-up.svg) No\n\n[Suggest an edit in GitHub](https://github.com/grafana/loki/edit/release-3.7.x/docs/sources/operations/storage/logs-deletion.md) [Create a GitHub issue](https://github.com/grafana/loki/issues/new?title=Documentation%20feedback:%20/docs/sources/operations/storage/logs-deletion.md) [Email docs@grafana.com](mailto:docs@grafana.com) [Help and support](https://grafana.com/help/) [Community](https://grafana.com/community/)\n\n## Related resources from Grafana Labs\n\nAdditional helpful documentation, links, and articles:\n\n[![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Getting started with logging and Grafana Loki](https://grafana.com/static/assets/featured/getting-started-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nGetting started with logging and Grafana Loki\\\\\n\\\\\nSee a demo of the updated features in Loki, and how to create metrics from logs and alert on your logs with powerful Prometheus-style alerting rules.](https://grafana.com/go/webinar/getting-started-with-logging-and-grafana-loki/?pg=docs-loki-latest-operations-storage-logs-deletion&plcmt=related) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Essential Grafana Loki configuration settings](https://grafana.com/static/assets/featured/logging-with-loki-essential-configuration-settings_featured.png?w=400)\\\\\n\\\\\nEssential Grafana Loki configuration settings\\\\\n\\\\\nThis webinar focuses on Grafana Loki configuration including agents Promtail and Docker; the Loki server; and Loki storage for popular backends.](https://grafana.com/go/webinar/logging-with-loki-essential-configuration-settings/?pg=docs-loki-latest-operations-storage-logs-deletion&plcmt=related-2) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Scaling and securing your logs with Grafana Loki](https://grafana.com/static/assets/featured/scaling-and-securing-your-logs-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nScaling and securing your logs with Grafana Loki\\\\\n\\\\\nThis webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.](https://grafana.com/go/webinar/scaling-and-securing-your-logs-with-grafana-loki/?pg=docs-loki-latest-operations-storage-logs-deletion&plcmt=related-3)\n\nAsk Grafana Assistant"
          }
        },
        {
          "url": "https://grafana.com/docs/loki/latest/",
          "title": "Grafana Loki | Grafana Loki documentation",
          "description": "Grafana Loki is a set of open source components that can be composed into a fully featured logging stack.",
          "thumbnail_url": "https://grafana.com/meta-generator/Grafana+Loki@@@loki@@@9.png",
          "original_thumbnail_url": "https://grafana.com/meta-generator/Grafana+Loki@@@loki@@@9.png",
          "favicon_url": "https://you.com/favicon?domain=grafana.com&size=128",
          "snippets": [
            "Retention in Loki is handled by the Compactor, not by the ingester or storage backend directly. A few common reasons why old data persists even after configuring a retention period: retention_enabled: true must be set under the compactor block, not just in limits_config. The Compactor must be running. In monolithic deployments it is sometimes inadvertently disabled. Deletion is not immediate.",
            "Unlike other logging systems, Loki is built around the idea of only indexing metadata about your logs\u2019 labels (just like Prometheus labels). Log data itself is then compressed and stored in chunks in object stores such as Amazon Simple Storage Service (S3) or Google Cloud Storage (GCS), or even locally on the filesystem.",
            "Loki\u2019s indexing model is label-based, which is different from most logging systems. Read Labels and the label best practices early \u2014 how you label your logs directly affects query performance and storage costs. Learn LogQL. LogQL is Loki\u2019s query language. Start with simple label matchers and line filters, then explore log pipeline stages and metric queries as you need them. Explore with Grafana. Connect Loki as a data source in Grafana and use Explore to run ad-hoc queries against your logs.",
            "compactor: working_directory: /data/loki/compactor retention_enabled: true delete_request_store:  limits_config: retention_period: 360h \u00b7 To verify the Compactor is running and retention is active, check the Loki logs for lines referencing compactor and look for the metrics loki_boltdb_shipper_compact_tables_operation_total (compaction runs) and loki_compactor_apply_retention_operation_total (retention runs)."
          ],
          "contents": {
            "markdown": "## Overview\n\nUnlike other logging systems, Loki is built around the idea of only indexing metadata about your logs\u2019 labels (just like Prometheus labels). Log data itself is then compressed and stored in chunks in object stores such as Amazon Simple Storage Service (S3) or Google Cloud Storage (GCS), or even locally on the filesystem.\n\n## Explore\n\n## Grafana Loki, frequently asked questions\n\nHere are answers to some frequently asked questions about how to configure and run Loki.\n\n### Where should I start if I\u2019m new to Loki?\n\nStart with the Loki Tutorial, which walks you through what Loki is, how it works, and how the components fit together.\n\n- Try it locally. The fastest way to experiment is to run Loki in monolithic (single-binary) mode with a local filesystem backend and send logs to it with Grafana Alloy.\n- Understand labels. Loki\u2019s indexing model is label-based, which is different from most logging systems. Read Labels and the label best practices early \u2014 how you label your logs directly affects query performance and storage costs.\n- Learn LogQL. LogQL is Loki\u2019s query language. Start with simple label matchers and line filters, then explore log pipeline stages and metric queries as you need them.\n- Explore with Grafana. Connect Loki as a data source in Grafana and use Explore to run ad-hoc queries against your logs.\n\n\nThe Grafana Labs Learning Hub offers self-paced, hands-on courses relevant to Loki:\n\n- Send logs to Grafana Cloud using Alloy \u2014 Walk through configuring Grafana Alloy to ship logs to Loki in Grafana Cloud.\n- Send data from external collectors \u2014 Learn how to send logs to Loki using OpenTelemetry (OTLP) or the HTTP API, and choose the right method for your setup.\n- Explore your infrastructure data with Grafana Drilldown apps \u2014 Explore Loki logs visually without writing LogQL, using the Logs Drilldown app to filter by labels, detect patterns, and investigate errors.\n- Optimize Adaptive Logs \u2014 Reduce log volume and storage costs in Grafana Cloud by tuning which logs Loki ingests.\n\n\n### Should I self-host or use Grafana Cloud for logs?\n\nThe right answer depends on your team\u2019s capacity and priorities. Choose Grafana Cloud if you want to get up and running quickly, prefer not to manage infrastructure, or are a small team without dedicated operations resources. The free tier is generous enough for most individuals and small projects.\n\nChoose self-hosted OSS or Enterprise if you have strict data residency or compliance requirements, need to keep all data on your own infrastructure, or have an existing investment in self-managed tooling like Prometheus and want to extend it.\n\nThe feature set between Cloud and a self-managed Enterprise stack is broadly equivalent. The primary difference is operational overhead: self-hosting means you own the availability, scaling, and maintenance of every component in the stack.\n\n### What are the best practices for Loki labels vs. structured metadata?\n\nLoki\u2019s indexing model differs significantly from other observability products. Choosing the wrong fields as labels is the most common cause of poor query performance and high resource usage.\n\nLabels define a log stream. Every unique combination of label values creates a new stream, which is stored and indexed separately.\n\n- \u2705 Use labels for low-cardinality dimensions you will always filter on:\n\n    env\n\n,\n\n    cluster\n\n,\n\n    namespace\n\n,\n\n    app\n\n,\n\n    job\n\n.\n\n- \u274c Do not use labels for high-cardinality values: pod, instance IDs, request IDs, user IDs, trace IDs, HTTP status codes, IP addresses. Each unique value creates a new stream, causing \u201ccardinality explosion\u201d that degrades ingestion and query performance.\n\n\nStructured metadata (introduced in Loki 3.0) allows attaching key-value pairs to log entries without creating new streams. Use it for values you want to filter or display but that are too high-cardinality for labels:\n\n  \n\n    // Example: attaching trace_id as structured metadata via Alloy\n    loki.process \"default\" {\n      stage.json {\n        expressions = { \"trace_id\" = \"\" }\n      }\n\n      stage.structured_metadata {\n        values = { \"trace_id\" = \"\" }\n      }\n\n      forward_to = [loki.write.local.receiver]\n    }\n\n    loki.write \"local\" {\n      endpoint {\n        url = \"http://loki:3100/loki/api/v1/push\"\n      }\n    }\n\n\n  \n\nParsed fields (extracted at query time with\n\n    | json\n\n,\n\n    | logfmt\n\n,\n\n    | pattern\n\n,\n\n    | regexp\n\n) require no schema changes and add no indexing overhead. Prefer them for ad-hoc filtering on log content.\n\nRule of thumb: If you would filter by it in every query, it belongs in a label. If you only need it occasionally or it has many unique values, use structured metadata or parse it from the log line at query time.\n\n### Why does     service_name show as     unknown_service in Explore Logs?\n\nLoki\u2019s Explore Logs feature uses a\n\n    service_name\n\nlabel to group and navigate logs. If it shows\n\n    unknown_service\n\n, Loki could not automatically determine a service name from the incoming stream.\n\nIf a\n\n    service_name\n\nlabel is already present on the stream, Loki uses it directly. Otherwise, Loki\u2019s\n\n    discover_service_name\n\nfeature looks for the first non-empty value from these label keys, in order:\n\n- service\n- app\n- application\n- app_name\n- name\n- app_kubernetes_io_name\n- container\n- container_name\n- k8s_container_name\n- component\n- workload\n- job\n- k8s_job_name\n\n\nCommon causes:\n\n- The log shipper (Alloy, OTel Collector, kube-logging-operator) is not forwarding Kubernetes metadata as stream labels.\n- The label name uses dot notation (\n\n    service.name\n\n). Loki normalizes label names server-side, replacing dots with underscores (for example,\n\n    service.name\n\nbecomes\n\n    service_name\n\n).\n\n-\n\n    discover_service_name\n\nis disabled in your Loki configuration.\n\nVerify by checking your stream labels in Explore. If none of the above keys are present as labels, configure your log shipper to include them. For Alloy, ensure\n\n    loki.source.kubernetes\n\nor\n\n    discovery.kubernetes\n\nis passing through pod metadata.\n\nYou can customize the list of labels Loki checks by setting\n\n    discover_service_name\n\nin\n\n    limits_config\n\n.\n\n### How do I fix \u201cingestion rate limit exceeded\u201d (HTTP 429) errors?\n\nA 429 error from Loki means an ingestion rate limit has been hit. Loki enforces limits both globally and per-stream.\n\nGlobal ingestion limits (applied per tenant):\n\n  \n\n    limits_config:\n      ingestion_rate_mb: 16        # default: 4 MB/s\n      ingestion_burst_size_mb: 32  # default: 6 MB\n\n\n  \n\nPer-stream rate limit:\n\n  \n\n    limits_config:\n      per_stream_rate_limit: 5MB        # default: 3MB\n      per_stream_rate_limit_burst: 15MB # default: 15MB (5x the rate limit)\n\n\n  \n\nTo identify which streams are responsible, check the error message in your log shipper. It includes the stream labels of the offending stream. You can also query Loki\u2019s metrics endpoint for\n\n    loki_ingester_streams_created_total\n\nbroken down by tenant.\n\nIf you are self-hosting and consistently hitting limits with legitimate log volume, increase the values above in\n\n    limits_config\n\n. If you are on Grafana Cloud, contact support to adjust your plan limits.\n> Note\n>\n> Increasing limits without investigating root cause can mask runaway log producers. Always check whether a specific workload or namespace is generating an unexpected spike before raising limits.\n\n### Why can\u2019t Grafana connect to Loki when both are running in Docker?\n\nWhen Grafana and Loki run as separate Docker containers,\n\n    localhost\n\ninside the Grafana container refers to the Grafana container itself, not the host machine or the Loki container. This is the most common misconfiguration for new users.\n\nCorrect datasource URL in Docker Compose:\n\n  \n\n    # docker-compose.yml\n    services:\n      loki:\n        image: grafana/loki:latest\n        ports:\n          - \"3100:3100\"\n\n      grafana:\n        image: grafana/grafana:latest\n        environment:\n          - GF_DATASOURCES_DEFAULT_URL=http://loki:3100\n\n\n  \n\nIn Grafana\u2019s datasource settings, use\n\n    http://loki:3100\n\n(the Docker Compose service name) instead of\n\n    http://localhost:3100\n\n.\n\nFor Kubernetes deployments, use the in-cluster service DNS name:\n\n  \n\n    http://loki.monitoring.svc.cluster.local:3100\n\n\n  \n\nVerify connectivity by exec-ing into the Grafana container and running:\n\n  \n\n    curl http://loki:3100/ready\n\n\n  \n\nIf this returns\n\n    ready\n\n, the networking is correct and the issue lies in the Grafana datasource configuration itself.\n\n### What causes \u201cToo many outstanding requests\u201d errors on my dashboard?\n\nThis error occurs when the number of concurrent queries to Loki exceeds the configured limit for a tenant. It is most common when a dashboard has four or more panels querying over a long time range against a single-node (monolithic) deployment.\n\nKey configuration knobs:\n\n  \n\n    query_scheduler:\n      max_outstanding_requests_per_tenant: 32000  # default: 32000\n\n    frontend:\n      max_outstanding_per_tenant: 2048            # default: 2048\n\n    limits_config:\n      split_queries_by_interval: 24h              # default: 1h\n\n\n  \n\nSplitting queries by interval reduces the load per request by breaking large time-range queries into smaller parallel chunks. For single-node deployments under sustained dashboard load, also consider increasing chunk sizes to reduce the total number of chunk reads:\n\n  \n\n    ingester:\n      chunk_target_size: 1572864\n      max_chunk_age: 2h\n      chunk_idle_period: 30m\n\n\n  \n\nIf the issue persists at scale, consider moving from a monolithic deployment to microservices mode.\n\n### How do I make a LogQL query return zero instead of \u201cno data\u201d?\n\nBy default, LogQL metric queries return no data points for intervals where no log lines matched, rather than returning\n\n    0\n\n. This breaks percentage calculations and alert rules that expect a numeric baseline.\n\nWorkaround using\n\n    or on() vector(0)\n\n(mirrors the PromQL pattern):\n\n  \n\n    (\n      sum(count_over_time({app=\"my-app\"} |= \"error\" [5m]))\n      or on() vector(0)\n    )\n\n\n  \n\nFor ratio/percentage queries, guard the denominator with\n\n    > 0\n\nto avoid dividing by zero (which produces\n\n    NaN\n\n), and wrap the entire expression with\n\n    or on() vector(0)\n\nso quiet periods return\n\n    0\n\ninstead of no data:\n\n  \n\n    (\n      (\n        sum(count_over_time({app=\"my-app\"} | json | status=~\"5..\" [5m]))\n        or on() vector(0)\n      )\n      /\n      (\n        sum(count_over_time({app=\"my-app\"} [5m]))\n        > 0\n      )\n    )\n    or on() vector(0)\n\n\n  \n\nFor alerting, this pattern is essential. Without it, an alert rule using\n\n    count_over_time\n\nproduces no evaluation result (not\n\n    0\n\n) during quiet periods, which can cause alerts to flap or never resolve correctly.\n\n### Why isn\u2019t my log retention policy deleting old data?\n\nRetention in Loki is handled by the Compactor, not by the ingester or storage backend directly. A few common reasons why old data persists even after configuring a retention period:\n\n-\n\n    retention_enabled: true\n\nmust be set under the\n\n    compactor\n\nblock, not just in\n\n    limits_config\n\n.\n\n- The Compactor must be running. In monolithic deployments it is sometimes inadvertently disabled.\n- Deletion is not immediate. The Compactor runs on a schedule and only marks chunks for deletion after a configurable grace period (\n\n    retention_delete_delay\n\n).\n\n- When using filesystem storage, the chunks directory size may not visibly decrease right away. The Compactor marks files for deletion first, then removes them on subsequent runs.\n\n\nMinimum required configuration:\n\n  \n\n    compactor:\n      working_directory: /data/loki/compactor\n      retention_enabled: true\n      delete_request_store: <your-object-store>\n\n    limits_config:\n      retention_period: 360h\n\n\n  \n\nTo verify the Compactor is running and retention is active, check the Loki logs for lines referencing\n\n    compactor\n\nand look for the metrics\n\n    loki_boltdb_shipper_compact_tables_operation_total\n\n(compaction runs) and\n\n    loki_compactor_apply_retention_operation_total\n\n(retention runs)."
          }
        },
        {
          "url": "https://blog.devops.dev/log-and-metric-retention-in-loki-and-prometheus-57e81bbad023?gi=780056f55dc2",
          "title": "Log and Metric Retention in Loki and Prometheus | by Faith Sodipe ...",
          "description": "Log and Metric Retention in Loki and Prometheus When working with observability tools such as Grafana, Loki and Prometheus, storage management is crucial to performance, cost, and compliance. By \u2026",
          "thumbnail_url": "https://miro.medium.com/v2/resize:fit:567/1*PjAQ8DrLYFGmmWeJSB--cA.png",
          "original_thumbnail_url": "https://miro.medium.com/v2/resize:fit:567/1*PjAQ8DrLYFGmmWeJSB--cA.png",
          "page_age": "2025-06-13T16:31:59",
          "favicon_url": "https://you.com/favicon?domain=blog.devops.dev&size=128",
          "snippets": [
            "When working with observability tools such as Grafana, Loki and Prometheus, storage management is crucial to performance, cost, and\u2026",
            "However, the Loki in question here is a Prometheus-inspired log aggregation system that is highly available and horizontally scalable. When compared to Elasticsearch-based solutions, Loki is lighter and less expensive since it simply index labels rather than the entire log data. My Loki is different. I am a god, he is just a log index storage \u00b7 Configuring Retention Policies Loki supports retention only when using the boltdb-shipper or tsdb block storage engine alongside compactor.",
            "When working with observability tools such as Grafana, Loki and Prometheus, storage management is crucial to performance, cost, and compliance. By default, these systems can keep logs and metrics indefinitely, which may result in disk bloat and poor query speed. In this article, we\u2019ll go over how to set up data retention policies for Loki and Prometheus, ensuring that old logs and metrics are safely removed after a certain time period.",
            "Compactor: provides explicit instructions on how the compactor should go about its clearing and forwarding business. compaction_interval specifies the frequency of operation, retention_enabled determines if the compactor is allowed to perform retention operations. retention_delete_delay tells the compactor to wait x amount of time (sec, min , hrs, month, year etc) after the set retention period before swinging into action. Verification and Testing Since my application uses docker, all my services such as Prometheus, Grafana and Loki itself have been configured to run in the container."
          ],
          "contents": {
            "markdown": "[Sitemap](https://blog.devops.dev/sitemap/sitemap.xml)\n\n[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fblog.devops.dev%2Flog-and-metric-retention-in-loki-and-prometheus-57e81bbad023&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n[Medium Logo](https://medium.com/?source=---top_nav_layout_nav-------------------------------------------)\n\nGet app\n\n[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav--------------------)\n\n[Search](https://medium.com/search?source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fblog.devops.dev%2Flog-and-metric-retention-in-loki-and-prometheus-57e81bbad023&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n![Unknown user](https://miro.medium.com/v2/resize:fill:64:64/1*dmbNkD5D-u45r44go_cf0g.png)\n\n[**DevOps.dev**](https://blog.devops.dev/?source=post_page---publication_nav-33f8b2d9a328-57e81bbad023-----------------------------------------)\n\n\u00b7\n\nFollow publication\n\n[![DevOps.dev](https://miro.medium.com/v2/resize:fill:76:76/1*3SZtM9yhQyfh-dfWk5gGFw.jpeg)](https://blog.devops.dev/?source=post_page---post_publication_sidebar-33f8b2d9a328-57e81bbad023-----------------------------------------)\n\n[Devops.dev](http://devops.dev/) is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.\n\nFollow publication\n\n[Containerization](https://medium.com/tag/containerization?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[Docker](https://medium.com/tag/docker?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[Prometheus](https://medium.com/tag/prometheus?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[Grafana](https://medium.com/tag/grafana?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n[DevOps](https://medium.com/tag/devops?source=post_page---header_tags--57e81bbad023-----------------------------------------)\n\n# Log and Metric Retention in Loki and Prometheus\n\n[![Faith Sodipe](https://miro.medium.com/v2/da:true/resize:fill:64:64/0*6zDALwKTapdArB48)](https://medium.com/@faithsodipe?source=post_page---byline--57e81bbad023-----------------------------------------)\n\n[Faith Sodipe](https://medium.com/@faithsodipe?source=post_page---byline--57e81bbad023-----------------------------------------)\n\nFollow\n\n5 min read\n\n\u00b7\n\nMay 30, 2025\n\n5\n\n1\n\n[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3D57e81bbad023&operation=register&redirect=https%3A%2F%2Fblog.devops.dev%2Flog-and-metric-retention-in-loki-and-prometheus-57e81bbad023&source=---header_actions--57e81bbad023---------------------post_audio_button--------------------)\n\nShare\n\nWhen working with observability tools such as Grafana, Loki and Prometheus, storage management is crucial to performance, cost, and compliance. By default, these systems can keep logs and metrics indefinitely, which may result in disk bloat and poor query speed.\n\nIn this article, we\u2019ll go over how to set up data retention policies for **Loki** and **Prometheus**, ensuring that old logs and metrics are safely removed after a certain time period. This article assumes that you are using Docker to build your application.\n\n**Why we may need this?** Configuring Log Retention Policies will:\n\n1\\. Remove sensitive logs/metrics after a while.\n\n2\\. Prevent disk overuse.\n\n3\\. Reduce clutter and increase query speed.\n\n## Loki\n\nIf you are a fan of Marvel, Loki is a god of Norse mythology, known as the trickster and god of mischief. However, the Loki in question here is a Prometheus-inspired log aggregation system that is highly available and horizontally scalable. When compared to Elasticsearch-based solutions, Loki is lighter and less expensive since it simply index labels rather than the entire log data.\n\n![](https://miro.medium.com/v2/resize:fit:220/1*5XOMwEQr7Qqq-JV2DqyZ-w.gif)\n\n**My Loki is different. I am a god, he is just a log index storage**\n\n**Configuring Retention Policies** Loki supports retention only when using the **boltdb-shipper or tsdb** blockstorage engine alongside **compactor**. This **compactor** is responsible for enforcing the deletion of old logs and merges index files while the **boltdb-shipper/tsdb** manages the storage of log index efficiently. Here is a minimal **loki-config.yaml** setup to enable retention.\n\n![](https://miro.medium.com/v2/resize:fit:567/1*PjAQ8DrLYFGmmWeJSB--cA.png)\n\n**Loki.yml file**\n\nThis file holds configurations under 3 different sections:\n\n- **storage\\_config**: defines the storage provider configurations(I used **tsdb** my project but you are able to use **boltdb** to achieve the same result).\n- **limits\\_config:** defines the behaviour of how log limits is handled in Loki. The **retention\\_period** property tells the compactor how long it should keep logs for before the big purge begins. Think of this as an explicit instruction on how to handle log retentions.\n- **Compactor:** provides explicit instructions on how the compactor should go about its clearing and forwarding business. **compaction\\_interval** specifies the frequency of operation, **retention\\_enabled** determines if the compactor is allowed to perform retention operations. **retention\\_delete\\_delay** tells the compactor to wait x amount of time (sec, min , hrs, month, year etc) after the set retention period before swinging into action.\n\n**Verification and Testing** Since my application uses docker, all my services such as **Prometheus**, **Grafana** and **Loki** itself have been configured to run in the container. For the sake of brevity, that configuration snippet is excluded from this article.\n\n## Get Faith Sodipe\u2019s stories in\u00a0your\u00a0inbox\n\nJoin Medium for free to get updates from\u00a0this\u00a0writer.\n\nSubscribe\n\nSubscribe\n\nRemember me for faster sign in\n\nAfter this necessary changes are made to the loki.yaml file, you may decide to restart your docker container to allow it pull the latest configuration first. Once its running, head over to your terminal and run the following command. This command shows docker logs specifically for the named container in the command.\n\n```\ndocker logs <loki-container-name>\n```\n\n<loki-container-name> refers to the name of your loki container you specified at the time of configuration. Just search the log for \u201c **retention**\u201d and you should find tags/meta data pointing to retention action as seen below.\n\nPress enter or click to view image in full size\n\n![](https://miro.medium.com/v2/resize:fit:700/1*M507epZpOiOOmOYIXmntMQ.png)\n\n**Docker Logs After Run**\n\nThat shows that retention is activated and the compactor is eavesdropping and counting down its own time, ready to clear old logs.\n\nNB: If you search for the keyword \u201c **retention**\u201d and you dont find anything, go through the process again as your configuration may be wrong. I have also attached the link to the official documentation at the end of this article to assist with debugging should the need arise.\n\n## Prometheus\n\nMetrics are stored in Prometheus\u2019s Time Series Database (TSDB). Retention can be set according to disk size or time. The retention configuration will be done in the docker-compose.yml file so as to attach the configuration to the instance once it is started.\n\n![](https://miro.medium.com/v2/resize:fit:528/1*9G6qONlteMiCeMZA_uCeJQ.png)\n\n**docker-compose.yml file**\n\nThe command section of this file has 3 parts to enable retention:\n\n- `\u2014 config.file=/etc/prometheus/prometheus.yml`: specifies the configuration file already defined for prometheus\n- `\u2014 storage.tsdb.path=/prometheus` **:** specifies the location of **tsdb** which is the index store used for holding our metrics\n- `\u2014 storage.tsdb.retention.time=7d`\\`: specifies the duration that prometheus is allowed to keep logs for before disposing them off.\n\n**NB:** You are able to configure retention also based on Disk size and storage space but our config focuses more on a time-based retention policy.\n\n**Verification and Testing** Everything runs in docker and therefore each service is containerized. Ensure to restart your docker container to allow these new changes to attach. If you are like who prefer to use GUIs, head over to the docker logs and search for \u201c **retention**\u201d in the log and you shall find traces of your retention policy being defined in the docker logs which basically means that your Prometheus instance now have retention activated. If youprefer terminal commands, run the command below:\n\n```\ndocker logs <prometheus-container-name>\n```\n\nThe Image below shows the result from my docker log showing my retention policy.\n\n![](https://miro.medium.com/v2/resize:fit:672/1*9ZYghkFbhcrgHiFDksU1pw.png)\n\n**Prometheus Container Docker Logs After Run**\n\nRetention configuring in Loki and Prometheus dont get easier than this. You may also se Grafana to test the behaviors of your services and see how they handle retention. For more detailed information, check out the official documentation here: [https://grafana.com/docs/loki/latest/operations/storage/retention/](https://grafana.com/docs/loki/latest/operations/storage/retention/)\n\nThank you!\n\n[Containerization](https://medium.com/tag/containerization?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[Docker](https://medium.com/tag/docker?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[Prometheus](https://medium.com/tag/prometheus?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[Grafana](https://medium.com/tag/grafana?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[DevOps](https://medium.com/tag/devops?source=post_page---footer_tags--57e81bbad023-----------------------------------------)\n\n[![Faith Sodipe](https://miro.medium.com/v2/resize:fill:96:96/0*6zDALwKTapdArB48)](https://medium.com/@faithsodipe?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\n[![Faith Sodipe](https://miro.medium.com/v2/resize:fill:128:128/0*6zDALwKTapdArB48)](https://medium.com/@faithsodipe?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\nFollow\n\n[**Written by Faith Sodipe**](https://medium.com/@faithsodipe?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\n[15 followers](https://medium.com/@faithsodipe/followers?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\n\u00b7 [13 following](https://medium.com/@faithsodipe/following?source=post_page---post_author_info--57e81bbad023-----------------------------------------)\n\nFollow\n\n[![DevOps.dev](https://miro.medium.com/v2/resize:fill:96:96/1*3SZtM9yhQyfh-dfWk5gGFw.jpeg)](https://blog.devops.dev/?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n[![DevOps.dev](https://miro.medium.com/v2/resize:fill:128:128/1*3SZtM9yhQyfh-dfWk5gGFw.jpeg)](https://blog.devops.dev/?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\nFollow\n\n[**Published in DevOps.dev**](https://blog.devops.dev/?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n[26K followers](https://blog.devops.dev/followers?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n\u00b7 [Last published\u00a014 hours ago](https://blog.devops.dev/building-a-kubernetes-cluster-from-scratch-using-kubeadm-475fa1d471bd?source=post_page---post_publication_info--57e81bbad023-----------------------------------------)\n\n[Devops.dev](http://devops.dev/) is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.\n\nFollow\n\n[Help](https://help.medium.com/hc/en-us?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Status](https://status.medium.com/?source=post_page-----57e81bbad023-----------------------------------------)\n\n[About](https://medium.com/about?autoplay=1&source=post_page-----57e81bbad023-----------------------------------------)\n\n[Careers](https://medium.com/jobs-at-medium/work-at-medium-959d1a85284e?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Press](mailto:pressinquiries@medium.com)\n\n[Blog](https://blog.medium.com/?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Store](https://medium.com/store)\n\n[Privacy](https://policy.medium.com/medium-privacy-policy-f03bf92035c9?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Rules](https://policy.medium.com/medium-rules-30e5502c4eb4?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Terms](https://policy.medium.com/medium-terms-of-service-9db0094a1e0f?source=post_page-----57e81bbad023-----------------------------------------)\n\n[Text to speech](https://speechify.com/medium?source=post_page-----57e81bbad023-----------------------------------------)\n\nreCAPTCHA\n\nRecaptcha requires verification.\n\nprotected by **reCAPTCHA**"
          }
        },
        {
          "url": "https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/",
          "title": "Log retention | Grafana Enterprise Logs documentation",
          "description": "Describes how Loki implements storage retention and retention configuration options.",
          "thumbnail_url": "https://grafana.com/meta-generator/Log+retention.png",
          "original_thumbnail_url": "https://grafana.com/meta-generator/Log+retention.png",
          "favicon_url": "https://you.com/favicon?domain=grafana.com&size=128",
          "snippets": [
            "For Azure Blob Storage, use a management policy with a prefixMatch set to the tenant chunk prefix and the same \u201cexpiration must exceed retention plus delete delay\u201d rule. ... This webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively. ... Laws for data privacy are complex and rapidly changing. During this webinar, we will show how Grafana Loki can help organizations meet these requirements. ... In Part 2 of \"The concise guide to Loki,\" you'll learn about how to properly use labels in our favorite logging database.",
            "Chunks are deleted by the Compactor according to your configured retention, but the Compactor only removes chunk objects: it never deletes the objects that hold cluster state, such as the index or the cluster seed. If you also configure an object store lifecycle policy on the bucket, scope it carefully. A blanket \u201cdelete everything older than N days\u201d rule will eventually remove objects that Loki must keep, which corrupts the store and causes query failures.",
            "Alternatively, the table-manager.retention-period and table-manager.retention-deletes-enabled command line flags can be used. The provided retention period needs to be a duration represented as a string that can be parsed using the Prometheus common model ParseDuration. Examples: 7d, 1w, 168h. ... The retention period must be a multiple of the index and chunks table period, configured in the period_config block. See the Table Manager documentation for more information. ... To avoid querying of data beyond the retention period,max_query_lookback config in limits_config must be set to a value less than or equal to what is set in table_manager.retention_period.",
            "compactor: working_directory: /data/retention compaction_interval: 10m retention_enabled: true retention_delete_delay: 2h retention_delete_worker_count: 150 delete_request_store: gcs schema_config: configs: - from: \"2020-07-31\" index: period: 24h prefix: index_ object_store: gcs schema: v13 store: tsdb storage_config: tsdb_shipper: active_index_directory: /data/index cache_location: /data/index_cache gcs: bucket_name: loki"
          ],
          "contents": {
            "markdown": "![ObservabilityCON 2025](https://a-us.storyblok.com/f/1022730/280x40/b0872b99f9/grafana-logo-observabilitycon-2025-black.svg/m/)\n\nWatch the keynote again and signup for more on-demand sessions.\n\n\n[Watch keynote](https://grafana.com/events/observabilitycon/?plcmt=obscon2025-post-event-banner)![](https://grafana.com/media/events/grafanacon/2025/icon-close-x.svg)\n\n![ObservabilityCON 2025](https://grafana.com/media/events/obscon/2025/grafana-obscon2025-promo-logo-black.svg)\n\n\ud83d\udce2 Registration + agenda now live\nExplore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).\n\n\n[Register now](https://grafana.com/events/observabilitycon/?tech=target&plcmt=top-banner&aud=default)\n\nSearching...\n\nSite search\n\nAsk Grot AI\n\n[Try using ![Grot AI](https://grafana.com/static/img/grot-chat.svg)**Grot AI** for this query ->](https://grafana.com/grot/?chat=&from=/search)\n\nAll\n\nDocs\n\nView all results\n\nNo results.\n\nThere was an error with your request.\n\n> Documentation for automated readers\n>\n> A curated documentation index is available at: https://grafana.com/llms.txt\n>\n> A complete documentation index is available at: https://grafana.com/llms-full.txt\n>\n> These indexes can help with page discovery before fetching individual documents.\n\nThis page is also available in Markdown, which may be easier for automated readers\nand AI tools to parse than HTML. The Markdown version is available at\nhttps://grafana.com/docs/enterprise-logs/latest/manage/storage/retention.md, or by sending\nAccept: text/markdown to https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/. For broader\ndocumentation discovery, the curated index is available at https://grafana.com/llms.txt\nand the complete index is available at https://grafana.com/llms-full.txt.\n\nLog retention\n\n[Documentation](https://grafana.com/docs/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Grafana Enterprise Logs](https://grafana.com/docs/enterprise-logs/latest/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Manage](https://grafana.com/docs/enterprise-logs/latest/manage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)[Storage](https://grafana.com/docs/enterprise-logs/latest/manage/storage/)![breadcrumb arrow](https://grafana.com/static/assets/img/icons/grafana-icon-breadcrumb-arrow-gray.svg)Log retention\n\nEnterprise\n\n# Log retention\n\nRetention in Grafana Loki is achieved through the [Compactor](https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/#compactor).\nBy default the `compactor.retention-enabled` flag is not set, so the logs sent to Loki live forever.\n\n> Note\n>\n> If you have a lifecycle policy configured on the object store, please ensure that it is longer than the retention period.\n\nGranular retention policies to apply retention at per tenant or per stream level are also supported by the Compactor.\n\n> Note\n>\n> The Compactor does not support retention on\n> [legacy index types](https://grafana.com/docs/loki/latest/configure/storage/#index-storage). Please use the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) when using legacy index types.\n> Both the Table manager and legacy index types are deprecated and may be removed in future major versions of Loki.\n\n## Compactor\n\nThe Compactor is responsible for compaction of index files and applying log retention.\n\n> Note\n>\n> Run the Compactor as a singleton (a single instance).\n\nThe Compactor runs compaction and retention on two independent schedules:\n\n- Compaction runs every `compactor.compaction-interval`.\n- Retention runs every `compactor.apply-retention-interval`. If you leave this at its default of `0s`, Loki sets it to the same value as `compactor.compaction-interval`. Whenever the two intervals are equal, Loki extends the retention interval by the smaller of `10m` or half the interval, so that compaction and retention do not run at the same time. For example, with the default `compaction_interval` of `10m`, retention runs every `15m`.\n\nIf the Compactor falls behind on either schedule, it runs the corresponding operation as soon as possible.\nBoth compaction and retention are idempotent, which means once the action has been performed, if the action is performed multiple times, it has no further effect on logs after the first time it is performed. If the Compactor restarts, it continues from where it left off.\n\n> Note\n>\n> Changes to your retention period are not retroactive, that is, they are not applied to logs that have already been ingested.\n\nThe Compactor\u2019s algorithm to apply retention is as follows:\n\n- For each day or table (one table per day with 24h index period):\n  - Compact multiple index files in the table into per-tenant index files. Result of compaction is a single index file per tenant per day.\n  - Traverse the per-tenant index. Use the tenant configuration to identify the chunks that need to be removed.\n  - Remove the references to the matching chunks from the index and add the chunk references to a marker file on disk.\n  - Upload the new modified index files.\n\nChunks are not deleted while applying the retention algorithm on the index. They are deleted asynchronously by a sweeper process\nand this delay can be configured by setting `-compactor.retention-delete-delay`. Marker files are used to keep track of the chunks pending for deletion.\n\nChunks cannot be deleted immediately for the following reasons:\n\n- Index Gateway downloads a copy of the index files to serve queries and refreshes them at a regular interval.\nHaving a delay allows the index gateways to pull the modified index file which would not contain any reference to the chunks marked for deletion.\nWithout the delay, index files (that are stale) on the gateways could refer to already deleted chunks leading to query failures.\n\n- It provides a short window of time in which to cancel chunk deletion in the case of a configuration mistake.\n\n\nBy default, marker files are written to local disk, under `<working_directory>/retention/<object_store_type>_<period_from_date>/markers/`. Marker files should be stored on a persistent disk to ensure that the chunks pending for deletion are processed even if the Compactor process restarts.\n\n> Note\n>\n> Grafana Labs recommends running Compactor as a stateful deployment (StatefulSet when using Kubernetes) with a persistent storage for storing marker files.\n\nAlternatively, you can configure the Compactor to store marker files in object storage instead of local disk, by setting `compactor.deletion-marker-object-store-prefix` (`deletion_marker_object_store_prefix`) to a prefix that ends with `/`. When set, the Compactor writes marker files to the same per-period object store bucket used for chunks, under that prefix. On startup it also copies any existing marker files from local disk to that prefix, then removes the local copies. This lets you run the Compactor without a persistent volume for marker files. Leave this setting empty to keep using local disk.\n\n### Retention Configuration\n\nThis Compactor configuration example activates retention.\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\ncompactor:\n  working_directory: /data/retention\n  compaction_interval: 10m\n  retention_enabled: true\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n  delete_request_store: gcs\nschema_config:\n  configs:\n    - from: \"2020-07-31\"\n      index:\n        period: 24h\n        prefix: index_\n      object_store: gcs\n      schema: v13\n      store: tsdb\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /data/index\n    cache_location: /data/index_cache\n  gcs:\n    bucket_name: loki\n```\n\n> Note\n>\n> Retention is only available if the index period is 24h. Single store TSDB and single store BoltDB require 24h index period.\n\n`retention_enabled` should be set to true. Without this, the Compactor will only compact tables.\n\n`delete_request_store` should be set to configure the store for delete requests. This is required when retention is enabled.\n\n`working_directory` is the directory where marked chunks and temporary tables will be saved.\n\n`compaction_interval` dictates how often compaction is applied. If the Compactor falls behind, compaction occurs as soon as possible.\n\n`apply_retention_interval` dictates how often retention is applied, independently of `compaction_interval`. Refer to [Compactor](https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/#compactor) for how the default value is derived from `compaction_interval`.\n\n`retention_delete_delay` is the delay after which the Compactor will delete marked chunks.\n\n`retention_delete_worker_count` specifies the maximum quantity of goroutine workers instantiated to delete chunks.\n\nA few other options are also relevant when tuning retention:\n\n- `retention_table_timeout` bounds how long the Compactor spends applying retention and processing delete requests on any single table. It defaults to `0s`, meaning no timeout. If the work on a table exceeds this timeout, the Compactor logs a warning and stops early rather than failing, and the remaining work is picked up again on a later run.\n- `retention_backoff_config` controls the retry behavior (minimum and maximum backoff, and number of retries) used by the sweeper when it fails to delete a marked chunk.\n- `delete_request_store_key_prefix` sets the path prefix used to store delete requests within `delete_request_store` (default `index/`).\n- `delete_request_store_db_type` sets the type of database used to store delete requests (default `boltdb`).\n\nRefer to the\n[Configuration reference](https://grafana.com/docs/loki/latest/configure/#compactor) for the full list of `compactor` options and their defaults.\n\n#### Configuring the retention period\n\nRetention period is configured within the\n[`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) configuration section.\n\nThere are two ways of setting retention policies:\n\n- `retention_period` which is applied globally for all log streams.\n- `retention_stream` which is only applied to log streams matching the selector.\n\n> Note\n>\n> Each `retention_stream` rule\u2019s `period` must be at least 24h. Loki rejects configuration with a shorter value, both in the global `retention_stream` list and in any per-tenant override. This minimum does not apply to the `retention_period` setting, either globally or per tenant.\n\nThis example configures global retention that applies to all tenants (unless overridden by configuring per-tenant overrides):\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\n...\nlimits_config:\n  retention_period: 744h\n  retention_stream:\n  - selector: '{namespace=\"dev\"}'\n    priority: 1\n    period: 24h\n  per_tenant_override_config: /etc/overrides.yaml\n...\n```\n\n> Note\n>\n> You can only use label matchers in the `selector` field of a `retention_stream` definition. Arbitrary LogQL expressions are not supported.\n\nPer tenant retention can be defined by configuring\n[runtime overrides](https://grafana.com/docs/loki/latest/configure/#runtime-configuration-file). For example:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\noverrides:\n    \"29\":\n        retention_period: 168h\n        retention_stream:\n        - selector: '{namespace=\"prod\"}'\n          priority: 2\n          period: 336h\n        - selector: '{container=\"loki\"}'\n          priority: 1\n          period: 72h\n    \"30\":\n        retention_stream:\n        - selector: '{container=\"nginx\", level=\"debug\"}'\n          priority: 1\n          period: 24h\n```\n\nRetention period for a given stream is decided based on the first match in this list:\n\n1. If multiple per-tenant `retention_stream` selectors match the stream, retention period with the highest priority is picked.\n2. If multiple global `retention_stream` selectors match the stream, retention period with the highest priority is picked. This value is not considered if per-tenant `retention_stream` is set.\n3. If a per-tenant `retention_period` is specified, it will be applied.\n4. The global `retention_period` will be applied if none of the above match.\n5. If no global `retention_period` is specified, the default value of `0s` is used, which means logs are kept indefinitely.\n\n> Note\n>\n> The larger the priority value, the higher the priority. If two matching `retention_stream` rules have the same priority, Loki applies the shorter (lowest) of the two periods.\n\nStream matching uses the same syntax as Prometheus label matching:\n\n- `=`: Select labels that are exactly equal to the provided string.\n- `!=`: Select labels that are not equal to the provided string.\n- `=~`: Select labels that regex-match the provided string.\n- `!~`: Select labels that do not regex-match the provided string.\n\nThe example configurations defined above will result in the following retention periods:\n\n- For tenant `29`:\n  - Streams that have the namespace label `prod` will have a retention period of `336h` (2 weeks), even if the container label is `loki`, since the priority of the `prod` rule is higher.\n  - Streams that have the container label `loki` but are not in the namespace `prod` will have a `72h` retention period.\n  - For the rest of the streams in this tenant, per-tenant override `retention_period` value of `168h` is applied.\n- For tenant `30`:\n  - Streams that have the label `nginx` and level `debug` will have a retention period of `24h`.\n  - For the rest of the streams in this tenant the global retention period of `744h`, since there is no override specified.\n- All tenants except `29` and `30`:\n  - Streams that have the namespace label `dev` will have a retention period of `24h` hours.\n  - Streams except those with the namespace label `dev` will have the retention period of `744h`.\n\n> Note\n>\n> If you are a Grafana Cloud customer, you can use the [config self-serve API](https://grafana.com/docs/grafana-cloud/send-data/logs/config-self-serve/#configure-retention) to configure your tenant retention.\n\n## Table Manager (deprecated)\n\nRetention through the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) is\nachieved by relying on the object store TTL feature, and will work for both\n[boltdb-shipper](https://grafana.com/docs/loki/latest/operations/storage/boltdb-shipper/) store and chunk/index stores.\n\nIn order to enable the retention support, the Table Manager needs to be\nconfigured to enable deletions and a retention period. Please refer to the\n[`table_manager`](https://grafana.com/docs/loki/latest/configure/#table_manager)\nsection of the Loki configuration reference for all available options.\nAlternatively, the `table-manager.retention-period` and\n`table-manager.retention-deletes-enabled` command line flags can be used. The\nprovided retention period needs to be a duration represented as a string that\ncan be parsed using the Prometheus common model [ParseDuration](https://pkg.go.dev/github.com/prometheus/common/model#ParseDuration). Examples: `7d`, `1w`, `168h`.\n\n> Warning\n>\n> The retention period must be a multiple of the index and chunks table\n> `period`, configured in the\n> [`period_config`](https://grafana.com/docs/loki/latest/configure/#period_config) block.\n> See the\n> [Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/#retention) documentation for\n> more information.\n\n> Note\n>\n> To avoid querying of data beyond the retention period,`max_query_lookback` config in\n> [`limits_config`](https://grafana.com/docs/loki/latest/configure/#limits_config) must be set to a value less than or equal to what is set in `table_manager.retention_period`.\n\nWhen using S3 or GCS, the bucket storing the chunks needs to have the expiry\npolicy set correctly. For more details check\n[S3\u2019s documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html)\nor\n[GCS\u2019s documentation](https://cloud.google.com/storage/docs/managing-lifecycles).\n\nIf you must delete ingested logs, you can delete old chunks in your object store. Note,\nhowever, that this only deletes the log content and keeps the label index\nintact; you will still be able to see related labels but will be unable to\nretrieve the deleted log content.\n\nFor further details on the Table Manager internals, refer to the\n[Table Manager](https://grafana.com/docs/loki/latest/operations/storage/table-manager/) documentation.\n\nAlternatively, if the BoltDB Shipper is configured for the index store, you can enable\n[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) to delete log entries from a specific stream.\n\n## Example Configuration\n\nExample configuration with GCS with a 28 day retention:\n\nYAML![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```yaml\nschema_config:\n  configs:\n    - from: 2018-04-15\n      store: tsdb\n      object_store: gcs\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /loki/index\n    cache_location: /loki/index_cache\n  gcs:\n    bucket_name: GCS_BUCKET_NAME\n\nlimits_config:\n  max_query_lookback: 672h # 28 days\n  retention_period: 672h   # 28 days\n\ncompactor:\n  working_directory: /data/retention\n  delete_request_store: gcs\n  retention_enabled: true\n```\n\n## Object store lifecycle policies\n\nLoki stores chunks and indexes as objects in the configured object store (S3, GCS, Azure Blob Storage, and so on). Chunks are deleted by the [Compactor](https://grafana.com/docs/enterprise-logs/latest/manage/storage/retention/#compactor) according to your configured retention, but the Compactor only removes chunk objects: it never deletes the objects that hold cluster state, such as the index or the cluster seed.\n\nIf you also configure an object store lifecycle policy on the bucket, scope it carefully. A blanket \u201cdelete everything older than N days\u201d rule will eventually remove objects that Loki must keep, which corrupts the store and causes query failures. The note at the top of this page applies here as well: any lifecycle expiration must be longer than your retention period.\n\n> Warning\n>\n> Never apply a lifecycle rule with an empty prefix (one that targets the whole bucket). Always scope lifecycle rules to the per-tenant chunk prefixes described below.\n\n### Bucket object layout\n\nThe following objects are written to the configured bucket. The exact prefixes depend on your `schema_config` and on whether multi-tenancy is enabled, so confirm them against your own configuration before writing a lifecycle rule.\n\nExpand table\n\n| Object or prefix | Content | Safe to expire with a lifecycle policy? |\n| --- | --- | --- |\n| `<tenant_id>/` (for example, `fake/` in single-tenant mode, or your org ID per tenant) | Chunk objects (the log data). | Yes. These are the only objects a lifecycle rule should target. |\n| Index objects (under the index path prefix, `index/` by default, set by `index.path_prefix` in `schema_config`) | TSDB or BoltDB index files, written by ingesters and rewritten by the Compactor. The `index.prefix` value (for example `index_` or `loki_index_`) is the table-name prefix used inside this path, not the path itself, so match a lifecycle rule against the path prefix. | No. Loki manages the index lifecycle internally. Deleting index objects removes references to live chunks and breaks queries. |\n| `loki_cluster_seed.json` | A small file at the bucket root holding the cluster seed used by usage reporting. It is written once and never rotated. | No. A blanket age-based rule will delete it once it ages past the time to live (TTL). |\n| Delete-request store objects (a `delete_requests/` table under `delete_request_store_key_prefix`, `index/` by default, in the bucket configured by `delete_request_store`) | The Compactor\u2019s database of delete requests submitted through the<br>[Log entry deletion](https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/) API, and their processing status. | No. Removing these makes the Compactor lose track of pending delete requests. |\n| Deletion marker objects (only present if you set `deletion_marker_object_store_prefix`; otherwise markers are kept on the Compactor\u2019s local disk and never appear in the bucket) | The Compactor\u2019s record of chunks that are marked for deletion but not yet swept. Written under the configured prefix in the same per-period bucket used for chunks. | No. Removing these makes the Compactor lose track of chunks pending deletion. |\n| Ruler store objects (if the Ruler is backed by the same bucket) | Recording and alerting rule files. | No. These are configuration, not time-series data. |\n\n### Compactor retention versus object store lifecycle policies\n\nCompactor retention and object store lifecycle policies are two independent mechanisms, and they should not be configured in ways that conflict:\n\n- The Compactor is index-aware. It only deletes a chunk after it has removed every reference to that chunk from the index, and it waits `compactor.retention-delete-delay` (default `2h`) before the sweeper deletes the marked chunk, so that index gateways pick up the rewritten index first.\n- An object store lifecycle policy is index-unaware. It deletes objects purely by age and prefix, with no knowledge of whether a chunk is still referenced by the index.\n\nFor most deployments, enabling Compactor retention is sufficient and an object store lifecycle policy is not required. If you do add a lifecycle policy as a cost safety net, set its expiration **longer** than your retention period plus `compactor.retention-delete-delay`, so the Compactor always deletes chunks first and the lifecycle rule only ever catches objects the Compactor has already orphaned.\n\n### Example: Amazon S3 lifecycle policy\n\nThis policy expires only chunk objects under a single tenant prefix. Replace `fake/` with your tenant prefix (use one rule per tenant, or your org ID prefix, when multi-tenancy is enabled). The `Days` value must be larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-chunk-expiration\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"fake/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 395\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the AWS CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\naws s3api put-bucket-lifecycle-configuration \\\n  --bucket YOUR_LOKI_BUCKET \\\n  --lifecycle-configuration file://lifecycle.json\n```\n\n### Example: Google Cloud Storage lifecycle rule\n\nThe equivalent GCS rule expires objects by age and prefix. As with S3, scope `matchesPrefix` to the tenant chunk prefix and keep `age` larger than your retention period plus the delete delay.\n\nJSON![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```json\n{\n  \"rule\": [\\\n    {\\\n      \"action\": {\"type\": \"Delete\"},\\\n      \"condition\": {\\\n        \"age\": 395,\\\n        \"matchesPrefix\": [\"fake/\"]\\\n      }\\\n    }\\\n  ]\n}\n```\n\nApply it with the Google Cloud CLI:\n\nBash![Copy code to clipboard](https://grafana.com/media/images/icons/icon-copy-small-2.svg)Copy\n\n```bash\ngcloud storage buckets update gs://YOUR_LOKI_BUCKET --lifecycle-file=lifecycle.json\n```\n\nFor Azure Blob Storage, use a management policy with a `prefixMatch` set to the tenant chunk prefix and the same \u201cexpiration must exceed retention plus delete delay\u201d rule.\n\n## Was this page helpful?\n\n![\ud83d\udc4d](https://grafana.com/media/images/svg/thumbs-up.svg) Yes![\ud83d\udc4e](https://grafana.com/media/images/svg/thumbs-up.svg) No\n\n[Email docs@grafana.com](mailto:docs@grafana.com) [Help and support](https://grafana.com/help/) [Community](https://grafana.com/community/)\n\n## Related resources from Grafana Labs\n\nAdditional helpful documentation, links, and articles:\n\n[![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Scaling and securing your logs with Grafana Loki](https://grafana.com/static/assets/featured/scaling-and-securing-your-logs-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nScaling and securing your logs with Grafana Loki\\\\\n\\\\\nThis webinar covers the challenges of scaling and securing logs, and how Grafana Cloud Logs powered by Grafana Loki can help, cost-effectively.](https://grafana.com/go/webinar/scaling-and-securing-your-logs-with-grafana-loki/?pg=docs-enterprise-logs-latest-manage-storage-retention&plcmt=related) [![video icon](https://grafana.com/static/assets/img/icons/grafana-icon-card-video.svg)\\\\\n\\\\\nVideo\\\\\n\\\\\n![Managing privacy in log data with Grafana Loki](https://grafana.com/static/assets/featured/managing-privacy-in-log-data-with-grafana-loki_featured.png?w=400)\\\\\n\\\\\nManaging privacy in log data with Grafana Loki\\\\\n\\\\\nLaws for data privacy are complex and rapidly changing. During this webinar, we will show how Grafana Loki can help organizations meet these requirements.](https://grafana.com/go/webinar/managing-log-privacy-with-loki/?pg=docs-enterprise-logs-latest-manage-storage-retention&plcmt=related-2)\n\nAsk Grafana Assistant"
          }
        },
        {
          "url": "https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view",
          "title": "How to Implement Loki Retention Strategies",
          "description": "Configure Grafana Loki retention policies with compactor-based deletion, per-tenant limits, and storage tiering for cost-effective log management.",
          "thumbnail_url": "https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/social-media.png",
          "original_thumbnail_url": "https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/social-media.png",
          "page_age": "2026-01-30T00:00:00",
          "favicon_url": "https://you.com/favicon?domain=oneuptime.com&size=128",
          "snippets": [
            "Managing log retention in Grafana Loki requires understanding how Loki stores data and which components handle deletion.",
            "Chunks marked for deletion wait this duration before actual removal. This gives you time to cancel accidental deletions. Set a default retention period that applies to all tenants: # loki-config.yaml limits_config: # Global retention period - logs older than this are deleted retention_period: 744h # 31 days",
            "Set the lifecycle policy expiration slightly longer than your Loki retention to catch any orphaned objects. Move older logs to cheaper storage tiers before deletion:",
            "Before diving into retention configuration, you need to understand how Loki stores logs. ... Chunks contain the actual log lines, compressed and grouped by stream. The index maps labels and time ranges to specific chunks, enabling efficient queries."
          ],
          "contents": {
            "markdown": "[Skip to main content](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view#main-content)\n\n![](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view)\n\n# How to Implement Loki Retention Strategies\n\nConfigure Grafana Loki retention policies with compactor-based deletion, per-tenant limits, and storage tiering for cost-effective log management.\n\n\n![Nawaz Dhandala](https://avatars.githubusercontent.com/nawazdhandala?s=64)\n\nBy @nawazdhandala\n\n\u2022Jan 30, 2026\u2022Reading time\n10 min read\n\n[Loki](https://oneuptime.com/blog/tag/loki) [Logging](https://oneuptime.com/blog/tag/logging) [Observability](https://oneuptime.com/blog/tag/observability) [Storage](https://oneuptime.com/blog/tag/storage)\n\n## On this page\n\n[Share on X](https://twitter.com/intent/tweet?text=%20How%20to%20Implement%20Loki%20Retention%20Strategies&url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on X\")[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on LinkedIn\")[Discuss on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview&t=%20How%20to%20Implement%20Loki%20Retention%20Strategies \"Discuss on Hacker News\")\n\n* * *\n\n## Introduction [Link to Introduction](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#introduction)\n\nManaging log retention in Grafana Loki requires understanding how Loki stores data and which components handle deletion. Unlike traditional databases where you simply set a TTL, Loki's architecture involves chunks, indexes, and a compactor service that work together to enforce retention policies.\n\nThis guide covers the practical implementation of retention strategies in Loki, from basic configuration to advanced per-tenant overrides. We will walk through working configurations, explain the trade-offs between different approaches, and help you build a retention strategy that balances cost with operational requirements.\n\n## Understanding Loki's Storage Model [Link to Understanding Loki's Storage Model](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#understanding-loki-s-storage-model)\n\nBefore diving into retention configuration, you need to understand how Loki stores logs.\n\n### Chunks and Indexes [Link to Chunks and Indexes](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#chunks-and-indexes)\n\nLoki stores log data in two types of objects:\n\n| Component | Purpose | Storage Backend |\n| --- | --- | --- |\n| Chunks | Compressed log data | Object storage (S3, GCS, filesystem) |\n| Index | Metadata for querying chunks | BoltDB, Cassandra, or object storage (TSDB) |\n\nChunks contain the actual log lines, compressed and grouped by stream. The index maps labels and time ranges to specific chunks, enabling efficient queries.\n\n### The TSDB Index (Recommended) [Link to The TSDB Index (Recommended)](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#the-tsdb-index-recommended)\n\nStarting with Loki 2.8, the TSDB index is the recommended schema. It stores indexes in object storage alongside chunks, simplifying operations and enabling better retention handling.\n\nHere is a basic schema configuration using TSDB:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\n\nschema_config:\n  configs:\n    - from: 2024-01-01\n      store: tsdb\n      object_store: s3\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n```\n\nThe `period: 24h` setting creates daily index tables. This matters for retention because deletion happens at the table level for older index types.\n\n## Compactor-Based Retention [Link to Compactor-Based Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#compactor-based-retention)\n\nThe compactor is Loki's primary mechanism for enforcing retention. It runs as a separate target (or within the single binary) and handles chunk deletion based on configured policies.\n\n### Enabling the Compactor [Link to Enabling the Compactor](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#enabling-the-compactor)\n\nFirst, enable the compactor and configure retention:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\ncompactor:\n  # Working directory for compaction\n  working_directory: /loki/compactor\n\n  # How often the compactor runs\n  compaction_interval: 10m\n\n  # Enable retention enforcement\n  retention_enabled: true\n\n  # Store used for delete requests\n  delete_request_store: s3\n\n  # How often to check for chunks to delete\n  retention_delete_delay: 2h\n\n  # Number of workers for deletion\n  retention_delete_worker_count: 150\n\n  # Delete request cancel period\n  delete_request_cancel_period: 24h\n```\n\nThe `retention_delete_delay` parameter adds a safety buffer. Chunks marked for deletion wait this duration before actual removal. This gives you time to cancel accidental deletions.\n\n### Global Retention Period [Link to Global Retention Period](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#global-retention-period)\n\nSet a default retention period that applies to all tenants:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\nlimits_config:\n  # Global retention period - logs older than this are deleted\n  retention_period: 744h  # 31 days\n```\n\nThe `retention_period` value uses Go duration format. Common values:\n\n| Duration | Days | Use Case |\n| --- | --- | --- |\n| 168h | 7 | Development environments |\n| 720h | 30 | Standard production |\n| 2160h | 90 | Compliance requirements |\n| 8760h | 365 | Long-term audit logs |\n\n### Complete Basic Configuration [Link to Complete Basic Configuration](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#complete-basic-configuration)\n\nHere is a complete configuration enabling compactor retention with S3 storage:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\nauth_enabled: false\n\nserver:\n  http_listen_port: 3100\n  grpc_listen_port: 9096\n\ncommon:\n  path_prefix: /loki\n  storage:\n    s3:\n      endpoint: s3.us-east-1.amazonaws.com\n      bucketnames: loki-chunks\n      region: us-east-1\n      access_key_id: ${AWS_ACCESS_KEY_ID}\n      secret_access_key: ${AWS_SECRET_ACCESS_KEY}\n      s3forcepathstyle: false\n  replication_factor: 1\n  ring:\n    kvstore:\n      store: inmemory\n\nschema_config:\n  configs:\n    - from: 2024-01-01\n      store: tsdb\n      object_store: s3\n      schema: v13\n      index:\n        prefix: loki_index_\n        period: 24h\n\nstorage_config:\n  tsdb_shipper:\n    active_index_directory: /loki/tsdb-index\n    cache_location: /loki/tsdb-cache\n    cache_ttl: 24h\n\ncompactor:\n  working_directory: /loki/compactor\n  compaction_interval: 10m\n  retention_enabled: true\n  delete_request_store: s3\n  retention_delete_delay: 2h\n  retention_delete_worker_count: 150\n\nlimits_config:\n  retention_period: 720h  # 30 days\n  ingestion_rate_mb: 10\n  ingestion_burst_size_mb: 20\n  max_streams_per_user: 10000\n  max_entries_limit_per_query: 5000\n```\n\n## Per-Tenant Retention Overrides [Link to Per-Tenant Retention Overrides](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#per-tenant-retention-overrides)\n\nIn multi-tenant deployments, different teams often have different retention requirements. Loki supports per-tenant overrides through a runtime configuration file.\n\n### Configuring Runtime Overrides [Link to Configuring Runtime Overrides](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#configuring-runtime-overrides)\n\nFirst, tell Loki where to find the overrides file:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\nruntime_config:\n  file: /loki/runtime-config.yaml\n  period: 10s  # How often to reload\n```\n\nThen create the overrides file:\n\n```yaml\nYAMLCopy\n# runtime-config.yaml\noverrides:\n  # Team with short retention needs\n  team-development:\n    retention_period: 168h  # 7 days\n    ingestion_rate_mb: 5\n    max_streams_per_user: 5000\n\n  # Team requiring longer retention for compliance\n  team-security:\n    retention_period: 8760h  # 365 days\n    ingestion_rate_mb: 20\n    max_streams_per_user: 50000\n\n  # Default tenant with standard settings\n  team-platform:\n    retention_period: 720h  # 30 days\n```\n\n### Stream-Based Retention [Link to Stream-Based Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#stream-based-retention)\n\nYou can apply different retention periods based on log stream selectors. This enables fine-grained control within a single tenant.\n\n```yaml\nYAMLCopy\n# runtime-config.yaml\noverrides:\n  production:\n    retention_period: 720h  # Default: 30 days\n    retention_stream:\n      # Keep error logs longer\n      - selector: '{level=\"error\"}'\n        priority: 1\n        period: 2160h  # 90 days\n\n      # Keep audit logs for compliance\n      - selector: '{log_type=\"audit\"}'\n        priority: 2\n        period: 8760h  # 365 days\n\n      # Delete debug logs quickly\n      - selector: '{level=\"debug\"}'\n        priority: 3\n        period: 72h  # 3 days\n\n      # Short retention for high-volume health checks\n      - selector: '{endpoint=\"/health\"}'\n        priority: 4\n        period: 24h  # 1 day\n```\n\nThe `priority` field determines which rule wins when multiple selectors match. Higher priority values take precedence.\n\n### Dynamic Override Reloading [Link to Dynamic Override Reloading](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#dynamic-override-reloading)\n\nThe compactor automatically reloads runtime configuration at the interval specified by `period`. To verify overrides are applied, check the compactor logs:\n\n```bash\nBashCopy\n# View compactor logs for retention activity\nkubectl logs -l app=loki-compactor | grep -i retention\n```\n\nYou should see entries like:\n\n```plaintext\nTextCopy\nlevel=info ts=2026-01-30T10:00:00.000Z caller=compactor.go:450 msg=\"applying retention\" tenant=team-security retention=8760h0m0s\n```\n\n## Table Manager vs Compactor Retention [Link to Table Manager vs Compactor Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#table-manager-vs-compactor-retention)\n\nLoki historically used the Table Manager for retention with BoltDB indexes. Understanding the differences helps when migrating or maintaining older deployments.\n\n### Comparison [Link to Comparison](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#comparison)\n\n| Feature | Table Manager | Compactor |\n| --- | --- | --- |\n| Index Support | Legacy chunk/index stores and BoltDB-shipper | TSDB and BoltDB-shipper |\n| Deletion Granularity | Table-level | Chunk-level |\n| Per-Tenant Overrides | Limited | Full support |\n| Stream Selectors | No | Yes |\n| Status | Deprecated | Recommended |\n\n### Table Manager Configuration (Legacy) [Link to Table Manager Configuration (Legacy)](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#table-manager-configuration-legacy)\n\nIf you are still running BoltDB indexes, here is how Table Manager retention works:\n\n```yaml\nYAMLCopy\n# loki-config.yaml (legacy configuration)\ntable_manager:\n  retention_deletes_enabled: true\n  retention_period: 720h  # 30 days\n\n  # Table creation settings\n  index_tables_provisioning:\n    inactive_read_throughput: 1\n    inactive_write_throughput: 1\n    provisioned_read_throughput: 100\n    provisioned_write_throughput: 100\n\n  chunk_tables_provisioning:\n    inactive_read_throughput: 1\n    inactive_write_throughput: 1\n    provisioned_read_throughput: 100\n    provisioned_write_throughput: 100\n```\n\n### Migration Path [Link to Migration Path](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#migration-path)\n\nTo migrate from Table Manager to Compactor retention:\n\n1. Deploy the new schema alongside the old one\n2. Enable compactor retention for new data\n3. Let Table Manager handle old data until it ages out\n4. Remove Table Manager configuration after full migration\n\n```yaml\nYAMLCopy\n# Schema configuration for migration\nschema_config:\n  configs:\n    # Old schema - Table Manager handles retention\n    - from: 2023-01-01\n      store: boltdb-shipper\n      object_store: s3\n      schema: v12\n      index:\n        prefix: loki_index_\n        period: 24h\n\n    # New schema - Compactor handles retention\n    - from: 2024-06-01\n      store: tsdb\n      object_store: s3\n      schema: v13\n      index:\n        prefix: loki_tsdb_\n        period: 24h\n```\n\n## Deletion Markers and the Deletion API [Link to Deletion Markers and the Deletion API](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#deletion-markers-and-the-deletion-api)\n\nBeyond automatic retention, Loki supports manual deletion through its API. This is useful for removing sensitive data or clearing specific log streams.\n\n### Enabling the Deletion API [Link to Enabling the Deletion API](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#enabling-the-deletion-api)\n\n```yaml\nYAMLCopy\n# loki-config.yaml\ncompactor:\n  retention_enabled: true\n  delete_request_cancel_period: 24h\n  delete_request_store: s3\n\n# runtime-config.yaml\noverrides:\n  tenant-a:\n    deletion_mode: filter-and-delete\n```\n\n### Creating Delete Requests [Link to Creating Delete Requests](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#creating-delete-requests)\n\nUse the deletion API to mark logs for removal:\n\n```bash\nBashCopy\n# Delete all logs matching a selector within a time range\ncurl -X POST \\\n  \"http://loki:3100/loki/api/v1/delete\" \\\n  -H \"Content-Type: application/x-www-form-urlencoded\" \\\n  -d \"query={app=\\\"legacy-service\\\"}\" \\\n  -d \"start=1704067200\" \\\n  -d \"end=1706745600\"\n```\n\nThe timestamps are Unix timestamps in seconds or RFC3339 timestamps. Convert from dates:\n\n```bash\nBashCopy\n# Convert dates to Unix timestamps in seconds\nSTART=$(date -d \"2024-01-01\" +%s)\nEND=$(date -d \"2024-02-01\" +%s)\n\ncurl -X POST \\\n  \"http://loki:3100/loki/api/v1/delete\" \\\n  -d \"query={app=\\\"legacy-service\\\"}\" \\\n  -d \"start=${START}\" \\\n  -d \"end=${END}\"\n```\n\n### Listing and Canceling Delete Requests [Link to Listing and Canceling Delete Requests](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#listing-and-canceling-delete-requests)\n\nView pending deletions:\n\n```bash\nBashCopy\n# List all delete requests\ncurl \"http://loki:3100/loki/api/v1/delete\"\n```\n\nResponse:\n\n```json\nJSONCopy\n[\\\n  {\\\n    \"request_id\": \"abc123\",\\\n    \"start_time\": 1704067200,\\\n    \"end_time\": 1706745600,\\\n    \"query\": \"{app=\\\"legacy-service\\\"}\",\\\n    \"status\": \"received\",\\\n    \"created_at\": 1706800000\\\n  }\\\n]\n```\n\nCancel a pending deletion (within the cancel period):\n\n```bash\nBashCopy\ncurl -X DELETE \\\n  \"http://loki:3100/loki/api/v1/delete?request_id=abc123\"\n```\n\n### Delete Request States [Link to Delete Request States](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#delete-request-states)\n\n| State | Description |\n| --- | --- |\n| received | Request received, waiting for cancel period |\n| building | Cancel period passed, building deletion plan |\n| deleting | Actively deleting chunks |\n| processed | Deletion complete |\n\n## Storage Considerations [Link to Storage Considerations](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#storage-considerations)\n\nRetention configuration directly impacts storage costs and performance. Here are key considerations for production deployments.\n\n### Object Storage Lifecycle Policies [Link to Object Storage Lifecycle Policies](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#object-storage-lifecycle-policies)\n\nCombine Loki retention with cloud provider lifecycle policies for defense in depth:\n\n```json\nJSONCopy\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-chunks-cleanup\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"loki/chunks/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 45\\\n      }\\\n    },\\\n    {\\\n      \"ID\": \"loki-index-cleanup\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"loki/index/\"\\\n      },\\\n      \"Expiration\": {\\\n        \"Days\": 45\\\n      }\\\n    }\\\n  ]\n}\n```\n\nSet the lifecycle policy expiration slightly longer than your Loki retention to catch any orphaned objects.\n\n### Storage Tiering for Cost Optimization [Link to Storage Tiering for Cost Optimization](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#storage-tiering-for-cost-optimization)\n\nMove older logs to cheaper storage tiers before deletion:\n\n```json\nJSONCopy\n{\n  \"Rules\": [\\\n    {\\\n      \"ID\": \"loki-tiering\",\\\n      \"Status\": \"Enabled\",\\\n      \"Filter\": {\\\n        \"Prefix\": \"loki/\"\\\n      },\\\n      \"Transitions\": [\\\n        {\\\n          \"Days\": 7,\\\n          \"StorageClass\": \"STANDARD_IA\"\\\n        },\\\n        {\\\n          \"Days\": 30,\\\n          \"StorageClass\": \"GLACIER_IR\"\\\n        }\\\n      ],\\\n      \"Expiration\": {\\\n        \"Days\": 90\\\n      }\\\n    }\\\n  ]\n}\n```\n\n### Chunk Size and Compression [Link to Chunk Size and Compression](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#chunk-size-and-compression)\n\nOptimize chunk configuration to reduce storage:\n\n```yaml\nYAMLCopy\n# loki-config.yaml\ningester:\n  chunk_encoding: snappy  # Options: gzip, lz4, snappy, zstd\n  chunk_target_size: 1572864  # 1.5MB target\n  chunk_idle_period: 30m\n  chunk_block_size: 262144  # 256KB\n\n  # Flush chunks before they get too old\n  max_chunk_age: 2h\n\n  # Number of chunks to keep in memory\n  chunk_retain_period: 30s\n```\n\nCompression comparison:\n\n| Algorithm | Compression Ratio | CPU Usage | Best For |\n| --- | --- | --- | --- |\n| snappy | Good | Low | General use |\n| lz4 | Good | Low | High throughput |\n| gzip | Better | Medium | Storage constrained |\n| zstd | Best | Medium-High | Cold storage |\n\n## Monitoring Retention [Link to Monitoring Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#monitoring-retention)\n\nTrack retention effectiveness with these metrics.\n\n### Key Compactor Metrics [Link to Key Compactor Metrics](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#key-compactor-metrics)\n\n```yaml\nYAMLCopy\n# Prometheus recording rules for retention monitoring\ngroups:\n  - name: loki-retention\n    rules:\n      # Compactor deletion rate\n      - record: loki:compactor:deleted_lines_per_hour\n        expr: |\n          sum(rate(loki_compactor_deleted_lines[1h])) * 3600\n\n      # Pending deletion requests\n      - record: loki:compactor:pending_deletions\n        expr: |\n          sum(loki_compactor_pending_delete_requests_count)\n\n      # Compaction lag\n      - record: loki:compactor:lag_seconds\n        expr: |\n          time() - max(loki_compactor_apply_retention_last_successful_run_timestamp_seconds)\n```\n\n### Alerting Rules [Link to Alerting Rules](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#alerting-rules)\n\n```yaml\nYAMLCopy\n# Prometheus alerting rules\ngroups:\n  - name: loki-retention-alerts\n    rules:\n      # Alert if compactor is not running\n      - alert: LokiCompactorNotRunning\n        expr: |\n          time() - max(loki_compactor_apply_retention_last_successful_run_timestamp_seconds) > 3600\n        for: 15m\n        labels:\n          severity: warning\n        annotations:\n          summary: \"Loki compactor has not run in over an hour\"\n          description: \"Retention policies are not being enforced\"\n\n      # Alert on high deletion backlog\n      - alert: LokiDeletionBacklog\n        expr: |\n          loki_compactor_pending_delete_requests_count > 100\n        for: 1h\n        labels:\n          severity: warning\n        annotations:\n          summary: \"High number of pending deletion requests\"\n\n      # Alert if old delete requests are not being processed\n      - alert: LokiOldestDeleteRequestStalled\n        expr: |\n          loki_compactor_oldest_pending_delete_request_age_seconds > 86400\n        for: 6h\n        labels:\n          severity: info\n        annotations:\n          summary: \"Old Loki delete requests are still pending\"\n```\n\n### Grafana Dashboard Queries [Link to Grafana Dashboard Queries](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#grafana-dashboard-queries)\n\nCreate a retention monitoring dashboard:\n\n```sql\nSQLCopy\n-- Deleted lines over time\nsum(rate(loki_compactor_deleted_lines[$__rate_interval])) by (user)\n\n-- Pending delete requests\nsum(loki_compactor_pending_delete_requests_count)\n\n-- Delete requests processed over time\nsum(rate(loki_compactor_delete_requests_processed_total[$__rate_interval])) by (user)\n\n-- Oldest pending delete request age\nmax(loki_compactor_oldest_pending_delete_request_age_seconds)\n```\n\n## Production Deployment Patterns [Link to Production Deployment Patterns](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#production-deployment-patterns)\n\n### Single Binary with Retention [Link to Single Binary with Retention](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#single-binary-with-retention)\n\nFor smaller deployments, run everything in one process:\n\n```yaml\nYAMLCopy\n# docker-compose.yml\nservices:\n  loki:\n    image: grafana/loki:3.7.1\n    ports:\n      - \"3100:3100\"\n    volumes:\n      - ./loki-config.yaml:/etc/loki/config.yaml\n      - ./runtime-config.yaml:/loki/runtime-config.yaml\n      - loki-data:/loki\n    command: -config.file=/etc/loki/config.yaml -target=all\n\nvolumes:\n  loki-data:\n```\n\n### Dedicated Compactor in Microservices Mode [Link to Dedicated Compactor in Microservices Mode](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#dedicated-compactor-in-microservices-mode)\n\nFor larger deployments, run the compactor as a dedicated service:\n\n```yaml\nYAMLCopy\n# kubernetes/compactor-deployment.yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: loki-compactor\nspec:\n  replicas: 1  # Only one compactor instance\n  selector:\n    matchLabels:\n      app: loki-compactor\n  template:\n    metadata:\n      labels:\n        app: loki-compactor\n    spec:\n      containers:\n        - name: compactor\n          image: grafana/loki:3.7.1\n          args:\n            - -config.file=/etc/loki/config.yaml\n            - -target=compactor\n          ports:\n            - containerPort: 3100\n              name: http\n          volumeMounts:\n            - name: config\n              mountPath: /etc/loki\n            - name: data\n              mountPath: /loki\n          resources:\n            requests:\n              cpu: 500m\n              memory: 1Gi\n            limits:\n              cpu: 2000m\n              memory: 4Gi\n      volumes:\n        - name: config\n          configMap:\n            name: loki-config\n        - name: data\n          persistentVolumeClaim:\n            claimName: loki-compactor-data\n```\n\nThe compactor must run as a singleton. Running multiple instances causes data corruption.\n\n### Helm Chart Configuration [Link to Helm Chart Configuration](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#helm-chart-configuration)\n\nUsing the official Loki Helm chart:\n\n```yaml\nYAMLCopy\n# values.yaml\nloki:\n  auth_enabled: false\n\n  commonConfig:\n    replication_factor: 1\n\n  storage:\n    type: s3\n    bucketNames:\n      chunks: loki-chunks\n      ruler: loki-ruler\n      admin: loki-admin\n    s3:\n      endpoint: s3.us-east-1.amazonaws.com\n      region: us-east-1\n\n  storage_config:\n    aws:\n      region: us-east-1\n      bucketnames: loki-chunks\n      s3forcepathstyle: false\n\n  schemaConfig:\n    configs:\n      - from: 2024-01-01\n        store: tsdb\n        object_store: s3\n        schema: v13\n        index:\n          prefix: loki_index_\n          period: 24h\n\n  limits_config:\n    retention_period: 720h\n\n  compactor:\n    retention_enabled: true\n    delete_request_store: s3\n    retention_delete_delay: 2h\n    retention_delete_worker_count: 150\n\n  # Runtime configuration for per-tenant overrides\n  runtimeConfig:\n    overrides:\n      team-a:\n        retention_period: 168h\n      team-b:\n        retention_period: 2160h\n\ncompactor:\n  replicas: 1\n  persistence:\n    enabled: true\n    claims:\n      - name: data\n        size: 10Gi\n```\n\n## Troubleshooting Retention Issues [Link to Troubleshooting Retention Issues](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#troubleshooting-retention-issues)\n\n### Logs Not Being Deleted [Link to Logs Not Being Deleted](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#logs-not-being-deleted)\n\nCheck the compactor is running and retention is enabled:\n\n```bash\nBashCopy\n# Check compactor status\ncurl http://loki:3100/compactor/ring\n\n# Check if retention is enabled in config\ncurl http://loki:3100/config | grep -A 10 \"compactor\"\n```\n\nCommon causes:\n\n- `retention_enabled: false` in config\n- Compactor not reaching the chunks (network or permission issues)\n- Delete delay has not passed yet\n\n### Debugging Retention Boundaries [Link to Debugging Retention Boundaries](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#debugging-retention-boundaries)\n\nVerify what the compactor sees as retention boundaries:\n\n```bash\nBashCopy\n# Check compactor logs for retention decisions\nkubectl logs deployment/loki-compactor | grep \"retention boundary\"\n```\n\n### Storage Not Decreasing [Link to Storage Not Decreasing](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#storage-not-decreasing)\n\nIf storage does not decrease after retention runs:\n\n1. Check if lifecycle policies are conflicting\n2. Verify the compactor has write access to delete objects\n3. Look for orphaned chunks from failed compactions\n\n```bash\nBashCopy\n# List objects that should have been deleted\naws s3 ls s3://loki-chunks/chunks/ --recursive | \\\n  awk '$1 < \"2024-01-01\" {print $4}'\n```\n\n### Per-Tenant Overrides Not Applied [Link to Per-Tenant Overrides Not Applied](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#per-tenant-overrides-not-applied)\n\nVerify runtime config is loaded:\n\n```bash\nBashCopy\n# Check runtime config hash\ncurl http://loki:3100/runtime_config?mode=diff\n```\n\nEnsure the tenant ID matches exactly (case-sensitive).\n\n## Best Practices Summary [Link to Best Practices Summary](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#best-practices-summary)\n\n1. **Start with compactor retention** \\- Table Manager is deprecated and has limited functionality.\n\n2. **Set conservative defaults** \\- Start with longer retention and reduce based on observed usage patterns.\n\n3. **Use stream selectors wisely** \\- Apply longer retention only to high-value logs like errors and audit trails.\n\n4. **Monitor compaction lag** \\- A backlog indicates the compactor cannot keep up with ingestion.\n\n5. **Combine with lifecycle policies** \\- Use cloud provider policies as a safety net, not the primary mechanism.\n\n6. **Test deletion in staging** \\- Verify retention policies work correctly before applying to production.\n\n7. **Document retention policies** \\- Teams need to know how long their logs persist for debugging and compliance.\n\n8. **Plan for growth** \\- Ingestion typically grows faster than deletion, so build in headroom.\n\n\n## Conclusion [Link to Conclusion](https://oneuptime.com/blog/post/2026-01-30-loki-retention-strategies/view\\#conclusion)\n\nImplementing effective retention in Loki requires configuring the compactor correctly and understanding how chunks and indexes interact. Start with the compactor-based approach using TSDB indexes for new deployments. Use per-tenant overrides to give teams flexibility while maintaining cost control. Monitor retention effectiveness with dedicated dashboards and alerts to catch issues before storage costs spiral.\n\nThe configurations in this guide provide a solid foundation. Adjust retention periods based on your compliance requirements, debugging needs, and budget constraints. Remember that retention is a balance - too short and you lose valuable debugging context, too long and storage costs become unsustainable.\n\nShare this article\n\n[Share on X](https://twitter.com/intent/tweet?text=%20How%20to%20Implement%20Loki%20Retention%20Strategies&url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on X\")[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview \"Share on LinkedIn\")[Discuss on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Foneuptime.com%2Fblog%2Fpost%2F2026-01-30-loki-retention-strategies%2Fview&t=%20How%20to%20Implement%20Loki%20Retention%20Strategies \"Discuss on Hacker News\")\n\n![Nawaz Dhandala](https://avatars.githubusercontent.com/nawazdhandala)\n\n### Nawaz Dhandala\n\nAuthor\n\n@nawazdhandala \u2022 Jan 30, 2026 \u2022 10 min read\n\nNawaz is building OneUptime with a passion for engineering reliable systems and improving observability.\n\n[GitHub](https://github.com/nawazdhandala)\n\nTechnically validated\u00b7 Jun 11, 2026\nView report\n\n\n### Help improve this post\n\nEvery OneUptime blog post is open source. Found a typo, an inaccuracy, or have a clearer way to explain something? Anyone can contribute \u2014 your edits make this post better for everyone who reads it next.\n\n[Edit this post on GitHub](https://github.com/oneuptime/blog/tree/master/posts/2026-01-30-loki-retention-strategies) [Contributing guidelines](https://github.com/oneuptime/blog)\n\n[Open source](https://github.com/oneuptime/oneuptime)\n\n## OneUptime is the Open-Source   Observability Platform\n\nYour complete reliability stack unified: infrastructure monitoring, incident management, status pages, and APM. Open-source and self-hostable.\n\n\n[Get started for free](https://oneuptime.com/accounts/register) [Request a demo](https://oneuptime.com/enterprise/demo)\n\n[Status Page\\\\\n\\\\\nReal-time status updates](https://oneuptime.com/product/status-page) [Incidents\\\\\n\\\\\nDetect and resolve fast](https://oneuptime.com/product/incident-management) [Monitoring\\\\\n\\\\\nMonitor any resource](https://oneuptime.com/product/monitoring) [On-Call\\\\\n\\\\\nSmart alert routing](https://oneuptime.com/product/on-call) [Maintenance\\\\\n\\\\\nPlan & communicate downtime](https://oneuptime.com/product/scheduled-maintenance) [Logs\\\\\n\\\\\nFastest log ingest and search](https://oneuptime.com/product/logs-management) [Metrics\\\\\n\\\\\nPerformance insights](https://oneuptime.com/product/metrics) [Traces\\\\\n\\\\\nEnd-to-end distributed tracing](https://oneuptime.com/product/traces) [Exceptions\\\\\n\\\\\nCatch and fix bugs early](https://oneuptime.com/product/exceptions) [Workflows\\\\\n\\\\\nAutomate any process](https://oneuptime.com/product/workflows) [Dashboards\\\\\n\\\\\nVisualize all your data](https://oneuptime.com/product/dashboards) [Kubernetes\\\\\n\\\\\nMonitor K8s clusters](https://oneuptime.com/product/kubernetes) [Profiles\\\\\n\\\\\nCPU & memory profiling](https://oneuptime.com/product/profiles)\n\n[AI\\\\\n\\\\\nDetect, diagnose, and resolve incidents with AI-powered root cause analysis and code fixes.](https://oneuptime.com/product/ai-agent)\n\n## Validation report\n\nTechnically reviewed for accuracy \u2022Jun 11, 2026\n\nLoading validation report\u2026\n\n\nAutomated technical review\nClose"
          }
        },
        {
          "url": "https://community.grafana.com/t/configuring-retention-for-loki-in-a-grafana-cloud-stack/140741",
          "title": "Configuring retention for Loki in a Grafana Cloud stack - ...",
          "description": "I just created a free tier Grafana Cloud stack to start working with collecting and analyzing logs and metrics. When pushing data to the Loki-instance I get by default, it drop all logs older tha a week. Is there any way to change that? Do I need to run my own Loki-instance somewhere to enable ...",
          "thumbnail_url": "https://us1.discourse-cdn.com/grafana/original/2X/a/a7f38198d3aa26d70bae13c3379e5b93a010e7d7.png",
          "original_thumbnail_url": "https://us1.discourse-cdn.com/grafana/original/2X/a/a7f38198d3aa26d70bae13c3379e5b93a010e7d7.png",
          "page_age": "2025-01-20T08:53:41",
          "favicon_url": "https://you.com/favicon?domain=community.grafana.com&size=128",
          "snippets": [
            "I just created a free tier Grafana Cloud stack to start working with collecting and analyzing logs and metrics. When pushing data to the Loki-instance I get by default, it drop all logs older tha a week. Is there any way to change that? Do I need to run my own Loki-instance somewhere to enable longer retention than 7 days?",
            "I just created a free tier Grafana Cloud stack to start working with collecting and analyzing logs and metrics. When pushing data to the Loki-instance I get by default, it drop all logs older tha a week. Is there any way\u2026"
          ]
        },
        {
          "url": "https://medium.com/@aditya.hilman_10961/enabling-log-retention-in-loki-with-compactor-fe3de2002b47",
          "title": "Enabling Log Retention in Loki with Compactor | by Aditya Hilman ...",
          "description": "Efficient log management is essential as Kubernetes workloads grow in complexity. In a previous guide, we explored how to centralize logs\u2026",
          "thumbnail_url": "https://miro.medium.com/v2/resize:fit:538/1*TDFVSRecndbaVz1nhu3HuQ.png",
          "original_thumbnail_url": "https://miro.medium.com/v2/resize:fit:538/1*TDFVSRecndbaVz1nhu3HuQ.png",
          "page_age": "2024-12-03T10:18:49",
          "favicon_url": "https://you.com/favicon?domain=medium.com&size=128",
          "snippets": [
            "Enabling Log Retention in Loki with Compactor Efficient log management is essential as Kubernetes workloads grow in complexity. In a previous guide, we explored how to centralize logs using Loki \u2026",
            "In a previous guide, we explored how to centralize logs using Loki, Promtail, and Grafana. But once logs start accumulating, controlling their retention becomes critical to manage storage and maintain performance. This article will focus on configuring log retention in Loki using the Compactor, a core component designed to manage retention policies effectively. The Compactor in Loki is responsible for managing and enforcing retention periods, cleaning up old logs, and optimizing stored data.",
            "If old chunks are not deleted, double-check your configuration for errors and ensure the compactor is running without issues. Log retention is a critical aspect of managing a scalable and efficient log storage system. By enabling Loki\u2019s Compactor and setting retention policies, you can control log storage while ensuring compliance and performance.",
            "limits_config: retention_period: 30d compactor: working_directory: /tmp/loki/retention retention_enabled: true retention_delete_delay: 2h delete_request_store: filesystem \u00b7 limits_config.retention_period: 30dSets the global retention period to 30 days. Logs older than 30 days will be marked for deletion by the compactor."
          ],
          "contents": {
            "markdown": "[Sitemap](https://medium.com/sitemap/sitemap.xml)\n\n[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40aditya.hilman_10961%2Fenabling-log-retention-in-loki-with-compactor-fe3de2002b47&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n[Medium Logo](https://medium.com/?source=---top_nav_layout_nav-------------------------------------------)\n\nGet app\n\n[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav--------------------)\n\n[Search](https://medium.com/search?source=---top_nav_layout_nav-------------------------------------------)\n\nSign up\n\n[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40aditya.hilman_10961%2Fenabling-log-retention-in-loki-with-compactor-fe3de2002b47&source=post_page---top_nav_layout_nav-----------------------global_nav--------------------)\n\n![Unknown user](https://miro.medium.com/v2/resize:fill:32:32/1*dmbNkD5D-u45r44go_cf0g.png)\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:40:40/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_sidebar--fe3de2002b47-----------------b00d17378766------------------------)\n\n## Aditya Hilman\n\nFollow writer\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:40:40/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_sidebar--fe3de2002b47-----------------b00d17378766------------------------)\n\n## Aditya Hilman\n\nFollow writer\n\n[DevOps](https://medium.com/tag/devops?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Logging](https://medium.com/tag/logging?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Monitoring](https://medium.com/tag/monitoring?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Kubernetes](https://medium.com/tag/kubernetes?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n[Loki](https://medium.com/tag/loki?source=post_page---header_tags--fe3de2002b47-----------------------------------------)\n\n# Enabling Log Retention in Loki with Compactor\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:32:32/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---byline--fe3de2002b47-----------------------------------------)\n\n[Aditya Hilman](https://medium.com/@aditya.hilman_10961?source=post_page---byline--fe3de2002b47-----------------------------------------)\n\nFollow\n\n2 min read\n\n\u00b7\n\nDec 3, 2024\n\n15\n\n1\n\n[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Dfe3de2002b47&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40aditya.hilman_10961%2Fenabling-log-retention-in-loki-with-compactor-fe3de2002b47&source=---header_actions--fe3de2002b47---------------------post_audio_button--------------------)\n\nShare\n\n![](https://miro.medium.com/v2/resize:fit:538/1*TDFVSRecndbaVz1nhu3HuQ.png)\n\nEfficient log management is essential as Kubernetes workloads grow in complexity. In a [previous guide](https://medium.com/@aditya.hilman_10961/centralizing-kubernetes-logs-with-promtail-loki-and-grafana-a-step-by-step-guide-cafffb59a13e), we explored how to centralize logs using Loki, Promtail, and Grafana. But once logs start accumulating, controlling their retention becomes critical to manage storage and maintain performance.\n\nThis article will focus on configuring **log retention in Loki** using the **Compactor**, a core component designed to manage retention policies effectively.\n\n## Understanding Loki\u2019s Compactor\n\nThe **Compactor** in Loki is responsible for managing and enforcing retention periods, cleaning up old logs, and optimizing stored data. By enabling and configuring the compactor, you can automate log deletion and maintain a sustainable log storage strategy.\n\n## Configuring Log Retention in Loki\n\nEnsure the compactor is enabled in your `/etc/loki/config.yml` file:\n\n```\nlimits_config:\n retention_period: 30d\n\ncompactor:\n working_directory: /tmp/loki/retention\n retention_enabled: true\n retention_delete_delay: 2h\n delete_request_store: filesystem\n```\n\n`limits_config.retention_period: 30d`Sets the global retention period to 30 days. Logs older than 30 days will be marked for deletion by the compactor.\n\n`compactor.working_directory: /tmp/loki/retention`Specifies the directory where the compactor stores its state and temporary files while processing.\n\n## Get Aditya Hilman\u2019s stories in\u00a0your\u00a0inbox\n\nJoin Medium for free to get updates from\u00a0this\u00a0writer.\n\nSubscribe\n\nSubscribe\n\nRemember me for faster sign in\n\n`compactor.retention_enabled: true`Enables the retention policy enforcement in Loki. Without this, the compactor will not delete old logs.\n\n`compactor.retention_delete_delay: 2h`Introduces a delay of 2 hours before permanently deleting logs. This ensures a buffer in case of accidental deletion or misconfigurations.\n\n`compactor.delete_request_store: filesystem`Specifies the storage backend for deletion requests. `filesystem` is used here to store delete requests locally on disk. You can switch to other storage backends (e.g., `s3`, `gcs`) if needed.\n\n## Verify Retention Policy\n\nTo confirm that the retention policy is working, you can inspect the directory where Loki stores its chunks. If you are using the filesystem as your `shared_store`, the chunks are stored in `/tmp/loki/chunks`.\n\n**Check the Directory Contents**:\n\nAfter the compactor runs, check for log chunks in the directory:\n\n```\nls -lh /tmp/loki/chunks\n```\n\n**Verify Cleanup**:\n\nEnsure that files corresponding to logs older than the defined retention period (`720h` in this case) are no longer present.\n\nIf old chunks are not deleted, double-check your configuration for errors and ensure the `compactor` is running without issues.\n\n## Conclusion\n\nLog retention is a critical aspect of managing a scalable and efficient log storage system. By enabling Loki\u2019s Compactor and setting retention policies, you can control log storage while ensuring compliance and performance.\n\nIf you\u2019re new to Loki, be sure to check out [step-by-step guide](https://medium.com/@aditya.hilman_10961/centralizing-kubernetes-logs-with-promtail-loki-and-grafana-a-step-by-step-guide-cafffb59a13e) to set up your centralized logging stack.\n\n[DevOps](https://medium.com/tag/devops?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Logging](https://medium.com/tag/logging?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Monitoring](https://medium.com/tag/monitoring?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Kubernetes](https://medium.com/tag/kubernetes?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[Loki](https://medium.com/tag/loki?source=post_page---footer_tags--fe3de2002b47-----------------------------------------)\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:48:48/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\n[![Aditya Hilman](https://miro.medium.com/v2/resize:fill:64:64/1*5pWd-yCClf4qZygBFaEyUA.jpeg)](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\nFollow\n\n[**Written by Aditya Hilman**](https://medium.com/@aditya.hilman_10961?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\n[12 followers](https://medium.com/@aditya.hilman_10961/followers?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\n\u00b7 [2 following](https://medium.com/@aditya.hilman_10961/following?source=post_page---post_author_info--fe3de2002b47-----------------------------------------)\n\nFollow\n\n[Help](https://help.medium.com/hc/en-us?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Status](https://status.medium.com/?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[About](https://medium.com/about?autoplay=1&source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Careers](https://medium.com/jobs-at-medium/work-at-medium-959d1a85284e?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Press](mailto:pressinquiries@medium.com)\n\n[Blog](https://blog.medium.com/?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Store](https://medium.com/store)\n\n[Privacy](https://policy.medium.com/medium-privacy-policy-f03bf92035c9?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Rules](https://policy.medium.com/medium-rules-30e5502c4eb4?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Terms](https://policy.medium.com/medium-terms-of-service-9db0094a1e0f?source=post_page-----fe3de2002b47-----------------------------------------)\n\n[Text to speech](https://speechify.com/medium?source=post_page-----fe3de2002b47-----------------------------------------)"
          }
        },
        {
          "url": "https://github.com/grafana/loki/issues/8357",
          "title": "Logs retention doesn't work \u00b7 Issue #8357 \u00b7 grafana/loki",
          "description": "Describe the bug Using a custom configuration I think the logs should be deleted after 1h, but they are always available To Reproduce I used the following configuration values for loki helm chart l...",
          "thumbnail_url": "https://opengraph.githubassets.com/1430d0bf007ff2bd9850045648c8d44c1eaf3a7ab55d92ed04f5b927fb27f653/grafana/loki/issues/8357",
          "original_thumbnail_url": "https://opengraph.githubassets.com/1430d0bf007ff2bd9850045648c8d44c1eaf3a7ab55d92ed04f5b927fb27f653/grafana/loki/issues/8357",
          "page_age": "2023-01-31T17:41:57",
          "favicon_url": "https://you.com/favicon?domain=github.com&size=128",
          "snippets": [
            "Describe the bug Using a custom configuration I think the logs should be deleted after 1h, but they are always available To Reproduce I used the following configuration values for loki helm chart loki: config: limits_config: retention_pe...",
            "auth_enabled: false chunk_store_config: max_look_back_period: 0s compactor: retention_delete_delay: 1h retention_enabled: true shared_store: filesystem working_directory: /data/loki/boltdb-shipper-compactor ingester: chunk_block_size: 262144 chunk_idle_period: 3m chunk_retain_period: 1m lifecycler: ring: replication_factor: 1 max_transfer_retries: 0 wal: dir: /data/loki/wal limits_config: enforce_metric_name: false max_entries_limit_per_query: 5000 reject_old_samples: true reject_old_samples_max_age: 168h retention_period: 1h memberlist: join_members: - 'loki-memberlist' schema_config: configs"
          ],
          "contents": {
            "markdown": "[Skip to content](https://github.com/grafana/loki/issues/8357#start-of-content)\n\nYou signed in with another tab or window. [Reload](https://github.com/grafana/loki/issues/8357) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/grafana/loki/issues/8357) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/grafana/loki/issues/8357) to refresh your session.Dismiss alert\n\n{{ message }}\n\n[grafana](https://github.com/grafana)/ **[loki](https://github.com/grafana/loki)** Public\n\n- [Notifications](https://github.com/login?return_to=%2Fgrafana%2Floki) You must be signed in to change notification settings\n- [Fork\\\\\n4.1k](https://github.com/login?return_to=%2Fgrafana%2Floki)\n- [Star\\\\\n28.9k](https://github.com/login?return_to=%2Fgrafana%2Floki)\n\n\n# Logs retention doesn't work\\#8357\n\n[New issue](https://github.com/login?return_to=https://github.com/grafana/loki/issues/8357)\n\nCopy link\n\n[New issue](https://github.com/login?return_to=https://github.com/grafana/loki/issues/8357)\n\nCopy link\n\nClosed\n\nClosed\n\n[Logs retention doesn't work](https://github.com/grafana/loki/issues/8357#top)#8357\n\nCopy link\n\n## Description\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4&size=48)](https://github.com/fpaparoni)\n\n[fpaparoni](https://github.com/fpaparoni)\n\nopened [on Jan 31, 2023on Jan 31, 2023](https://github.com/grafana/loki/issues/8357#issue-1564748865)\n\nIssue body actions\n\n**Describe the bug**\n\nUsing a custom configuration I think the logs should be deleted after 1h, but they are always available\n\n**To Reproduce**\n\nI used the following configuration values for loki helm chart\n\n```\nloki:\n  config:\n    limits_config:\n      retention_period: 1h\n    compactor:\n      retention_enabled: true\n      retention_delete_delay: 1h\n    table_manager:\n      retention_deletes_enabled: true\n      retention_period: 1h\n```\n\nlaunched the creation using the following command\n\n`helm install loki grafana/loki-stack --values loki-stack-values.yaml -n loki --create-namespace`\n\nand if I enter into the loki pod I can see the following configuration from /etc/loki/loki.yaml\n\n```\nauth_enabled: false\nchunk_store_config:\n  max_look_back_period: 0s\ncompactor:\n  retention_delete_delay: 1h\n  retention_enabled: true\n  shared_store: filesystem\n  working_directory: /data/loki/boltdb-shipper-compactor\ningester:\n  chunk_block_size: 262144\n  chunk_idle_period: 3m\n  chunk_retain_period: 1m\n  lifecycler:\n    ring:\n      replication_factor: 1\n  max_transfer_retries: 0\n  wal:\n    dir: /data/loki/wal\nlimits_config:\n  enforce_metric_name: false\n  max_entries_limit_per_query: 5000\n  reject_old_samples: true\n  reject_old_samples_max_age: 168h\n  retention_period: 1h\nmemberlist:\n  join_members:\n  - 'loki-memberlist'\nschema_config:\n  configs:\n  - from: \"2020-10-24\"\n    index:\n      period: 24h\n      prefix: index_\n    object_store: filesystem\n    schema: v11\n    store: boltdb-shipper\nserver:\n  grpc_listen_port: 9095\n  http_listen_port: 3100\nstorage_config:\n  boltdb_shipper:\n    active_index_directory: /data/loki/boltdb-shipper-active\n    cache_location: /data/loki/boltdb-shipper-cache\n    cache_ttl: 24h\n    shared_store: filesystem\n  filesystem:\n    directory: /data/loki/chunks\ntable_manager:\n  retention_deletes_enabled: true\n  retention_period: 1h\n```\n\n**Expected behavior**\n\nAfter one hour logs should be deleted, but the retention doesn't work (of course there is something in the configuration that is wrong)\n\n**Environment:**\n\n- Infrastructure: Kubernetes\n- Deployment tool: helm\n\n## Activity\n\n### danielrosa-zh commented on Jan 31, 2023on Jan 31, 2023\n\n[![@danielrosa-zh](https://avatars.githubusercontent.com/u/92591588?u=338bb817890c8036cd7fb7b373b0779c4ff10127&v=4&size=48)](https://github.com/danielrosa-zh)\n\n[danielrosa-zh](https://github.com/danielrosa-zh)\n\n[on Jan 31, 2023on Jan 31, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1411281458)\n\nMore actions\n\nHi [@fpaparoni](https://github.com/fpaparoni)\n\nLooks like the minimum retention period is 24h regarding the documentation.\n\n### fpaparoni commented on Feb 1, 2023on Feb 1, 2023\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4&size=48)](https://github.com/fpaparoni)\n\n[fpaparoni](https://github.com/fpaparoni)\n\n[on Feb 1, 2023on Feb 1, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1411656192)\n\nAuthor\n\nMore actions\n\nHi [@danielrosa-zh](https://github.com/danielrosa-zh) ,\n\nI didn't see it, I'll try and wait one day to see if it works :)\n\n### aleksandr-seleznyov commented on Mar 21, 2023on Mar 21, 2023\n\n[![@aleksandr-seleznyov](https://avatars.githubusercontent.com/u/9655244?u=64370cc509f33f68838f727d59fce2e86866f744&v=4&size=48)](https://github.com/aleksandr-seleznyov)\n\n[aleksandr-seleznyov](https://github.com/aleksandr-seleznyov)\n\n[on Mar 21, 2023on Mar 21, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1478362759)\n\nMore actions\n\nHello [@fpaparoni](https://github.com/fpaparoni) ,\n\nIt worked?\n\n### fpaparoni commented on Mar 21, 2023on Mar 21, 2023\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4&size=48)](https://github.com/fpaparoni)\n\n[fpaparoni](https://github.com/fpaparoni)\n\n[on Mar 21, 2023on Mar 21, 2023](https://github.com/grafana/loki/issues/8357#issuecomment-1478562202)\n\nAuthor\n\nMore actions\n\nyes it worked, thanks for the support\n\n\ud83d\udc4dReact with \ud83d\udc4d1Reacted by neonvignesh\n\n[![](https://avatars.githubusercontent.com/u/4602065?s=64&u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4)fpaparoni](https://github.com/fpaparoni)\n\nclosed this as [completed](https://github.com/grafana/loki/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted) [on Mar 21, 2023on Mar 21, 2023](https://github.com/grafana/loki/issues/8357#event-8810133030)\n\n[Sign up for free](https://github.com/signup?return_to=https://github.com/grafana/loki/issues/8357)**to join this conversation on GitHub.** Already have an account? [Sign in to comment](https://github.com/login?return_to=https://github.com/grafana/loki/issues/8357)\n\n## Metadata\n\n## Metadata\n\n### Assignees\n\nNo one assigned\n\n### Labels\n\nNo labels\n\nNo labels\n\n### Type\n\nNo type\n\n### Projects\n\nNo projects\n\n### Milestone\n\nNo milestone\n\n### Relationships\n\nNone yet\n\n### Development\n\nNo branches or pull requests\n\n### Participants\n\n[![@fpaparoni](https://avatars.githubusercontent.com/u/4602065?s=64&u=c7cc4aa7d4f6f3b26010e2edddb43450f259a42f&v=4)](https://github.com/fpaparoni)[![@aleksandr-seleznyov](https://avatars.githubusercontent.com/u/9655244?s=64&u=64370cc509f33f68838f727d59fce2e86866f744&v=4)](https://github.com/aleksandr-seleznyov)[![@danielrosa-zh](https://avatars.githubusercontent.com/u/92591588?s=64&u=338bb817890c8036cd7fb7b373b0779c4ff10127&v=4)](https://github.com/danielrosa-zh)\n\n## Issue actions\n\n- ![](https://github.githubassets.com/assets/github-copilot-app-light-15ad5534265eeacd.svg)Open in GitHub Copilot app\n\nYou can\u2019t perform that action at this time."
          }
        }
      ]
    },
    "metadata": {
      "query": "In Loki, the log aggregation system from Grafana Labs, which configuration block does retention_enabled have to be set in for old log data to actually be deleted?",
      "search_uuid": "86875943-0906-45af-876e-1550450736ab",
      "latency": 10.901536450954154
    }
  },
  "credits_reported": null,
  "tokens_reported": null,
  "shared_http_call": true
}