AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/servicecontrol/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

ServiceControl PostgreSQL Storage

Component:
ServiceControl

From ServiceControl 7, Error and Audit instances can use PostgreSQL instead of RavenDB storage. Select PostgreSQL when an instance should use an existing PostgreSQL deployment. Storage is configured separately for each instance.

Supported PostgreSQL versions

ServiceControl supports the PostgreSQL major versions that are currently supported by the PostgreSQL Global Development Group; see the PostgreSQL versioning policy. Use the latest minor release of the chosen major version.

PostgreSQL 18 or later is recommended. In testing by Particular Software, PostgreSQL 18 significantly improved ServiceControl performance. PostgreSQL 18 can build GIN indexes in parallel, and ServiceControl uses GIN indexes for full-text message search.

Prepare the database

Create a database before configuring the instance as ServiceControl does not create the database. Setup creates the instance's schema if it does not exist. If the identity that runs setup cannot create schemas, create the schema in advance and grant that identity rights on it. Error and Audit instances can use the same database but not the same schema; see sharing a database.

PostgreSQL full-text search uses a built-in tsvector GIN index and message body search is always enabled for PostgreSQL storage, regardless of the EnableFullTextSearchOnBodies setting.

Database permissions

Grant each role the following rights:

RoleRequired rights
The role that runs setupCREATE on the database, so that setup can create the schema. If the schema already exists, USAGE and CREATE on it instead. Setup creates the tables and indexes, and for Audit instances the first daily partitions, so this role owns them.
The role an Error instance runs asUSAGE on the schema, and SELECT, INSERT, UPDATE, and DELETE on the tables in it. No sequence privileges are needed.
The role an Audit instance runs asOwnership of the Audit tables: the same role that runs setup, or a member of it. See the warning below.

An Error instance with no Database/Schema uses the connection's current schema, usually public. From PostgreSQL 15, only the database owner can create objects in public unless CREATE on it is granted, so the setup role needs CREATE on public or ownership of the database.

When the same connection string is used for setup and normal operation, as the ServiceControl Management Utility and PowerShell do, that role needs the setup rights.

Authentication

Configure database authentication in the connection string for each Error or Audit instance. This is separate from the transport connection string.

ServiceControl uses Npgsql. Methods configured entirely in the connection string work, such as a user name and password, a password file (Passfile), a client certificate, or Kerberos.

Token authentication

Azure Database for PostgreSQL and Amazon RDS for PostgreSQL, including Aurora PostgreSQL, can sign in with short-lived access tokens instead of a password. To use them, add Token Authentication to the connection string, set Username to the database role the token signs in as, and leave out Password and Passfile.

Token Authentication valueDatabaseCredentials
AzureEntraIdAzure Database for PostgreSQL with Microsoft Entra authenticationThe Azure SDK's DefaultAzureCredential. See Microsoft Entra ID.
AwsRdsIamAmazon RDS for PostgreSQL or Aurora PostgreSQL with IAM database authenticationThe AWS SDK default credential chain, such as an IAM role. The region comes from the AWS_REGION environment variable or the AWS profile.
Host=my-server.postgres.database.azure.com;Database=ServiceControl;Username=servicecontrol-identity;Token Authentication=AzureEntraId;SSL Mode=Require
Host=my-cluster.cluster-xxxxxxxxxxxx.us-east-1.rds.amazonaws.com;Database=ServiceControl;Username=servicecontrol;Token Authentication=AwsRdsIam;SSL Mode=Require

ServiceControl uses a token each time it opens a new database connection:

  • AWS IAM: ServiceControl signs a new token for every connection.
  • Microsoft Entra ID: ServiceControl reuses a token until two minutes before it expires, then gets a new one. If getting a new token fails while the current one is still valid, ServiceControl logs a warning, keeps using the current token, and tries again 10 seconds later.

If ServiceControl cannot get a valid token, opening the connection fails with Could not get a database access token for user <user> on host <host>, database <database>. The inner exception contains the error from the credential. Neither the error nor the warning includes the token.

The same keywords work in the PostgreSQL transport connection string.

Microsoft Entra ID

ServiceControl gets Microsoft Entra tokens from the Azure SDK's DefaultAzureCredential. It supports the following identities:

IdentityConfiguration
System-assigned managed identityNone
User-assigned managed identitySet AZURE_CLIENT_ID to the client ID of the identity.
Service principal with a client secretSet AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET.
Service principal with a certificateSet AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_CERTIFICATE_PATH to a PEM or PFX file that contains the certificate and its private key. For a password-protected PFX file, also set AZURE_CLIENT_CERTIFICATE_PASSWORD.
Microsoft Entra Workload ID, for example on Azure Kubernetes ServiceThe environment variables that the workload identity webhook sets.

Set these environment variables for the ServiceControl process. See EnvironmentCredential and ManagedIdentityCredential for the complete list of variables.

DefaultAzureCredential tries a chain of credentials in order and uses the first one that returns a token: environment variables (service principals), workload identity, managed identity, and then developer tools such as Visual Studio, the Azure CLI, and Azure PowerShell. On a machine where more than one credential is available, such as a virtual machine with a managed identity where a user is also signed in to the Azure CLI, the first available credential in the chain is used.

To use one credential only, set the AZURE_TOKEN_CREDENTIALS environment variable to its name, for example ManagedIdentityCredential or EnvironmentCredential. To exclude developer tool credentials, set it to prod. Setting AZURE_TOKEN_CREDENTIALS is recommended in production: the instance always signs in as the expected identity, and an authentication error comes from that credential instead of from the whole chain. See use a specific credential for the supported values.

ServiceControl works out the token scope from host names in the Azure public cloud, Azure Government, and Azure China. For other host names, such as a custom DNS alias, add Token Scope with the server's Microsoft Entra scope, for example Token Scope=https://ossrdbms-aad.database.windows.net/.default.

AWS IAM

The connection string must list exactly one host, because an IAM token is signed for a single host and port. Grant the database user the rds_iam role, and give the identity that ServiceControl runs as the rds-db:connect permission for that user. A user with rds_iam can no longer sign in with a password.

Error instance configuration

Set the storage type to PostgreSQL, provide the database connection string, and configure the retention period. Also configure an external message body store, which is required even if most bodies fit inline in the database. The ServiceControl Management Utility and the PowerShell module configure it when they create the instance. For manual or container deployments, add the ServiceControl/MessageBody/* settings to the instance's configuration file or environment.

ServiceControl/StorageType

Added in version 7.0.0

The storage implementation used by the instance. This setting is required; an instance without it does not start.

ContextName
Environment variableSERVICECONTROL_STORAGETYPE
App config keyServiceControl/StorageType
SCMU fieldSTORAGE TYPE
TypeDefault value
stringNone (required)

Valid values are RavenDB, SQLServer, and PostgreSQL. To choose where message bodies are stored with SQL Server or PostgreSQL storage, use ServiceControl/MessageBody/StorageType.

ServiceControl/Database/ConnectionString

Added in version 7.0.0

The connection string for the SQL Server or PostgreSQL database. The database must already exist.

ContextName
Environment variableSERVICECONTROL_DATABASE_CONNECTIONSTRING
App config keyServiceControl/Database/ConnectionString
SCMU fieldDATABASE CONNECTION STRING
TypeDefault value
stringNone (required for SQL Server and PostgreSQL storage)

ServiceControl/Database/Schema

Added in version 7.0.0

The schema that contains the Error instance tables. If the schema does not exist, setup creates it, which requires permission to create schemas. Changing this setting does not move existing data; an instance that already has data must keep using the schema that contains it.

ContextName
Environment variableSERVICECONTROL_DATABASE_SCHEMA
App config keyServiceControl/Database/Schema
SCMU fieldN/A
TypeDefault value
stringNone. Tables are created in the connection's default schema: the login's default schema on SQL Server (usually dbo), or the current schema from search_path on PostgreSQL (usually public).

ServiceControl/ErrorRetentionPeriod

The grace period that errored messages are kept before they are deleted.

For a message to be considered for deletion, it needs to have a status of either Archived, RetryIssued, or Resolved.

ContextName
Environment variableSERVICECONTROL_ERRORRETENTIONPERIOD
App config keyServiceControl/ErrorRetentionPeriod
SCMU fieldERROR RETENTION PERIOD
TypeDefault value
timespanNone (required) (SCMU slider defaults to 15 Days)

Valid range for this setting is between 5 days and 45 days.

Set these variables in the Error instance's environment to use file system body storage. Replace the connection string placeholder with credentials supplied by the deployment environment. These storage settings supplement the instance's transport and other required settings.

SERVICECONTROL_STORAGETYPE=PostgreSQL
SERVICECONTROL_DATABASE_CONNECTIONSTRING="Host=postgres;Database=ServiceControl;Username=sc;Password=..."
SERVICECONTROL_MESSAGEBODY_STORAGETYPE=FileSystem
SERVICECONTROL_MESSAGEBODY_FILESYSTEM_STORAGEPATH=/var/servicecontrol/bodies
SERVICECONTROL_ERRORRETENTIONPERIOD=15

See the Error instance settings reference for the complete reference.

To share the ingestion load across several processes, see Scaling out error ingestion. Workers use this instance's database, schema, and message body store, and only this instance runs setup.

Audit instance configuration

Set the storage type to PostgreSQL, provide the database connection string, and configure the retention period. Also configure an external message body store, which is required even if most bodies fit inline in the database. The ServiceControl Management Utility and the PowerShell module configure it when they create the instance. For manual or container deployments, add the ServiceControl.Audit/MessageBody/* settings to the instance's configuration file or environment.

ServiceControl.Audit/StorageType

Added in version 7.0.0

The storage implementation used by the Audit instance. This setting is required; an instance without it does not start.

ContextName
Environment variableSERVICECONTROL_AUDIT_STORAGETYPE
App config keyServiceControl.Audit/StorageType
SCMU fieldSTORAGE TYPE
TypeDefault value
stringNone (required)

Valid values are RavenDB, SQLServer, and PostgreSQL. To choose where message bodies are stored with SQL Server or PostgreSQL storage, use ServiceControl.Audit/MessageBody/StorageType.

ServiceControl.Audit/Database/ConnectionString

Added in version 7.0.0

The connection string for the SQL Server or PostgreSQL database. The database must already exist.

ContextName
Environment variableSERVICECONTROL_AUDIT_DATABASE_CONNECTIONSTRING
App config keyServiceControl.Audit/Database/ConnectionString
SCMU fieldDATABASE CONNECTION STRING
TypeDefault value
stringNone (required for SQL Server and PostgreSQL storage)

ServiceControl.Audit/Database/Schema

Added in version 7.0.0

The schema that contains the Audit instance tables. If the schema does not exist, setup creates it, which requires permission to create schemas. Changing this setting does not move existing data; an instance that already has data must keep using the schema that contains it.

ContextName
Environment variableSERVICECONTROL_AUDIT_DATABASE_SCHEMA
App config keyServiceControl.Audit/Database/Schema
SCMU fieldN/A
TypeDefault value
stringsc_audit

ServiceControl.Audit/AuditRetentionPeriod

The grace period to keep an audit message before it is deleted.

ContextName
Environment variableSERVICECONTROL_AUDIT_AUDITRETENTIONPERIOD
App config keyServiceControl.Audit/AuditRetentionPeriod
SCMU fieldAUDIT RETENTION PERIOD
TypeDefault value
timespanNone (required)

Valid range for this setting is from 1 hour to 365 days.

PostgreSQL-backed Audit instances are partitioned by day. The instance creates and drops daily partitions automatically, which requires the runtime role to own the Audit tables; see database permissions.

ServiceControl.Audit/MaxBodySizeToStore

A size limit, in bytes, for message bodies. Its effect depends on the storage type:

StorageEffect
RavenDBThe largest message body that the Audit instance stores. Larger bodies cannot be viewed in ServicePulse.
SQL Server or PostgreSQLThe 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 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.
ContextName
Environment variableSERVICECONTROL_AUDIT_MAXBODYSIZETOSTORE
App config keyServiceControl.Audit/MaxBodySizeToStore
SCMU fieldN/A
TypeDefault value
int102400 (100 KB)

Example environment variables for an Audit instance using file system body storage:

SERVICECONTROL_AUDIT_STORAGETYPE=PostgreSQL
SERVICECONTROL_AUDIT_DATABASE_CONNECTIONSTRING="Host=postgres;Database=ServiceControl.Audit;Username=sc;Password=..."
SERVICECONTROL_AUDIT_MESSAGEBODY_STORAGETYPE=FileSystem
SERVICECONTROL_AUDIT_MESSAGEBODY_FILESYSTEM_STORAGEPATH=/var/servicecontrol/audit-bodies
SERVICECONTROL_AUDIT_AUDITRETENTIONPERIOD=30

See the Audit instance settings reference for the complete reference.

Run setup

Setup applies database migrations for both Error and Audit instances. Setup also provisions the external message body store. See database permissions for the rights setup and normal operation need. See the Error container setup or Audit container setup instructions when deploying in containers.

The ServiceControl Management Utility (SCMU) and the PowerShell module run setup when they create or upgrade an instance, and can create PostgreSQL-backed Error and Audit instances:

  • SCMU: choose PostgreSQL as the STORAGE TYPE, enter the DATABASE CONNECTION STRING, and check the MESSAGE BODY PATH, which defaults to %ProgramData%\Particular\ServiceControl\<instance name>\MessageBodies. SCMU stores message bodies only on the file system.
  • PowerShell: pass -StorageType PostgreSQL and -DatabaseConnectionString to New-ServiceControlInstance or New-ServiceControlAuditInstance, and leave out -DBPath and -DatabaseMaintenancePort, which apply only to RavenDB. Also pass -MessageBodyPath, or choose Azure Blob Storage or Amazon S3 with -MessageBodyStorageType. See the Error instance and Audit instance PowerShell guides.

To change the message body store after the instance is created, change the message body settings in the instance's configuration file. Bodies already stored are not moved, so make the change before the instance ingests messages.

Neither tool sets Database/Schema, so instances they create use the default schema. Two Audit instances in one database both use the sc_audit schema, and two Error instances both use the current schema from search_path, usually public, so they share tables. Create independent instances of the same type in separate databases. To share a database between Audit instances on purpose, see Scaling out audit ingestion; those instances must also share a message body store. An Error instance and an Audit instance can use one database, because their default schemas differ.

Verify the setup

Setup logs PostgreSQL database migration completed for an Error instance, or Audit database migration completed for an Audit instance, and exits without an error. After the instance starts, check that no storage custom checks report a failure in ServicePulse.

Troubleshooting

  • Setup fails with a permission error: grant the rights in database permissions, or create the schema in advance.
  • Setup fails because "A primary instance and an audit instance cannot share a schema": set a different Database/Schema for one of the instances. See sharing a database.
  • The instance does not start with "Maintenance mode is not supported": set MaintenanceMode to false. Maintenance mode is only available with embedded RavenDB storage. To perform database maintenance, stop the ServiceControl instance and access PostgreSQL directly.
  • The ServiceControl Retention custom check fails: check the instance log. A body store that refuses deletes stops failed-message retention; see external message body storage operations.
  • The Audit partition provisioning custom check fails: make sure the Audit instance runs as the role that owns its tables. See database permissions.
  • Connections fail with "Could not get a database access token": check the inner exception for the credential's error. For Microsoft Entra ID, set AZURE_TOKEN_CREDENTIALS to the credential the instance should use, so that the error comes from that credential; see Microsoft Entra ID. For AWS IAM, check that the identity has the rds-db:connect permission for the database user and that the region is set.
  • Messages show without their bodies after a restore: restore the database and the external message body store from the same point in time. See backup and restore.

Next steps