General database instructions
Prepare your database to work with Pulse.
Prisma Pulse requires a publicly accessible PostgreSQL (version 12+) database with logical replication enabled. To configure specific database providers for Prisma Pulse, visit here.
Database Replication
Database replication is the process of creating copies of a database and storing them across various on-premises or cloud destinations. Prisma Pulse uses logical replication to monitor your database for changes.
Enable logical replication
wal_level
Some providers may not allow direct access to this setting. If you are unable to change this setting, please refer to the provider-specific guides for further assistance.
ALTER SYSTEM SET wal_level = logical;
You will need to restart the database after changing this setting.
Optional settings
wal_keep_size
Setting wal_keep_size
increases the memory usage of the write-ahead log on your PostgreSQL database.
We recommend setting a value for wal_keep_size
tailored to your database's storage capacity. This ensures smooth operation of both your database and Prisma Pulse.
We suggest setting these values initially and adjusting them if necessary.
ALTER SYSTEM SET wal_keep_size = 2048;
max_replication_slots
Prisma Pulse only needs one replication slot available. You can set the max_replication_slots
if you have other replications in use.
We suggest setting these values initially and adjusting them if necessary.
ALTER SYSTEM SET max_replication_slots = 20;
REPLICA IDENTITY
To get the before values of all fields in the record for some events, you must set REPLICA IDENTITY
to FULL
on the table(s) you want to get field values for. If this is not configured, defining a filter for those events will only be possible on the primary key.
For example, running the following SQL command will set the REPLICA IDENTITY
to FULL
on a table named User
:
ALTER TABLE public."User" REPLICA IDENTITY FULL;
Manage your own publication slot
If you want to enable replication for specific models or use a database provider that restricts superuser access for Prisma Pulse our advanced setup allows you to configure your own publication slot and use it to enable Pulse.
Creating a publication slot
You can create publications in the following ways below depending on the version of your PostgreSQL database.
Publication for all models.
CREATE PUBLICATION $PUBLICATION_NAME FOR ALL TABLES;
Publication for specific fields.
For example, create a publication that publishes all changes for table users
, but replicates only columns user_id
and firstname
:
CREATE PUBLICATION users_filtered FOR TABLE users (user_id, firstname);
Publication for specific models.
For example, create a publication that publishes all changes in two tables:
CREATE PUBLICATION user_and_department_publication FOR TABLE users, departments;
Publication for a model with a WHERE
clause on it’s fields.
For example, create a publication that publishes all changes from active departments
:
CREATE PUBLICATION active_departments FOR TABLE departments WHERE (active IS TRUE);
Publication based on DML operations.
For example, create a publication that only publishes INSERT
operations in one table:
CREATE PUBLICATION insert_only FOR TABLE departments
WITH (publish = 'insert');
publish
(string
)This parameter determines which DML operations will be published by the new publication to the subscribers. The value is comma-separated list of operations. The allowed operations are
insert
,update
,delete
, andtruncate
. The default is to publish all actions, and so the default value for this option is'insert, update, delete, truncate'
.
You can learn more about the PostgreSQL's CREATE PUBLICATION
, supported versions and see more examples here.
Submit your publication slot
You can submit the publication name in the Platform console, before enabling Prisma Pulse:
-
To view your publications, execute:
SELECT * FROM pg_publication_tables;
-
Then you can submit the desired publication name in the Platform console:
Removing publications
If you are managing your replications independently and choose to disable Prisma Pulse for a particular environment, you can refer to the following SQL queries to remove your publications.
-
To delete a publication:
DROP PUBLICATION IF EXISTS "$PUBLICATION_SLOT_NAME";
-
View your publications:
SELECT * FROM pg_publication_tables;
💡 To configure specific database providers for Prisma Pulse, visit here.