---
title: Run Multiple Deployments on Postgres
description: Release a new build of a self-hosted eve agent while the previous build finishes its work on the same Postgres Workflow world.
url: "https://eve.dev/docs/guides/deployment/postgres-multi-deployment"
docs_index: /llms.txt
---

> For an index of all documentation, see [/llms.txt](/llms.txt).

Use Postgres deployment routing to release a new build without replacing the code that runs in-flight turns. Each Workflow run is pinned to a deployment. New sessions start on the new deployment, and eligible idle sessions can move there on their next message.

## Configure deployment routing

These steps use eve 1.7 and `@workflow/world-postgres` 5.5.2. [Select and bootstrap the Postgres world](./workflow-worlds#use-the-postgres-world) before starting the server. Select the package in `agent.ts`; `WORKFLOW_TARGET_WORLD` is a Workflow SDK setting, not the eve build configuration.

Give each build a unique `WORKFLOW_POSTGRES_DEPLOYMENT_ID`, even if only your agent code changed. Build once and give every replica of that build the same output and ID. Keep the database and `WORKFLOW_POSTGRES_JOB_PREFIX` the same across deployments of this agent.

```bash
WORKFLOW_POSTGRES_DEPLOYMENT_ID=support-2026-12-03 \
  eve start --host 0.0.0.0
```

Use letters, digits, `.`, `-`, `_`, or `@`. In 5.5.2, the limit is 72 characters with the default job prefix; a longer prefix reduces the limit. Don't use `postgres` or `latest`. The former identifies unpinned runs, and eve requires an exact ID instead of `latest`.

The Postgres world reads `WORKFLOW_POSTGRES_DEPLOYMENT_ID`, not the `WORKFLOW_DEPLOYMENT_ID` that eve sets from the build output. If you omit the Postgres setting, runs are unpinned. Never reuse an ID for different output: workers sharing an ID can claim one another's jobs, and eve skips its version check with deployment routing enabled.

Leave `WORKFLOW_POSTGRES_INVOKE` unset on every deployment. Use queued delivery so messages can wake sessions on another deployment. Leave `WORKFLOW_POSTGRES_SKIP_WORKERS` unset on processes that need to execute queued work.

### Start routing on an existing database

If the database already contains unpinned runs, finish or end them before enabling routing. Setting the ID doesn't move those runs. In 5.5.2, startup recovery can also pick up active runs created before the package recorded job prefixes, even when a new deployment ID is set.

1. Stop sending new work to the unpinned build. Keep its workers running until its runs end.
2. Check for active runs with `deployment_id = 'postgres'` using the [retirement query](#retire-a-deployment). Also check for active runs with `job_prefix IS NULL` on the database before you start the first pinned build.
3. Stop the unpinned processes. Start the pinned build and verify a new session before opening public traffic.

## Release a new build

1. Build and start the new deployment with a new `WORKFLOW_POSTGRES_DEPLOYMENT_ID`. Keep it out of the public proxy and start it with `eve start --no-schedules`.
2. Cut over all customer API traffic and channel webhooks to the new deployment. Disable authored schedules on the previous deployment and enable them on [one replica](./self-hosted-operations#run-schedules) of the new deployment. Avoid serving public requests from both builds: a session can move to whichever build accepted the message, including the older one.
3. Keep workers on the previous deployment running with their original build and environment. Use `eve start --no-schedules` to run them without authored schedules. They don't need public traffic: eve runs queued Postgres work inside the worker process.
4. [Retire the previous deployment](#retire-a-deployment) only after it has no active runs. Keep a copy of its build and runtime configuration until then.

If your agent uses connection sign-in or remote agents, keep the [public callback origin](./self-hosting#set-the-public-callback-origin) on the public hostname. The proxy sends those requests to the new deployment, while Postgres routes queued work to its pinned workers.

Several deployments can drain at once. Include their workers in your [Postgres pool and concurrency sizing](./workflow-worlds#tune-the-postgres-world).

## What happens to existing sessions

- A busy session stays on its current deployment. Running turns, pending approvals or sign-ins, queued messages, and active tasks or subagents can prevent a move.
- An eligible idle session can move when the new deployment receives its next message. [Handoff](../../concepts/execution-model-and-durability#sessions-turns-and-steps) keeps its ID, stream, conversation, and channel addresses. Work already started, including subagent and workflow tool runs, isn't moved.
- If the new build can't read the session's checkpoint, the current deployment keeps the session and handles the message. Look for `session handoff refused` on the target and `session handoff failed` on the source. A rollback changes where new sessions start; it doesn't automatically move existing sessions back.

Even after a handoff, the session's first run stays on the original deployment until the session ends. It owns the public stream and needs its original workers to finish. Keep those workers available even if the newer deployment handles all subsequent turns.

**Startup recovery in 5.5.2:** A handoff can create the new run's record with the source deployment's job prefix. Queued work still uses the target deployment ID, but restarting the target isn't guaranteed to recover an interrupted handoff run through startup recovery. Don't rely on restart alone to recover those runs.

## Retire a deployment

First confirm that no public traffic, schedules, or other callers can start runs on the deployment. Then query Postgres for pending or running runs:

```sql
SELECT count(*)
FROM workflow.workflow_runs
WHERE deployment_id = 'support-2026-12-03'
  AND status IN ('pending', 'running');
```

Substitute the deployment ID you plan to retire. Stop its workers only when the count is zero. The count includes open sessions' first runs, even after handoff. It also includes subagent sessions, workflow tool runs, and session timeout timers.

The default [`sessionTimeoutMs`](../../agent-config#runtime-limits) is a 30-day idle timeout, not a drain deadline. New messages extend the idle window, and `sessionTimeoutMs: false` disables it. End open sessions explicitly if you need to retire the deployment by a deadline.

Postgres doesn't report a deployment as missing when it has no workers. Messages can be accepted without a reply, and streams that depend on that deployment can remain open. If you stopped it too early, restart its original build with the same deployment ID, database, and job prefix.

---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)