summaryrefslogtreecommitdiff
path: root/contrib/rserv/master.sql.in
blob: e52fc5760770b9a7d203e09bcabae45e3fa10cfd (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
-- erServer
-- Master server setup for erServer demonstration implementation
-- (c) 2000 Vadim Mikheev, PostgreSQL Inc.
--

--
-- Slave servers
--
drop table _RSERV_SERVERS_;

create table _RSERV_SERVERS_
(
	server	int4,	-- slave server id
	host	text,	-- server' host
	port	int4,	-- server' port
	dbase	text	-- db name
);


--
-- Tables to sync
--
drop table _RSERV_TABLES_;

create table _RSERV_TABLES_
(
	tname  name,	-- table name
	cname  name,	-- column name
	reloid	oid,	-- table oid
	key		int4	-- key attnum 
);


--
-- Log for inserts/updates/deletes to sync-ed tables
--
drop table _RSERV_LOG_;

create table _RSERV_LOG_
(
	reloid		oid,
	logid		int4,		-- xid of last update xaction
	logtime		timestamp,	-- last update xaction start time
	deleted		int4,		-- deleted or inserted/updated
	key			text		-- 
);

-- This is to speedup lookup deleted tuples
create index _RSERV_LOG_INDX_DLT_ID_ on _RSERV_LOG_ (deleted, logid);

-- This is to speedup cleanup
create index _RSERV_LOG_INDX_TM_ID_ on _RSERV_LOG_ (logtime, logid);

-- This is to speedup trigger and lookup updated tuples
create index _RSERV_LOG_INDX_REL_KEY_ on _RSERV_LOG_ (reloid, key);


--
-- How much each slave servers are sync-ed
--
drop table _RSERV_SYNC_;

create table _RSERV_SYNC_
(
	server		int4,
	syncid		int4,		-- from _rserv_sync_seq_
	synctime	timestamp,	-- 
	status		int4,		-- prepared (0) | applied
	minid		int4,		-- min xid from serializable snapshot
	maxid		int4,		-- max xid from serializable snapshot
	active		text		-- list of active xactions
);

create index _RSERV_SYNC_INDX_SRV_ID_ on _RSERV_SYNC_ (server, syncid);

drop sequence _rserv_sync_seq_;
create sequence _rserv_sync_seq_;

drop function _rserv_log_();

CREATE FUNCTION _rserv_log_()
	RETURNS opaque
	AS '_OBJWD_/rserv_DLSUFFIX_'
	LANGUAGE 'c'
;

drop function _rserv_sync_(int4);

CREATE FUNCTION _rserv_sync_(int4)
	RETURNS int4
	AS '_OBJWD_/rserv_DLSUFFIX_'
	LANGUAGE 'c'
;

drop function _rserv_debug_(int4);

CREATE FUNCTION _rserv_debug_(int4)
	RETURNS int4
	AS '_OBJWD_/rserv_DLSUFFIX_'
	LANGUAGE 'c'
;