---
title: "Postgres queues for AI agents (2026) — Cadenya"
url: "https://cadenya.com/other-content/postgres-queues-for-ai-agents"
description: "How pgmq, pg-boss, River, graphile-worker and Solid Queue run AI agent jobs on your Postgres, with 2026 versions, retries and human approval."
---

pgmq, pg-boss, River, graphile-worker, and Solid Queue all run AI agent jobs on the Postgres you already have: each one claims work with `SKIP LOCKED`, brings failed work back for another try, and, except for Solid Queue on its default separate database, lets you enqueue in the same transaction as your data. None of them runs the agent loop itself, so the model calls, the event stream, and the wait for a human approval stay in your code, though River Pro workflows can hold a task for an approval signal.

So pick by runtime. Use pg-boss or graphile-worker in Node.js, River in Go (with Java, Ruby, Rust, and TypeScript clients on the same schema), Solid Queue in Rails, and pgmq for plain SQL queues any language can call, as Supabase Queues does. And if you’d rather your queue just start agent runs and handle webhooks, Cadenya is a hosted agent loop with approvals, conversation state, resume, and model swap built in, so a job makes one API call to start an objective. A coding agent can set it up with no account, in a temporary workspace you claim later. [What it offers](#what-does-cadenya-add-to-a-postgres-job-queue) is at the end.

Every price and limit below comes from each vendor’s own pages, checked on November 11, 2026.

## pgmq vs pg-boss vs River vs graphile-worker vs Solid Queue for AI agent jobs

|  | pgmq | pg-boss | River | graphile-worker | Solid Queue | Cadenya |
| --- | --- | --- | --- | --- | --- | --- |
| What it is | A Postgres extension: SQL functions and one table per queue | A Node.js job queue | A Go job queue, with Java, Ruby, Rust, and TypeScript clients | A Node.js job queue you can also call from SQL | The Active Job backend for Rails | A hosted agent loop your jobs call |
| Retries | A message reappears after its visibility timeout, and read_ct counts reads | retryLimit, exponential backoff, dead letter queues | 25 attempts by default, plus snooze | 25 attempts by default, exponential backoff | Active Job retry_on | An External ID on each objective, so a retried job never starts a second run |
| Scheduling | A delay on send | Cron and RRULE schedules | Scheduled, periodic, and cron jobs | run_at and a crontab | Delayed jobs and config/recurring.yml | Agent schedules start objectives on calendar or interval rules |
| Waiting for a human approval | A message your app sends after the decision | A second job your approve endpoint sends | River Pro workflows: a task waits for a signal | A second job, which a trigger can add | A second job your approve endpoint enqueues | Mark a tool for approval, and the loop parks on toolApprovalRequested until your backend decides |
| What you still build | Workers, loop, stream, approval screen | Loop, stream, approval screen | Loop, stream, approval screen | Loop, stream, approval screen | Loop, stream, approval screen | Your tools and the approval decision. The loop, event log, and stream are hosted |
| License | PostgreSQL License | MIT | MPL-2.0, plus paid River Pro | MIT | MIT | SDKs under Apache-2.0 |

The first five are libraries you run next to your app, and the last is a service your jobs call.

## Latest versions

The latest releases on each registry and GitHub:

| Queue | Package | Latest release | Runs on |
| --- | --- | --- | --- |
| pg-boss | pg-boss on npm | 12.38.2, November 10, 2026 | Node.js 22.12 or Bun, PostgreSQL 13 or later |
| River | github.com/riverqueue/river | v0.51.2, November 9, 2026 | go 1.26.0 in go.mod, the three latest PostgreSQL majors |
| Solid Queue | solid_queue gem | 1.7.2, November 3, 2026 | Ruby 3.2 or later, Rails 7.1 or later |
| graphile-worker | graphile-worker on npm | 0.18.0, September 8, 2026 | Node.js 22.18 or later, PostgreSQL 12 or later |
| pgmq | pgmq/pgmq on GitHub | v1.13.1, October 20, 2026 | Postgres 14 to 18 |

River’s `riverqueue` npm package (0.3.2) and gem (0.16.1) shipped the same day, and “Every language uses the same River schema and migration history.” River Pro’s Go module is at v0.32.0 (October 5).

pg-boss ships `@pg-boss/dashboard` (1.13.1), and Solid Queue 1.7.0 added batches with callbacks. pgmq v1.13.1 is a security release, and Supabase Queues is “built on the pgmq database extension.”

## Retries and idempotency on SKIP LOCKED Postgres queues

All five claim work with `SKIP LOCKED`, so many workers share one queue without blocking each other. The pg-boss, graphile-worker, and Solid Queue docs say so, and the pgmq and River SQL on GitHub uses it.

And a job can run more than once. pg-boss says it plainly: “Jobs are delivered at least once,” so “Write handlers so that running one twice does no harm.”

**That matters more for an agent than for an email job.** Put a whole agent loop in one job, and a retry after a crash starts it from the top. You pay for the model calls again, and a tool that sent an email sends it again.

Three habits keep that safe:

1.  **Small jobs.** Run one model or tool call per job and keep the conversation in your own table. pg-boss `flow()` chains them, as do River Pro workflows.
2.  **Keys on side effects.** graphile-worker de-duplicates with a unique `job_key`. River unique jobs guarantee “only one exists for a given set of properties.” pg-boss policies such as `singleton` limit jobs per `singletonKey`.
3.  **Transactional enqueue.** In River, “A job inserted in a transaction becomes visible to workers only after the transaction commits.” So a saved message and the job that answers it can’t drift apart.

To make the whole loop durable on the same Postgres, see [DBOS for AI agents](/other-content/dbos-for-ai-agents). [Retries and idempotency for agent tool calls](/other-content/retries-and-idempotency-for-agent-tool-calls) covers the tool side.

## Human approval on a Postgres queue: River Pro workflows and the two-job pattern

A job that waits for a person holds a worker slot the whole time, and a deploy stops it. So on four of the five queues, an approval is two jobs and a row:

1.  The first job runs the agent until it wants a risky tool, saves the pending call to your `approvals` table, and finishes.
2.  Your approve endpoint updates that row and enqueues the second job in the same transaction.
3.  The second job loads the conversation, runs the approved tool, and continues.

graphile-worker can add that second job “from a trigger or function” with `graphile_worker.add_job`, and `pgmq.send` is plain SQL inside your transaction. pg-boss takes your transaction through ORM adapters. Solid Queue uses a separate database by default, so set `self.enqueue_after_transaction_commit = true` in Rails 8 to enqueue after the approval commits.

River Pro workflows can wait instead. The docs list “Human approval or rejection” as a use for wait conditions, and this example from them runs a task once a reviewer approves or a 30-minute timer fires:

```
workflow.Add("decide_shipment", ShipmentDecisionArgs{OrderID: "ord_123"}, nil, &riverpro.WorkflowTaskOpts{
    Wait: &riverworkflow.WaitSpec{
        Expr: "manual_review_received || review_sla",
        Terms: []riverworkflow.WaitTermSpec{
            riverworkflow.WaitTermSignal(
                "manual_review_received",
                "manual_review",
                `payload.approved == true && payload.reviewer != ""`,
            ).Label("Manual review approved"),
            riverworkflow.WaitTermTimer(
                riverworkflow.TimerAfterWaitStarted("review_sla", 30*time.Minute),
            ).Label("Review SLA elapsed"),
        },
    },
})
```

Your approve endpoint emits the signal, with an idempotency key so a replayed webhook creates “only one signal row for the same logical event”:

```
_, err := workflow.Signals().Emit(ctx, "manual_review", ManualReviewSignal{
    Approved: true,
    Reviewer: "alice",
}, &riverpro.WorkflowSignalEmitOpts{
    IdempotencyKey: requestID,
})
```

Workflows are part of River Pro: $150 a month, or $125 a month billed yearly, for up to 20 developers.

**On all five, the approval screen is yours to build.** [Human-in-the-loop approvals for AI agents](/other-content/human-in-the-loop-approvals-for-ai-agents) compares the ways to build it.

## Solid Queue and Rails 8.1 ActiveJob::Continuable for agent steps

Rails 8.1 (now 8.1.4.1) added Active Job Continuations, so a job can “continue from the last completed step rather than the beginning after a restart.” On Solid Queue, that’s the closest thing to durable agent steps without a workflow engine. Here’s the release notes example, adapted to an agent:

```
class SupportAgentJob < ApplicationJob
  include ActiveJob::Continuable

  def perform(ticket_id)
    # This always runs, even if the job is resumed.
    @ticket = Ticket.find(ticket_id)

    step :gather_context do
      @ticket.gather_context!
    end

    step :draft_reply do
      @ticket.draft_reply!
    end

    step :send_reply
  end

  def send_reply
    @ticket.send_reply!
  end
end
```

Four rules from the Active Job source decide how it behaves:

1.  **Completed steps are skipped on resume**, and a step in progress resumes “with the last recorded cursor.”
2.  **Code outside a step runs on every attempt**, so a model call there can run twice.
3.  **Steps don’t save results.** “Steps store serialized progress but they do not persist any other state,” so `draft_reply!` should save the draft to your database.
4.  **Checkpoints ask the adapter whether to stop.** A checkpoint calls `queue_adapter.stopping?`, and Solid Queue’s adapter sets that flag when its worker stops. The job then retries with its progress saved.

The release notes say why: Kamal gives “job-running containers thirty seconds to shut down by default.” A long model call isn’t a checkpoint, so give each one its own step. [Durable AI agents in Rails](/other-content/durable-ai-agents-in-rails) compares the other Rails options.

## Running agent jobs on the Postgres you already have

A queue runs your code reliably. For an agent, that code is still most of the work:

1.  **The loop.** Call the model, run the tools it asks for, append the results, and decide when it’s done.
2.  **The stream.** A job runs in a worker, not in the web request, so tokens reach the browser through a channel you add, such as `LISTEN` and `NOTIFY` or an SSE endpoint.
3.  **The approvals.** The pending-call table, the second job or the River Pro signal, and the screen.
4.  **The context window.** Long conversations need trimming to fit the model.

The other option is to keep the queue and move the loop out. With Cadenya hosting the loop, a pg-boss job just starts an objective. Create objective “rejects a duplicate externalId with AlreadyExists,” so a retried job finds the objective it already started:

```
import { PgBoss } from 'pg-boss'
import Cadenya from '@cadenya/cadenya'

const boss = new PgBoss(process.env.DATABASE_URL)
const cadenya = new Cadenya() // reads CADENYA_API_KEY and CADENYA_WORKSPACE_ID

boss.on('error', console.error)
await boss.start()
await boss.createQueue('start-agent', { retryLimit: 5, retryDelay: 60, retryBackoff: true })

await boss.work('start-agent', async ([job]) => {
  const externalId = `ticket-${job.data.ticketId}`
  try {
    await cadenya.objectives.create({
      agentId: 'external_id:support-agent',
      metadata: { externalId },
      firstUserMessage: job.data.question,
    })
  } catch (err) {
    // A retry after a successful create gets AlreadyExists. Retrieving by the
    // External ID confirms the objective exists; any other error throws here,
    // and pg-boss retries the job.
    await cadenya.objectives.retrieve(externalId)
  }
})
```

Events come back as signed webhooks. A handler can enqueue a job on `objective_event.tool_approval_requested` to notify a reviewer, keyed on the `webhook-id` header. The same shape works with River’s `InsertTx`, graphile-worker’s `addJob`, or a Solid Queue job.

## What does Cadenya add to a Postgres job queue?

**Cadenya is the agent loop, hosted, with approvals, conversation state, resume, and model swap, so your queue just starts objectives and handles webhooks.** Here’s what that covers:

1.  **Short jobs that are safe to retry.** A job makes one API call, and an External ID prevents duplicate objectives for a record in your app.
2.  **The agent loop, already written.** Cadenya calls the model, runs the tools, records every event in a durable event log, and compacts the context window.
3.  **Approvals without a second job.** Mark a tool as needing approval, and Cadenya “parks the Agent loop until it receives approval or a denial with optional steering.” A denial carries a memo the agent reads, such as “Use the read-only lookup tool instead.”
4.  **Conversation state and resume.** A Continue message resumes a waiting objective with its conversation intact, and the event stream resumes from the last event ID.
5.  **Webhooks your queue can consume.** Each event arrives as a Standard Webhooks delivery with your External ID in the envelope, so a handler routes it without another API call.
6.  **Schedules without a crontab.** An agent schedule starts objectives on calendar or interval rules in your time zone.
7.  **Model swap with no deploy.** The model is a setting on an agent variation, on your own provider keys.
8.  **SDKs and a price in one line.** SDKs for TypeScript, Python, Ruby, and Go are at 1.9.0 under Apache-2.0. Free covers 1,000 loops a month, and Growth is $49 a month for 50,000, then $0.0015 a loop.

[Create an Objective with an External ID](/docs/guides/the-basics/objectives#create-an-objective-with-an-external-id) shows the call your job makes, and the free plan needs no card.

No account yet? A coding agent can create a temporary workspace with `cadenya workspaces create --temporary`, run its first objectives there, and hand you a link to claim it, as [auth.md](https://cadenya.com/auth.md) explains. To create an account, sign up at [app.cadenya.com/signup](https://app.cadenya.com/signup?utm_source=cadenya.com&utm_medium=article&utm_campaign=postgres-queues-for-ai-agents), then copy your API key from the API keys page at `app.cadenya.com/account/apiKeys`.