View Source Oban.Notifiers.PG (Oban v2.15.4)

A PG/PG2 based notifier implementation that runs with Distributed Erlang.

Out of the box, Oban uses PostgreSQL's LISTEN/NOTIFY for PubSub. For most applications, that is fine, but Postgres-based PubSub isn't sufficient in some circumstances. In particular, Postgres notifications won't work when your application connects through PGbouncer in transaction or statement mode.

Note: You must be using Distributed Erlang to use the PG notifier.

Usage

Specify the PG notifier in your Oban configuration:

config :my_app, Oban,
  notifier: Oban.Notifiers.PG,
  ...

Implementation Notes

  • The notifier will use pg if available (OTP 23+) or fall back to pg2 for older OTP releases.

  • Like the Postgres implementation, notifications are namespaced by prefix.

  • For compatibility, message payloads are always serialized to JSON before broadcast and deserialized before relay to local processes.

Migrating from Oban.Notifiers.Postgres

After switching from Oban.Notifiers.Postgres, you may remove the unused oban_notify trigger. Use the following migration to drop the trigger while retaining the oban_jobs_notify function:

defmodule MyApp.Repo.Migrations.DropObanJobsNotifyTrigger do
  use Ecto.Migration

  def change do
    execute(
      "DROP TRIGGER IF EXISTS oban_notify ON public.oban_jobs",
      "CREATE TRIGGER oban_notify AFTER INSERT ON public.oban_jobs FOR EACH ROW EXECUTE PROCEDURE public.oban_jobs_notify()"
    )
  end
end

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.