CREATE TABLE test_table_pk (id SERIAL, name VARCHAR(30), time_info TIMESTAMP NOT NULL, PRIMARY KEY(id));
CREATE TABLE test_table_2_pk_no (id SERIAL, num NUMERIC(5,2), info TEXT);
SELECT 'creat' FROM pg_create_logical_replication_slot('replication_slot', 'wal2json');
select * from pg_replication_slots ;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn | wal_status | safe_
replication_slot | wal2json | logical | 14037 | postgres | f | f | | | 495 | 0/17F5E28 | 0/17F5F80 | reserved |
INSERT INTO test_table_pk (name, time_info) VALUES('myuser1', now());
INSERT INTO test_table_pk (name, time_info) VALUES('myuser2', now());
INSERT INTO test_table_pk (name, time_info) VALUES('myuser3', now());
DELETE FROM test_table_pk WHERE id < 3;
INSERT INTO test_table_2_pk_no (num, info) VALUES(3.14, 'pie');
UPDATE test_table_2_pk_no SET info = 'pizza' WHERE info = 'pie';
SELECT data FROM pg_logical_slot_get_changes('replication_slot', NULL, NULL, 'pretty-print', '1');
WARNING: table "test_table_2_pk_no" without primary key or replica identity is nothing
"table": "test_table_pk", +
"columnnames": ["id", "name", "time_info"], +
"columntypes": ["integer", "character varying(30)", "timestamp without time zone"],+
"columnvalues": [1, "myuser1", "2024-08-16 16:39:24.320516"] +
"table": "test_table_pk", +
"columnnames": ["id", "name", "time_info"], +
"columntypes": ["integer", "character varying(30)", "timestamp without time zone"],+
"columnvalues": [2, "myuser2", "2024-08-16 16:39:24.320516"] +
"table": "test_table_pk", +
"columnnames": ["id", "name", "time_info"], +
"columntypes": ["integer", "character varying(30)", "timestamp without time zone"],+
"columnvalues": [3, "myuser3", "2024-08-16 16:39:24.320516"] +
"table": "test_table_pk", +
"keytypes": ["integer"], +
"table": "test_table_pk", +
"keytypes": ["integer"], +
"table": "test_table_2_pk_no", +
"columnnames": ["id", "num", "info"], +
"columntypes": ["integer", "numeric(5,2)", "text"], +
"columnvalues": [1, 3.14, "pie"] +
注:因为test_table_2_pk_no没有主键,所以update数据无法展示