# External Message Body Storage SQL Server and PostgreSQL storage separate large message bodies from the instance's database. The database stores message metadata and small text bodies; an external store holds larger bodies and every binary body. Configure an external store even if most messages have small bodies. SQL-backed Error instances require an external store and do not start without one. SQL-backed Audit instances start without one, but then [do not store large or binary bodies](#storage-providers-servicecontrol-auditmessagebodystoragetype). RavenDB manages message body storage itself. ## Storage providers Choose one provider per instance and follow its configuration guide. | Provider | `MessageBody/StorageType` value | Requirements | Configuration | | --- | --- | --- | --- | | File system | `FileSystem` | A durable directory accessible to the instance | [Configure file system storage](/servicecontrol/storage/external-body/file.md) | | Azure Blob Storage | `AzureBlob` | An Azure Storage account and credentials | [Configure Azure Blob Storage](/servicecontrol/storage/external-body/azure-blob.md) | | Amazon S3 | `S3` | An S3 bucket and credentials | [Configure Amazon S3 storage](/servicecontrol/storage/external-body/amazon-s3.md) | Configure the body store alongside [SQL Server](/servicecontrol/storage/sqlserver/index.md) or [PostgreSQL](/servicecontrol/storage/postgresql/index.md) storage. Use the same settings during setup and normal operation. Error instance settings use the `ServiceControl/` prefix, and Audit instance settings use the `ServiceControl.Audit/` prefix. The ServiceControl Management Utility configures file system body storage for Error and Audit instances, in the **MESSAGE BODY PATH** of each instance. The PowerShell module configures any of these stores; see [deploying an Error instance](/servicecontrol/servicecontrol-instances/deployment/powershell.md) and [deploying an Audit instance](/servicecontrol/audit-instances/deployment/powershell.md) with PowerShell. ### ServiceControl/MessageBody/StorageType _Added in version 7.0.0_ The external storage provider used for message bodies. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_STORAGETYPE` | | **App config key** | `ServiceControl/MessageBody/StorageType` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None (required for SQL Server and PostgreSQL storage) | Valid values are `FileSystem`, `AzureBlob`, and `S3`. The ServiceControl Management Utility sets this to `FileSystem`. The PowerShell module sets it from `-MessageBodyStorageType`, which defaults to `FileSystem`. ### ServiceControl.Audit/MessageBody/StorageType _Added in version 7.0.0_ The external storage provider used for message bodies. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_STORAGETYPE` | | **App config key** | `ServiceControl.Audit/MessageBody/StorageType` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | Valid values are `FileSystem`, `AzureBlob`, and `S3`. The ServiceControl Management Utility sets this to `FileSystem`. The PowerShell module sets it from `-MessageBodyStorageType`, which defaults to `FileSystem`. When this setting is not set, an Audit instance using SQL Server or PostgreSQL storage has no external body store. It still starts, but it does not store bodies that are not text or that are larger than [`ServiceControl.Audit/MaxBodySizeToStore`](/servicecontrol/audit-instances/configuration.md#performance-tuning-servicecontrol-auditmaxbodysizetostore), and those bodies cannot be viewed in ServicePulse. Set it for every SQL-backed Audit instance. ## Sharing a message body store > [!WARNING] > Give each instance its own directory, container, or key prefix, and do not share one between an Error instance and an Audit instance. Audit instances delete the bodies of expired messages by hour or by day across the whole location, so an instance with a shorter retention period can delete bodies that another instance still needs, and those messages stay visible without their bodies. The Audit defaults (`audit-bodies` and `audit-bodies/`) differ from the Error defaults, but they are the same for every Audit instance, so set a different [container](/servicecontrol/storage/external-body/azure-blob.md) or [key prefix](/servicecontrol/storage/external-body/amazon-s3.md) for each Audit instance. The exception is processes that share a database: [ingestion-only workers](/servicecontrol/servicecontrol-instances/scaling-out-ingestion.md) use their Error instance's body store, and [Audit instances that share a database](/servicecontrol/audit-instances/scaling-out-ingestion.md#sql-storage-shared-database) must also share one body store. ## Inline storage and compression A message body is stored in the database only when it is text and no larger than `MaxBodySizeToStore`. The following bodies go to the external store, whatever their size: - Bodies whose `NServiceBus.ContentType` header is missing, or does not contain `text/`, `xml`, or `json`, or contains `binary` - Bodies that have a `Content-Encoding` header, such as compressed payloads - Bodies that are not valid UTF-8 text, or that contain NUL characters A text body larger than the limit is also stored externally, and its first `MaxBodySizeToStore` bytes are kept in the database so that full-text search can match it. When endpoints use a binary serializer, plan for every message body to be in the external store. Bodies in the external store are compressed when they are at least `MessageBody/MinCompressionSize` bytes. ### ServiceControl/MaxBodySizeToStore _Added in version 7.0.0_ The maximum size, in bytes, of a text message body stored inline in the SQL database. Larger text bodies, and binary bodies of any size, are stored using the configured external storage provider. A larger text body also keeps its first `MaxBodySizeToStore` bytes in the database for full-text search. See [what is stored where](/servicecontrol/storage/external-body/index.md#inline-storage-and-compression). | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MAXBODYSIZETOSTORE` | | **App config key** | `ServiceControl/MaxBodySizeToStore` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | int | `102400` (100 KB) | ### ServiceControl.Audit/MaxBodySizeToStore A size limit, in bytes, for message bodies. Its effect depends on the storage type: | Storage | Effect | | --- | --- | | RavenDB | The largest message body that the Audit instance stores. Larger bodies cannot be viewed in ServicePulse. | | SQL Server or PostgreSQL | The largest text message body that is stored inline in the database. Larger text bodies, and bodies that are not text, are stored in the [external message body store](/servicecontrol/storage/external-body/index.md) and can be viewed in ServicePulse. A larger text body also keeps its first `MaxBodySizeToStore` bytes in the database for full-text search. See [what is stored where](/servicecontrol/storage/external-body/index.md#inline-storage-and-compression). | | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MAXBODYSIZETOSTORE` | | **App config key** | `ServiceControl.Audit/MaxBodySizeToStore` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | int | `102400` (100 KB) | ### ServiceControl/MessageBody/MinCompressionSize _Added in version 7.0.0_ The minimum message body size, in bytes, at which external message bodies are compressed. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_MINCOMPRESSIONSIZE` | | **App config key** | `ServiceControl/MessageBody/MinCompressionSize` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | int | `4096` (4 KB) | ### ServiceControl.Audit/MessageBody/MinCompressionSize _Added in version 7.0.0_ The minimum message body size, in bytes, at which external message bodies are compressed. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_MINCOMPRESSIONSIZE` | | **App config key** | `ServiceControl.Audit/MessageBody/MinCompressionSize` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | int | `4096` (4 KB) | See the [Error instance storage settings](/servicecontrol/servicecontrol-instances/configuration.md#message-body-storage) and [Audit instance storage settings](/servicecontrol/audit-instances/configuration.md#message-body-storage) for the complete reference. ## Operations Treat the database and external body store as a pair, and [back up and restore them together](/servicecontrol/storage/index.md#backup-and-restore). Monitor body-store capacity and availability as well as database health. An Error instance's retention process deletes a message's external body before it deletes the message's database record, starting with the oldest expired message. If body deletion fails, the affected records remain for a later sweep. After three failed runs in a row, the [**ServiceControl Retention**](/servicecontrol/servicecontrol-instances/index.md#notifications-health-monitoring-sql-storage-retention) custom check reports the failure in ServicePulse. Audit instances delete the external bodies of each expired hour (SQL Server) or day (PostgreSQL) before removing the corresponding database records. If the body store fails, the records stay and the next retention run tries again. Repeated failures are reported by the [**Audit retention**](/servicecontrol/audit-instances/index.md#notifications-health-monitoring-sql-storage-retention) custom check. Because retention deletes bodies, the identity the instance runs as needs delete access to the body store as well as read and write access. > [!WARNING] > Do not add storage cleanup rules, such as S3 Lifecycle rules or Azure Blob Storage lifecycle management policies, to the body store. ServiceControl deletes bodies itself when it removes their messages; rules that run on their own schedule delete bodies that ServiceControl still needs. Changing the provider, directory, container, or bucket does not move existing message bodies. Do not use configuration changes as a migration procedure. For database choices, see the [storage overview](/servicecontrol/storage/index.md).