# installChangeTriggers() function · @imqueue/pg-prisma

Source: https://imqueue.org/api/pg-prisma/latest/pg-prisma.installchangetriggers/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-prisma 1.0.1 — generated reference, not hand-written

Install Postgres triggers that `NOTIFY` on every row change in the given tables.

**Signature:**

```typescript
export declare function installChangeTriggers(client: RawClient, input: ChangeTriggerConfig): Promise<void>;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| client | [RawClient](https://imqueue.org/api/pg-prisma/latest/pg-prisma.rawclient/) | A client that can execute raw SQL and open a transaction. |
| input | [ChangeTriggerConfig](https://imqueue.org/api/pg-prisma/latest/pg-prisma.changetriggerconfig/) |  |


**Returns:**

Promise<void>

Nothing; it resolves once the triggers match `models`.

## Remarks

Creates one shared plpgsql function and attaches a row-level trigger to each table in `models`, firing after every insert, update and delete. Each notification is a JSON payload with three keys — `table`, `op` (`INSERT`, `UPDATE` or `DELETE`) and `row` — where `row` is the new row, or the OLD row for a delete. Listen for them with `@imqueue/pg-pubsub`, or any `LISTEN` client.

The whole thing runs in one transaction and is idempotent, so it is safe on every start. It also reconciles in both directions: `models` is the complete desired set, read against `information_schema.triggers`, so a table that carries the trigger but is not listed has it dropped. Calling this with an empty or omitted `models` therefore REMOVES every trigger of that name — it is not a no-op.

Two limits worth knowing. Postgres caps a notification payload at 8000 bytes and raises an error beyond it, so a table with large rows can make its own writes fail — this is unsuitable for wide or blob-bearing tables. And the trigger fires per row inside the writing transaction, so a bulk write produces one notification per row, delivered only if that transaction commits.

## Example


```typescript
await installChangeTriggers(prisma, { models: ['User', 'Order'] });
```

