12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- Once logical replication is enabled, create a publication with the tables that
- you want to replicate to Materialize. You'll also need a user for Materialize
- with sufficient privileges to manage replication.
- 1. As a _superuser_, use `psql` (or your preferred SQL client) to connect to
- your database.
- 1. For each table that you want to replicate to Materialize, set the
- [replica identity](https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-REPLICA-IDENTITY)
- to `FULL`:
- ```postgres
- ALTER TABLE <table1> REPLICA IDENTITY FULL;
- ```
- ```postgres
- ALTER TABLE <table2> REPLICA IDENTITY FULL;
- ```
- `REPLICA IDENTITY FULL` ensures that the replication stream includes the
- previous data of changed rows, in the case of `UPDATE` and `DELETE`
- operations. This setting enables Materialize to ingest PostgreSQL data with
- minimal in-memory state. However, you should expect increased disk usage in
- your PostgreSQL database.
- 1. Create a [publication](https://www.postgresql.org/docs/current/logical-replication-publication.html)
- with the tables you want to replicate:
- _For specific tables:_
- ```postgres
- CREATE PUBLICATION mz_source FOR TABLE <table1>, <table2>;
- ```
- _For all tables in the database:_
- ```postgres
- CREATE PUBLICATION mz_source FOR ALL TABLES;
- ```
- The `mz_source` publication will contain the set of change events generated
- from the specified tables, and will later be used to ingest the replication
- stream.
- Be sure to include only the tables you need. If the publication includes
- additional tables, Materialize will waste resources on ingesting and then
- immediately discarding the data.
- 1. Create a user for Materialize, if you don't already have one:
- ```postgres
- CREATE USER materialize PASSWORD '<password>';
- ```
- 1. Grant the user permission to manage replication:
- ```postgres
- GRANT rds_replication TO materialize;
- ```
- 1. Grant the user the required permissions on the tables you want to replicate:
- ```postgres
- GRANT CONNECT ON DATABASE <dbname> TO materialize;
- ```
- ```postgres
- GRANT USAGE ON SCHEMA <schema> TO materialize;
- ```
- ```postgres
- GRANT SELECT ON <table1> TO materialize;
- ```
- ```postgres
- GRANT SELECT ON <table2> TO materialize;
- ```
- Once connected to your database, Materialize will take an initial snapshot
- of the tables in your publication. `SELECT` privileges are required for
- this initial snapshot.
- If you expect to add tables to your publication, you can grant `SELECT` on
- all tables in the schema instead of naming the specific tables:
- ```postgres
- GRANT SELECT ON ALL TABLES IN SCHEMA <schema> TO materialize;
- ```
|