You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 4 години
преди 4 години
преди 2 години
преди 4 години
преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # Message retention policies
  2. Synapse admins can enable support for message retention policies on
  3. their homeserver. Message retention policies exist at a room level,
  4. follow the semantics described in
  5. [MSC1763](https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md),
  6. and allow server and room admins to configure how long messages should
  7. be kept in a homeserver's database before being purged from it.
  8. **Please note that, as this feature isn't part of the Matrix
  9. specification yet, this implementation is to be considered as
  10. experimental.**
  11. A message retention policy is mainly defined by its `max_lifetime`
  12. parameter, which defines how long a message can be kept around after
  13. it was sent to the room. If a room doesn't have a message retention
  14. policy, and there's no default one for a given server, then no message
  15. sent in that room is ever purged on that server.
  16. MSC1763 also specifies semantics for a `min_lifetime` parameter which
  17. defines the amount of time after which an event _can_ get purged (after
  18. it was sent to the room), but Synapse doesn't currently support it
  19. beyond registering it.
  20. Both `max_lifetime` and `min_lifetime` are optional parameters.
  21. Note that message retention policies don't apply to state events.
  22. Once an event reaches its expiry date (defined as the time it was sent
  23. plus the value for `max_lifetime` in the room), two things happen:
  24. * Synapse stops serving the event to clients via any endpoint.
  25. * The message gets picked up by the next purge job (see the "Purge jobs"
  26. section) and is removed from Synapse's database.
  27. Since purge jobs don't run continuously, this means that an event might
  28. stay in a server's database for longer than the value for `max_lifetime`
  29. in the room would allow, though hidden from clients.
  30. Similarly, if a server (with support for message retention policies
  31. enabled) receives from another server an event that should have been
  32. purged according to its room's policy, then the receiving server will
  33. process and store that event until it's picked up by the next purge job,
  34. though it will always hide it from clients.
  35. Synapse requires at least one message in each room, so it will never
  36. delete the last message in a room. It will, however, hide it from
  37. clients.
  38. ## Server configuration
  39. Support for this feature can be enabled and configured by adding a the
  40. `retention` in the Synapse configuration file (see
  41. [configuration manual](usage/configuration/config_documentation.md#retention)).
  42. To enable support for message retention policies, set the setting
  43. `enabled` in this section to `true`.
  44. ### Default policy
  45. A default message retention policy is a policy defined in Synapse's
  46. configuration that is used by Synapse for every room that doesn't have a
  47. message retention policy configured in its state. This allows server
  48. admins to ensure that messages are never kept indefinitely in a server's
  49. database.
  50. A default policy can be defined as such, by adding the `retention` option in
  51. the configuration file and adding these sub-options:
  52. ```yaml
  53. default_policy:
  54. min_lifetime: 1d
  55. max_lifetime: 1y
  56. ```
  57. Here, `min_lifetime` and `max_lifetime` have the same meaning and level
  58. of support as previously described. They can be expressed either as a
  59. duration (using the units `s` (seconds), `m` (minutes), `h` (hours),
  60. `d` (days), `w` (weeks) and `y` (years)) or as a number of milliseconds.
  61. ### Purge jobs
  62. Purge jobs are the jobs that Synapse runs in the background to purge
  63. expired events from the database. They are only run if support for
  64. message retention policies is enabled in the server's configuration. If
  65. no configuration for purge jobs is configured by the server admin,
  66. Synapse will use a default configuration, which is described here in the
  67. [configuration manual](usage/configuration/config_documentation.md#retention).
  68. Some server admins might want a finer control on when events are removed
  69. depending on an event's room's policy. This can be done by setting the
  70. `purge_jobs` sub-section in the `retention` section of the configuration
  71. file. An example of such configuration could be:
  72. ```yaml
  73. purge_jobs:
  74. - longest_max_lifetime: 3d
  75. interval: 12h
  76. - shortest_max_lifetime: 3d
  77. longest_max_lifetime: 1w
  78. interval: 1d
  79. - shortest_max_lifetime: 1w
  80. interval: 2d
  81. ```
  82. In this example, we define three jobs:
  83. * one that runs twice a day (every 12 hours) and purges events in rooms
  84. which policy's `max_lifetime` is lower or equal to 3 days.
  85. * one that runs once a day and purges events in rooms which policy's
  86. `max_lifetime` is between 3 days and a week.
  87. * one that runs once every 2 days and purges events in rooms which
  88. policy's `max_lifetime` is greater than a week.
  89. Note that this example is tailored to show different configurations and
  90. features slightly more jobs than it's probably necessary (in practice, a
  91. server admin would probably consider it better to replace the two last
  92. jobs with one that runs once a day and handles rooms which
  93. policy's `max_lifetime` is greater than 3 days).
  94. Keep in mind, when configuring these jobs, that a purge job can become
  95. quite heavy on the server if it targets many rooms, therefore prefer
  96. having jobs with a low interval that target a limited set of rooms. Also
  97. make sure to include a job with no minimum and one with no maximum to
  98. make sure your configuration handles every policy.
  99. As previously mentioned in this documentation, while a purge job that
  100. runs e.g. every day means that an expired event might stay in the
  101. database for up to a day after its expiry, Synapse hides expired events
  102. from clients as soon as they expire, so the event is not visible to
  103. local users between its expiry date and the moment it gets purged from
  104. the server's database.
  105. ### Lifetime limits
  106. Server admins can set limits on the values of `max_lifetime` to use when
  107. purging old events in a room. These limits can be defined under the
  108. `retention` option in the configuration file:
  109. ```yaml
  110. allowed_lifetime_min: 1d
  111. allowed_lifetime_max: 1y
  112. ```
  113. The limits are considered when running purge jobs. If necessary, the
  114. effective value of `max_lifetime` will be brought between
  115. `allowed_lifetime_min` and `allowed_lifetime_max` (inclusive).
  116. This means that, if the value of `max_lifetime` defined in the room's state
  117. is lower than `allowed_lifetime_min`, the value of `allowed_lifetime_min`
  118. will be used instead. Likewise, if the value of `max_lifetime` is higher
  119. than `allowed_lifetime_max`, the value of `allowed_lifetime_max` will be
  120. used instead.
  121. In the example above, we ensure Synapse never deletes events that are less
  122. than one day old, and that it always deletes events that are over a year
  123. old.
  124. If a default policy is set, and its `max_lifetime` value is lower than
  125. `allowed_lifetime_min` or higher than `allowed_lifetime_max`, the same
  126. process applies.
  127. Both parameters are optional; if one is omitted Synapse won't use it to
  128. adjust the effective value of `max_lifetime`.
  129. Like other settings in this section, these parameters can be expressed
  130. either as a duration or as a number of milliseconds.
  131. ## Room configuration
  132. To configure a room's message retention policy, a room's admin or
  133. moderator needs to send a state event in that room with the type
  134. `m.room.retention` and the following content:
  135. ```json
  136. {
  137. "max_lifetime": ...
  138. }
  139. ```
  140. In this event's content, the `max_lifetime` parameter has the same
  141. meaning as previously described, and needs to be expressed in
  142. milliseconds. The event's content can also include a `min_lifetime`
  143. parameter, which has the same meaning and limited support as previously
  144. described.
  145. Note that over every server in the room, only the ones with support for
  146. message retention policies will actually remove expired events. This
  147. support is currently not enabled by default in Synapse.
  148. ## Note on reclaiming disk space
  149. While purge jobs actually delete data from the database, the disk space
  150. used by the database might not decrease immediately on the database's
  151. host. However, even though the database engine won't free up the disk
  152. space, it will start writing new data into where the purged data was.
  153. If you want to reclaim the freed disk space anyway and return it to the
  154. operating system, the server admin needs to run `VACUUM FULL;` (or
  155. `VACUUM;` for SQLite databases) on Synapse's database (see the related
  156. [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-vacuum.html)).