Skip to main content
connic
Connectors

PostgreSQL

Start agents from PostgreSQL NOTIFY messages that a trigger or your application code sends.

Last updated
ModesInbound
YAML typepostgres
CredentialsA Connection of type postgres with the database address and login
BridgeOn the Connection, to reach a database in a private network
Custom domainNot supported
Linked agentsOne or more. A notification starts every linked agent.
While pausedconnic stops listening. PostgreSQL doesn't keep notifications for a listener that isn't connected, so notifications sent during the pause are lost.
New connectorsCreated paused in the dashboard, and through the REST API or connic MCP unless the request sets enabled: true. Start them with Resume. Connectors in code start active.

Set up

  1. Make the database reachable. Without a Bridge, its host must resolve only to public IP addresses. For a database in a private network, use a Bridge.

  2. Create a database user with the CONNECT permission on the database. Receiving notifications needs no other permission.

  3. Open the agent. In Connector Flow, click Add inbound connector, then Create New Connector, and select PostgreSQL.

  4. Under Connection, pick a saved Connection or create one with the database address and login; see Connection. If the database is in a private network, select the Bridge in the Connection. Enter the Notification Channel.

  5. Click Create. The new connector is paused: click Resume in its details drawer to start listening. To reopen the drawer, hover over the connector in the flow and click the eye icon.

  6. Send notifications on the channel from a trigger or from your application code.

In code

Declare the connector in connectors/*.yaml. The file names the Connection and never contains the database login. Connectors in code start active, so the connector starts listening when its first deploy goes live.

connectors/new-customers.yaml
type: postgres
connection: app-db            # Connection with the database address, login, and optional Bridge
config:
  channel: new_customers
agents:
  - customer-onboarding

Configuration

The fields of a PostgreSQL connector, the same in connectors/*.yaml, the REST API, and connic MCP. The descriptions name the matching setting in the dashboard. Connectors in code describes the fields every connector shares, such as agents and environments.

FieldTypeStatusDescription
typestringRequiredpostgres.
connectionstringRequiredName or ID of a Connection of type postgres, which holds the database address, the login, and the Bridge. See Connection. Dashboard: Connection.
configobjectRequiredPostgreSQL settings.
channelstringRequiredThe channel to listen on, such as new_customers. Letters, digits, and underscores, not starting with a digit. connic stores it in lowercase. Dashboard: Notification Channel.
parse_json_payloadbooleanOptionalParse each payload as JSON; see Agent input. Dashboard: Parse JSON Payload.Default: true

Connection

A Connection of type postgres holds these fields. Every PostgreSQL connector in the project can use it, and a connector's config doesn't take them. Manage Connections in Project Settings → Connections or through the REST API.

FieldTypeStatusDescription
hoststringRequiredHostname or IP address of the database server. Dashboard: Host.
portintegerOptionalServer port. Dashboard: Port.Default: 5432
databasestringRequiredName of the database to connect to. Dashboard: Database.
usernamestringRequiredDatabase user. Dashboard: Username.
passwordstringRequiredPassword of the database user. Secret. Dashboard: Password.
ssl_modestringOptionaldisable connects without TLS. prefer uses TLS when the server supports it. require always uses TLS and verifies the server certificate and hostname. Dashboard: SSL Mode.Default: prefer
bridgestringOptionalName or ID of the Bridge that reaches a database in a private network. The REST API and connic MCP take it as the Connection's top-level bridge, not in config. Dashboard: Bridge.

Every connector that uses the Connection goes through its Bridge. To use a different Bridge per environment, give each environment its own Connection; see Connections and Bridges. When you change the host, port, username, SSL mode, or Bridge of a saved Connection, enter the password again; connic refuses the change otherwise.

Send notifications

Every notification on the connector's channel starts runs. Send them from a trigger, so that each row change sends one, or from your application code. PostgreSQL delivers a notification when the sending transaction commits, and never for a transaction that rolls back.

From a trigger

This trigger sends a JSON object for each new row:

new_customers.sql
-- Send a notification for every new customer
CREATE OR REPLACE FUNCTION notify_new_customer()
RETURNS TRIGGER AS $$
BEGIN
  PERFORM pg_notify(
    'new_customers',
    json_build_object(
      'customer_id', NEW.id,
      'email', NEW.email,
      'company_name', NEW.company_name,
      'created_at', NEW.created_at
    )::text
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER customer_insert_trigger
  AFTER INSERT ON customers
  FOR EACH ROW
  EXECUTE FUNCTION notify_new_customer();

To report inserts and updates on one channel, include the operation:

customer_changes.sql
-- Report inserts and updates, with the operation
CREATE OR REPLACE FUNCTION notify_customer_changes()
RETURNS TRIGGER AS $$
BEGIN
  PERFORM pg_notify(
    'customer_changes',
    json_build_object(
      'operation', TG_OP,
      'customer_id', NEW.id,
      'old_email', CASE WHEN TG_OP = 'UPDATE' THEN OLD.email ELSE NULL END,
      'new_email', NEW.email,
      'updated_at', NOW()
    )::text
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER customer_change_trigger
  AFTER INSERT OR UPDATE ON customers
  FOR EACH ROW
  EXECUTE FUNCTION notify_customer_changes();

From application code

query.sql
SELECT pg_notify('new_customers', '{"customer_id": "12345", "action": "created"}');

-- or
NOTIFY new_customers, '{"customer_id": "12345", "action": "created"}';

NOTIFY folds an unquoted channel name to lowercase, but pg_notify uses the name exactly as written. connic listens on the lowercase name, so pass it to pg_notify in lowercase.

Keep payloads small: PostgreSQL limits a payload to less than 8000 bytes. Send IDs and let the agent load the full record with a tool. Use a separate channel, with its own connector, for each type of event, such as orders_created and users_updated.

Agent input

Each notification becomes the input of every linked agent. With Parse JSON Payload on, the default, a JSON object keeps its fields, and connic adds the notification metadata under _postgres:

payload.json
{
  "customer_id": "12345",
  "email": "customer@example.com",
  "company_name": "Acme Corp",
  "created_at": "2026-01-15T10:30:00",
  "_postgres": {
    "channel": "new_customers",
    "pid": 48213,
    "timestamp": "2026-01-15T10:30:00.123456"
  }
}

_postgres holds the channel, the pid of the database server process that sent the notification, and the timestamp when connic received it, in UTC.

Other JSON values, such as arrays or numbers, arrive under data. A payload that isn't valid JSON, and every payload while parsing is off, arrives as text under message.

Delivery

Each active connector keeps one database connection open and listens on its channel. Count these connections against the database's connection limit when you create several connectors. PostgreSQL sends a notification only to the listeners connected at that moment and doesn't store it.

Notifications sent while the connector is paused or reconnecting are lost, and so is a notification whose run fails to start. For events that must not be lost, write them to a queue that a Kafka or SQS connector reads.

Limits and errors

SituationWhat happens
A payload of 8000 bytes or morePostgreSQL rejects the NOTIFY with an error in the sending transaction.
No agent is linkedconnic records each notification as a connector run with No agents linked and starts no run.
Starting a run failsconnic records a failed connector run. The notification isn't delivered again.
The connection is lostconnic checks the connection every 30 seconds and reconnects with exponential backoff, from 5 seconds up to 2 minutes. Notifications sent in between are lost.
Wrong password, unknown database or role, or no pg_hba.conf entryThe listener stops and writes the error to the connector logs. It starts again when you update the connector or its Connection, or pause and resume it.