简体   繁体   中英

Master Slave replication using WAL: Postgres uuid_generate_v4() to generate primary key

I'm creating a users table in postgres with the following schema:

CREATE TABLE users
(
    uuid character uuid COLLATE pg_catalog."default" NOT NULL DEFAULT uuid_generate_v4(),
    first_name character varying(100) COLLATE pg_catalog."default",

    CONSTRAINT agents_pkey PRIMARY KEY (uuid)
)

uuid is primary key of type uuid . I'm using uuid_generate_v4() to generate uuid values.

I'm not using Postgres in replication mode now.
But later, when I start using replication (most probably WAL streaming replication), will this lead to issues when I add replicas?
Is this similar to using non - deterministic functions (time now()) case?

Can the uuid values differ between master and replica for the same user (not sure if uuid is written to WAL, my assumption is it shouldn't be written)?

Also how are auto increment keys kept in sync across master - slave, is it kept in sync by replaying / inserting rows in the same order as master?

Either you misunderstand streaming replication, or I misunderstand what you are trying to do.

A streaming replication standby is a physical copy of the primary, and if hot_standby = on , you can establish read-only connections.

The contents of the table will always be identical on both servers, and you won't be able to insert a row on the standby, so it does not matter if the function in the DEFAULT clause is deterministic or not.

It seems like you might be looking for something called “multi-master replication”, so that you can modify data on both servers. PostgreSQL doesn't offer a solution for that out of the box.

It seems like you understand some of the problems with multi-master replication, since you ask this question. In most cases, it is better to choose a different architecture that comes with fewer problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM