Quick Setup

Set the following configuration items in the postgresql.conf file.

wal_level = logical

For a basic setup, retain the default values for the other necessary configuration items.

You need to adjust the pg_hba.conf file to allow replication (the value depends on the actual network configuration and the user used for connection).

host     all     repuser     0.0.0.0/0     sha256

Run the following command in the publisher database. (For details about the command for creating a publication, see CREATE PUBLICATION.)

CREATE PUBLICATION mypub FOR TABLE users, departments;

Run the following command in the subscriber database: (For details about the command for creating a subscription, see CREATE SUBSCRIPTION.)

CREATE SUBSCRIPTION mysub CONNECTION 'dbname=foo host=bar user=repuser' PUBLICATION mypub;

The preceding statement starts the replication process, synchronizes the initial data of the users and departments tables, and then starts to replicate incremental changes to those tables.

You can modify the publication later, for example, add or delete the publication table. (For details about the command for modifying a publication, see ALTER PUBLICATION.)

ALTER PUBLICATION mypub ADD TABLE new_tbl;

After adding a publication table, you need to update the table in the subscriber database. (For details about the command for modifying a subscription, see ALTER SUBSCRIPTION.)

ALTER SUBSCRIPTION mysub REFRESH PUBLICATION;

Delete the publication from the publisher database. (For details about the command for deleting a publication, see DROP PUBLICATION.)

DROP PUBLICATION mypub;

Delete the subscription from the subscriber database. For details about the command for deleting a subscription, see DROP SUBSCRIPTION.)

DROP SUBSCRIPTION mysub;
Feedback
编组 3备份
    openGauss 2024-05-19 00:42:09
    cancel