Getting Started
Architecture
NServiceBus
Transports
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Combining PostgreSQL Persistence and Transport

Component: Sql Persistence
Target Version: NServiceBus 9.x

Connection behavior

When combining PostgreSQL and SQL persistence using the PostgreSQL dialect, the connection behaves differently based on whether the Outbox is enabled or disabled. This influences where the saga data is stored.

Without Outbox

PostgreSQL Transport
TransactionMode
Connection sharingSaga location
SendsAtomicWithReceivePostgreSQL Transport uses isolated transaction for send and receiveTransport DB
ReceiveOnlyPostgreSQL Transport uses isolated transaction for receiveTransport DB
NoneNo transactionsPersistence DB

Explicitly opting out of connection sharing when not using the Outbox

When an endpoint uses PostgreSQL Persistence combined with the PostgreSQL Transport with Outbox disabled, the persistence uses the connection and transaction context established by the transport when accessing saga data. This behavior ensures exactly-once message processing behavior as the state change of the saga is committed atomically while consuming the message that triggered it.

When using the outbox, SQL Persistence always opens its own connection. In order to force using a separate connection even when the outbox is disabled, use the following API:

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
dialect.DoNotUsePostgreSqlTransportConnection();

With Outbox

PostgreSQL Transport
TransactionMode
Connection sharingSaga location
SendsAtomicWithReceiveNot supportedN/A
ReceiveOnlyConnection sharing via PostgreSQL Transport storage contextPersistence DB
NoneNot supportedN/A

Related Articles