{
  "schema_version": 2,
  "id": "commands/bgrewriteaof",
  "title": "BGREWRITEAOF",
  "url": "https://redis.io/docs/latest/commands/bgrewriteaof/",
  "summary": "Asynchronously rewrites the append-only file to disk.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:09+01:00",
  "page_type": "content",
  "content_hash": "18b7d7c1404835d0eee5adcc68cac8117ebd4dc35d711cbfbf675fa6de80d06e",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Instruct Redis to start an [Append Only File](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence#append-only-file) rewrite process.\nThe rewrite will create a small optimized version of the current Append Only\nFile.\n\nIf `BGREWRITEAOF` fails, no data gets lost as the old AOF will be untouched.\n\nThe rewrite will be only triggered by Redis if there is not already a background\nprocess doing persistence.\n\nSpecifically:\n\n* If a Redis child is creating a snapshot on disk, the AOF rewrite is _scheduled_ but not started until the saving child producing the RDB file terminates. In this case the `BGREWRITEAOF` will still return a positive status reply, but with an appropriate message.  You can check if an AOF rewrite is scheduled looking at the [`INFO`](https://redis.io/docs/latest/commands/info) command as of Redis 2.6 or successive versions.\n* If an AOF rewrite is already in progress the command returns an error and no\n  AOF rewrite will be scheduled for a later time.\n* If the AOF rewrite could start, but the attempt at starting it fails (for instance because of an error in creating the child process), an error is returned to the caller.\n\nSince Redis 2.4 the AOF rewrite is automatically triggered by Redis, however the\n`BGREWRITEAOF` command can be used to trigger a rewrite at any time.\n\nSee the [persistence documentation](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence) for detailed information."
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> | <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Simple string reply](../../develop/reference/protocol-spec#simple-strings): a simple string reply indicating that the rewriting started or is about to start ASAP when the call is executed with success.\nThe command may reply with an error in certain cases, as documented above.\n\n**RESP3:**\n\n[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): a simple string reply indicating that the rewriting started or is about to start ASAP when the call is executed with success.\nThe command may reply with an error in certain cases, as documented above."
    }
  ],
  "examples": []
}
