Loki log retention per tenant and per stream

Loki keeps logs indefinitely until retention is enabled in the compactor. This page explains how to set global, per tenant and per stream retention, how often it runs, and how to confirm data is removed.

On this page

Why Loki log retention per tenant and per stream needs a deliberate design

Self-hosted Loki keeps logs indefinitely unless you configure otherwise, so storage grows quietly until someone asks why the bucket is full. Retention is applied by the compactor and stays off until you set compactor.retention-enabled explicitly. Turning it on is the first decision, and it should be made in the same change that defines what Loki keeps and for how long. Because the default is to keep everything, a cluster that was installed without a retention plan is already holding data that no one has classified.

Retention can be set three ways: globally for the whole cluster, per tenant when auth_enabled separates teams, customers or environments, and per stream using a label selector for cases such as a noisy debug stream or an audit stream that must live longer. Each stream rule must keep data for at least 24 hours, so short-lived debugging retention needs a different plan than a per-stream rule. Start by listing which tenants have different legal, contractual or operational needs, then list the streams that differ from those defaults. Keep the number of overrides small, because each one is another setting to review when requirements change.

Retention runs inside the compactor, and the Loki documentation describes the compactor as a singleton. With the default compaction interval of 10 minutes, retention runs every 15 minutes, so removal is not instantaneous and a change to a rule will not show results immediately. Confirm that exactly one compactor is running before you rely on deletion, and check the Loki retention documentation for the current schedule and settings in your release, since these values affect how long you should wait before verifying removal.

Which retention scope fits which requirement

This table compares the three retention scopes Loki's compactor applies: global, per tenant and per stream selector. Read each row as a question you need to answer about where a setting lives, what it reaches and when it is the right tool. The main takeaway is that a stream rule can only shorten or lengthen retention for matching streams with a 24 hour minimum, so it complements rather than replaces a tenant default.

ScopeWhere it is configuredWhat it applies toWhen it fits
Global retentionCompactor retention settings with retention enabled at the cluster levelEvery tenant and every stream in the cluster unless a narrower rule overrides itA single default period for all data when tenants share one policy
Per tenant overrideRuntime limits configuration keyed by tenant ID, set through the X-Scope-OrgID tenantAll streams belonging to that tenant, applied by the compactorDifferent teams, customers or environments in one cluster need different periods
Per stream selector ruleRetention rules inside a tenant's limits, each matching streams by label selectorOnly streams whose labels match the selector, with a minimum of 24 hours per ruleAudit or security streams need longer keeping, or noisy debug streams need shorter keeping
Stream rule minimumEach stream selector rule's period valueMust be at least 24 hours; shorter values are not a documented optionConfirm the exact behavior with the current retention docs before setting short periods
Multi-tenant requirementTenant identification enabled through auth settings and the tenant headerTenant-scoped retention only works when tenants are actually separated by IDSingle-tenant clusters rely on the global setting alone
Rule precedenceCheck the retention docs for how overlapping global, tenant and stream rules resolveStreams matching a stream rule within a tenant with its own overrideTest overlapping selectors in a non-production cluster before relying on them
Compliance-driven periodsDocumented per-tenant or per-stream periods set from your retention scheduleOnly the streams you label and scope, so unlabeled data follows the defaultWrite the required period into the policy first, then map it to a scope

How the compactor applies retention and when deletion happens

Retention in Loki is enforced by the compactor, not by the ingesters or queriers, so the compactor is the component to plan and verify. Retention is off by default. The compactor.retention-enabled setting is not set out of the box, which means logs are kept indefinitely until you enable it and define rules. Before you go live, confirm that the setting is on in the configuration that actually runs in production, because a deployment that looks correct in a values file can still be keeping everything if the flag was never applied to the running compactor.

The compactor must run as a singleton. Two compactors working on the same index can conflict, so treat a second replica as a misconfiguration rather than as extra capacity. With the default compaction interval of 10 minutes, the retention cycle runs every 15 minutes. Those figures come from the Loki retention documentation, and they set the earliest point at which an expired chunk can be removed, not the moment it expires. For a compliance statement such as "logs are deleted after 90 days," the realistic answer is that deletion happens on the first retention pass after the limit is reached, so the time between expiry and removal is bounded by that cycle plus any processing delay on your storage.

Confirm this timing in your own version before you rely on it for compliance. Check the compactor logs after enabling retention on a test tenant with a short period, then query for data older than the limit and confirm it no longer returns results. Record the version, the compaction and retention settings, and the test result as evidence. Review the Loki log retention documentation for your release, since retention behavior and its settings are the kind of detail that changes between versions.

How to enable and configure Loki retention step by step

This sequence turns on compactor-driven retention, sets a global period, layers per-tenant and per-stream rules on top, and confirms through logs and queries that the intended data is being removed.

  1. Confirm the deployment mode and a single compactor

    Check which deployment mode you run (monolithic, simple scalable or microservices) and confirm that exactly one compactor process is active across the cluster. In the monolithic mode this is the single binary; in the other modes, identify the compactor target and verify it is not scaled above one replica. Loki's retention documentation expects the compactor to run as a singleton, and the default compaction interval of 10m means retention runs every 15m. You are done when your deployment manifest or process list shows one compactor and no second instance is writing to the same object store path.

  2. Enable retention in the compactor configuration

    In the compactor block of your Loki configuration, set retention_enabled to true, and set the working directory and shared storage settings the compactor already uses for index compaction. Retention is disabled by default, so without this key logs are kept indefinitely. Apply the change through your configuration management or Helm values. You are done when the rendered configuration file shows retention_enabled set to true and the compactor starts without configuration errors in its logs.

  3. Set the global retention period in limits

    Under limits_config, set retention_period to the period you have agreed with your data owners and compliance team. This value applies to every tenant unless an override replaces it. Confirm the chosen period against your legal, security and audit requirements before you apply it, because removal is applied by the compactor and is not reversible for data already deleted. You are done when the effective limits endpoint or configuration review shows the intended global value for a tenant that has no override.

  4. Add per-tenant overrides for multi-tenant clusters

    If auth_enabled is true and tenants are identified by the X-Scope-OrgID header, add a runtime overrides file that sets retention_period for each tenant that needs a different period. Keep the list of tenant IDs in sync with the teams or customers you serve, and document who approved each period. Retention rules are applied per tenant, so a tenant with no override inherits the global value. You are done when a query for each override tenant's limits returns the expected period and a tenant without an override returns the global value.

  5. Define stream selector rules for specific logs

    Where particular log streams need a different lifetime, add retention_stream entries with a stream selector (for example, a label match on namespace or app) and a period. Each stream rule must be at least 24 hours. Check that each selector uses labels that exist in your streams, because a selector that matches nothing has no effect and fails silently. You are done when you have run the selector as a LogQL label matcher in Grafana Explore and the returned streams are the ones you intended to target.

  6. Restart Loki and confirm the compactor applies retention

    Restart or roll the compactor and any component that reads these limits, so the new configuration and overrides load. Then watch the compactor logs over at least one compaction cycle. With the default 10m compaction interval, retention runs every 15m, so allow for that window before judging the result. You are done when the logs show retention activity for the expected tenants and the compactor reports no errors reading the overrides or stream rules.

  7. Verify that expired data is actually removed

    Pick a test stream or tenant with a short illustrative period in a non-production environment, then query for log lines older than the period after several retention cycles. Confirm the expected results are gone while data inside the window remains. Also check the object store to see whether chunks for old time ranges are being deleted, and compare that with any lifecycle policy you have set, which must be longer than the retention period. You are done when old lines return no results in queries and the storage footprint for that tenant declines as expected.

How retention decisions flow from config to object storage

Retention starts in the Loki configuration, where global, per-tenant and per-stream selector rules are defined, and the compactor is the only component that acts on them. The compactor removes chunks and index entries from the object store on its own schedule, which is why it must run as a singleton. The object store lifecycle policy sits outside Loki as a longer-lived backstop, so check that its expiry is set beyond the Loki retention period.

Retention rules flow from Loki config through the compactor into the client's object storage.

How object store lifecycle policies interact with Loki retention

If you configure a lifecycle policy on the bucket or container that holds Loki chunks, that policy must be longer than the Loki retention period. The Loki retention documentation states this requirement. The reason is simple: the object store deletes objects on its own clock, and if it removes chunks while Loki still has index entries pointing at them, queries return gaps and the compactor may keep stale references. Loki's compactor is the component that should decide when data leaves the system, so the bucket rule should act only as a backstop that never fires before the compactor has finished its work.

Per-tenant and per-stream retention makes this harder than it looks. Retention can be set globally, per tenant and per stream selector, and each stream rule has a minimum of 24 hours. A single bucket usually holds data for every tenant, so the lifecycle rule has to cover the longest retention period in use anywhere in the cluster, including any stream rule that keeps one selector longer than its tenant default. Before you set the lifecycle rule, export the effective retention_period values from your limits_config and the retention_stream entries for each tenant, then confirm which one is the maximum. Revisit that list whenever a team asks for a longer period, because a new stream rule can silently exceed the bucket rule you set months earlier.

Set the lifecycle expiration to the longest retention in use, plus a margin you choose and document, and record that value next to your retention configuration so both change together. For the bucket specifics, including how the rule is written for your provider and how IAM permissions affect who can change it, see the Loki with Amazon S3 storage sibling topic, which covers this for S3 in more depth. Before you rely on a lifecycle rule in production, confirm with your storage team that it matches the object store you run, and test the rule on a non-production bucket with a short retention so you know what it deletes and when.

Security and operational risks in retention settings

Retention in Loki is set in several places that can disagree: the compactor, per-tenant overrides, stream rules, the object store and the proxy in front of Loki. The cards below cover the failure modes that show up most often, and the checks that catch them before an auditor or an incident does.

Infinite retention from a disabled flag

Retention is disabled by default, so logs are kept indefinitely until compactor.retention-enabled is set. A cluster that was deployed without the flag, or whose configuration was reset during an upgrade, will keep growing without any error. Check the effective compactor configuration on every replica and confirm that old data is actually being deleted after the first retention cycle, not just that the setting exists in a file.

Loki retention docs

Lifecycle rules shorter than retention

If an object store lifecycle policy is configured, Loki says it must be longer than the retention period. A bucket rule that expires objects earlier than the compactor's retention will delete chunks that some tenants are still entitled to keep, and it does so outside Loki's own record of what was removed. Review the bucket lifecycle rules together with the global and per-tenant retention values whenever either one changes.

Tenant overrides that miss policy

Per-tenant and per-stream retention overrides let one cluster hold different periods for different teams or customers. An override that was typed for the wrong tenant ID, or a stream selector that matches fewer streams than intended, can leave sensitive data kept too long or removed too early. Compare the overrides file against the written retention schedule, and confirm the tenant IDs match the values sent in the X-Scope-OrgID header.

Loki multi-tenancy docs

Compactor failure or duplicate compactors

The compactor applies retention and should run as a singleton. Two compactor instances pointed at the same storage can compete over index files, and a stopped compactor means retention silently stops taking effect. With the default compaction interval, retention runs every 15 minutes, so a missing run shows up as a steady rise in stored data. Alert on compactor health and on the age of the oldest data in each tenant.

Access to retained logs through the proxy

Loki has no built-in authentication layer, so retention does not limit who can read logs that are still within their retention window. An authenticating reverse proxy such as nginx, HAProxy, OAuth2 Proxy or Pomerium must sit in front of Loki and map each user to the tenant IDs they may query. Test that a user from one team cannot send a different X-Scope-OrgID header and read another tenant's retained data.

Loki authentication docs

Retention decisions missing from audit evidence

Auditors and privacy reviewers ask how long each category of log is kept, who approved that period and how deletion is verified. Retention values scattered across Helm values, bucket policies and override files are hard to explain. Keep a single register that lists each tenant or stream selector, its retention period, the owner who approved it, the configuration version and the test that confirms deletion ran. Record changes with dates and reasons.

How to verify that logs are actually removed

Verify deletion with a controlled test before you rely on retention for anything an auditor will ask about. Pick a dedicated test tenant and a stream selector that matches only test traffic, such as a label value like env="retention-test", and set a short retention rule for that selector in the compactor's limits configuration. Then write a set of known test lines with distinct markers, record the exact times you wrote them, and keep a copy of the configuration that was active during the test. Confirm the retention window you chose is at least the 24-hour minimum for a stream rule, so the test runs on the same terms as production. Because the default compaction interval is 10 minutes and retention runs every 15 minutes, wait for the retention window to pass plus that cycle before you check. Confirm the exact cycle timing on your Loki version in the retention documentation, since the schedule is a compactor setting you may have changed.

Once the wait has passed, run two checks. First, query the test tenant in Grafana or with LogCLI for the unique markers over the original time range, and confirm that no lines return. An empty result alone is weak evidence, because the query path can also hide data in cache or in chunks that are still awaiting deletion, so also check the compactor logs for retention activity covering the test stream. Second, inspect the object store directly: list the chunk and index paths for the test tenant and confirm that no objects still hold the marker strings, or that objects remaining are outside the retention window. Confirm with your storage vendor how their listing and versioning behave, because a versioned bucket or a lifecycle rule can keep old object versions that a plain listing does not show.

Record the test as evidence: the configuration, the timestamps of writes and checks, the query outputs and the object listings, and the compactor log lines. Auditors ask how you know data was removed, and a repeatable test with stored output answers that better than a configuration file. Ask your team to confirm whether the test should be repeated after each Loki upgrade and after any change to the bucket lifecycle policy, since the lifecycle rule must outlast the retention period and a mismatch can keep data longer than Loki intends.

Questions teams ask before setting Loki retention

How much effort does Loki retention setup take, and what drives it?

The effort depends less on the retention setting itself than on how many tenants, stream rules and storage lifecycle policies have to be designed and kept consistent. Retention in Loki is applied by the compactor and is disabled by default, so logs are kept indefinitely until compactor.retention-enabled is set. Each additional tenant with its own period, and each stream selector with its own rule, adds design and testing work. Coordinating with object store lifecycle rules adds more, because Loki expects any lifecycle policy to outlast the retention period. Ask any quote to break effort down by tenant count, stream rule count, storage configuration and verification steps, and to state which parts are one-time and which recur when policies change.

Can our team set up Loki retention on its own?

Yes, a team that already runs Loki and has Grafana access can set retention on its own, provided it understands the compactor and its storage. The core configuration is small: enable retention on the compactor, define a global period, then add per-tenant or per-stream overrides where needed. The harder parts are running the compactor as a singleton, aligning the object store lifecycle policy, and proving that old data is actually removed. Teams without an existing Loki operator or without someone who owns the object storage bucket often find those coordination steps take longer than the configuration. DeployOpen can plan and implement this work as a fixed-scope engagement or leave the configuration with your team, depending on what you decide.

What does our organization need to provide for the retention work?

You need to provide a few decisions and some access before work starts. The main inputs are:

  • A written retention policy that states how long each category of log must be kept, and which categories can be removed sooner
  • The list of tenants, teams or environments that share the Loki cluster, with their owners
  • Access to the object storage buckets and the lifecycle configuration that applies to them
  • A change window in which the compactor configuration can be updated and checked
  • Named contacts for security, compliance and the teams whose logs are affected

If any stream carries personal or regulated data, say so early, because it may need a shorter period or a separate tenant. Ask the quote to list these inputs explicitly so that gaps are found before the change window.

How long does verifying that Loki removed expired data take?

Verification takes time because retention is not instant. The compactor runs retention on a schedule: with the default compaction interval of 10m, retention runs every 15m, so you should wait through several cycles before judging the result. Verification then checks three things: that the compactor logs show retention running, that a query for a tenant or stream returns no data older than its period, and that the object store contains no expired objects after the lifecycle rule has acted. Confirm with the vendor or your own test environment how long your storage backend takes to reflect deletions. Ask any quote to state the verification steps, the test data used and the evidence delivered at the end.

Why must the object store lifecycle policy be longer than the Loki retention period?

A lifecycle policy that expires objects before Loki's retention runs can delete chunks while the index still points to them, which produces query errors and makes retention behavior hard to reason about. The Loki documentation says that if an object store lifecycle policy is configured, it must be longer than the retention period. In practice, set the bucket lifecycle as a backstop and let the compactor do the primary deletion. Review both settings together whenever a tenant period is shortened or lengthened, because a change to one can silently break the other.

What changes if compliance requires a documented retention schedule?

A documented retention schedule turns the Loki configuration into evidence that must match the written policy. The schedule should list each tenant and stream selector, its retention period, the reason for that period, the owner and the review date. Each entry should map to a configured value and to the verification result from the compactor and storage. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications, and independent auditors decide whether your schedule meets a given framework. Ask any quote to include the schedule document, the configuration mapping and a process for approving and reviewing changes.

Does retention in Loki delete individual log lines?

No, retention removes data by age for the tenant or stream it applies to, and it does not remove specific lines. If a secret or personal data was logged, removing those lines is a different operation handled through the compactor's delete API, which has its own modes, cancellation period and requirements. Plan for that case separately, because retention alone will keep the sensitive line until its period ends. Ask any quote whether a deletion procedure is included or planned as a separate task.

Should retention be set globally or per tenant?

Set a global default that covers the most common case, then add per-tenant or per-stream overrides only where a documented requirement justifies a different period. Many overrides make the configuration harder to audit and easier to misconfigure, so each override should have an owner and a reason. Keep the list of overrides short and reviewed together with the storage lifecycle settings.

How DeployOpen scopes and delivers Loki retention work

DeployOpen plans and implements self-hosted Loki retention inside your own infrastructure, starting from a written scope that names each tenant, stream selector and retention period. We build the compactor settings, test that data is removed as intended, and hand over documentation your operators and compliance team can review.

How we scope

  • Engagements are fixed-scope, with retention periods, tenants and stream selectors agreed in writing before work starts.
  • We record which tenants and streams need different retention and which must be kept for a defined period.
  • The scope confirms the object store, lifecycle policy owner and the compactor host that will run retention.
  • We agree how deletion will be checked and which evidence the client receives at the end of the work.

How we build

  • We enable retention in the compactor configuration and set global, per tenant and per stream rules to the agreed values.
  • We align object store lifecycle rules so they outlast the longest Loki retention period, as the Loki documentation requires.
  • We run the compactor as a single instance and confirm its schedule, which runs retention on the default cadence unless changed.
  • We test retention on a non-production tenant with known data, then confirm that expired chunks and index entries are removed.

How we hand over

  • You receive the final configuration, tenant and stream retention map, and lifecycle policy settings in a written document.
  • The handover includes a verification runbook that shows operators how to confirm removal after each retention cycle.
  • We walk your platform and compliance teams through the settings so the configuration can be reviewed and changed later.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the initial handover.
  • Retainers can cover retention changes when new tenants or streams are added and when Loki versions are upgraded.
  • Confirm with your team which compactor monitoring and alerting you already run, so retention failures are noticed early.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.