-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpostgres_cdc.sql
47 lines (38 loc) · 1.11 KB
/
postgres_cdc.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
select version();
CREATE USER testuser WITH PASSWORD 'testpassword';
ALTER USER testuser WITH SUPERUSER;
CREATE TABLE IF NOT EXISTS emp (
empno int NOT NULL,
fname varchar(50),
lname varchar(50),
job varchar(50),
mgr int,
hiredate timestamp with time zone,
sal decimal(13, 2),
comm decimal(13, 2),
dept int,
PRIMARY KEY (empno)
);
ALTER TABLE emp REPLICA IDENTITY FULL;
CREATE TABLE IF NOT EXISTS heartbeat (id SERIAL PRIMARY KEY, ts TIMESTAMP WITH TIME ZONE);
ALTER TABLE heartbeat REPLICA IDENTITY FULL;
SELECT CASE relreplident
WHEN 'd' THEN 'default'
WHEN 'n' THEN 'nothing'
WHEN 'f' THEN 'full'
WHEN 'i' THEN 'index'
END AS replica_identity
FROM pg_class
WHERE oid = 'emp'::regclass;
SELECT CASE relreplident
WHEN 'd' THEN 'default'
WHEN 'n' THEN 'nothing'
WHEN 'f' THEN 'full'
WHEN 'i' THEN 'index'
END AS replica_identity
FROM pg_class
WHERE oid = 'heartbeat'::regclass;
COPY emp(empno, fname, lname, job, mgr, hiredate, sal, comm, dept)
FROM '/tmp/emp.csv'
DELIMITER ','
CSV HEADER;