aboutsummaryrefslogtreecommitdiff
path: root/contrib/rserv/InitRservTest.in
blob: 414744c6c012a3737fbc12f65b9131b910dad34a (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/sh
# InitRservTest
# erServer demonstration implementation
# (c) 2000 Vadim Mikheev, PostgreSQL Inc.

[ -n "$RSERV_PERL" ] || RSERV_PERL=@LIBDIR@
[ -n "$RSERV_SQL" ] || RSERV_SQL=@SQLDIR@
[ -n "$RSERV_BIN" ] || RSERV_BIN=@BINDIR@
export RSERV_PERL
export RSERV_SQL
export RSERV_BIN

pargs=

while [[ $1 == -* ]]; do
    case "$1" in
	--user)
	    shift
	    pargs="$pargs -U $1"
	    ;;
	--host)
	    shift
	    pargs="$pargs -h $1"
	    ;;
	*)
	    echo "Usage: $0 --user name --host name masterdb slavedb"
	    exit 1
	    ;;
    esac
    shift
done

masterdb=$1
slavedb=$2

[ "${masterdb}" != "" ] || masterdb=master
[ "${slavedb}" != "" ] || slavedb=slave

echo "Master -> $masterdb"
echo "Slave  -> $slavedb"

############################################################################

fill()
{
	table="create table test (i text, k int, l int);
copy test from stdin;
Line: 1	1	1
Line: 2	2	2
Line: 3	3	3
Line: 4	4	4
Line: 5	5	5
Line: 6	6	6
Line: 7	7	7
Line: 8	8	8
Line: 9	9	9
Line: 10	10	10
Line: 11	11	11
Line: 12	12	12
Line: 13	13	13
Line: 14	14	14
Line: 15	15	15
Line: 16	16	16
Line: 17	17	17
Line: 18	18	18
Line: 19	19	19
Line: 20	20	20
Line: 21	21	21
Line: 22	22	22
Line: 23	23	23
Line: 24	24	24
Line: 25	25	25
Line: 26	26	26
Line: 27	27	27
Line: 28	28	28
Line: 29	29	29
Line: 30	30	30
Line: 31	31	31
Line: 32	32	32
Line: 33	33	33
Line: 34	34	34
Line: 35	35	35
Line: 36	36	36
Line: 37	37	37
Line: 38	38	38
Line: 39	39	39
Line: 40	40	40
Line: 41	41	41
Line: 42	42	42
Line: 43	43	43
Line: 44	44	44
Line: 45	45	45
Line: 46	46	46
Line: 47	47	47
Line: 48	48	48
Line: 49	49	49
Line: 50	50	50
Line: 51	51	51
Line: 52	52	52
Line: 53	53	53
Line: 54	54	54
Line: 55	55	55
Line: 56	56	56
Line: 57	57	57
Line: 58	58	58
Line: 59	59	59
Line: 60	60	60
Line: 61	61	61
Line: 62	62	62
Line: 63	63	63
Line: 64	64	64
Line: 65	65	65
Line: 66	66	66
Line: 67	67	67
Line: 68	68	68
Line: 69	69	69
Line: 70	70	70
Line: 71	71	71
Line: 72	72	72
Line: 73	73	73
Line: 74	74	74
Line: 75	75	75
Line: 76	76	76
Line: 77	77	77
Line: 78	78	78
Line: 79	79	79
Line: 80	80	80
Line: 81	81	81
Line: 82	82	82
Line: 83	83	83
Line: 84	84	84
Line: 85	85	85
Line: 86	86	86
Line: 87	87	87
Line: 88	88	88
Line: 89	89	89
Line: 90	90	90
Line: 91	91	91
Line: 92	92	92
Line: 93	93	93
Line: 94	94	94
Line: 95	95	95
Line: 96	96	96
Line: 97	97	97
Line: 98	98	98
Line: 99	99	99
Line: 100	100	100
\\.";
	echo "$table" | psql $pargs $1 || exit
	if [ "$1" = "$masterdb" ]
	then
		rm -rf __tmpf__
		psql $pargs -c "select * into table testoid from test" $1 || exit
		psql $pargs -c "copy testoid with oids to '`pwd`/__tmpf__'" $1 || exit
		psql $pargs -c "select * into table teststr from test" $1 || exit
	else
		psql $pargs -c "select * into table testoid from test where k < 0" $1 || exit
		psql $pargs -c "copy testoid with oids from '`pwd`/__tmpf__'" $1 || exit
		psql $pargs -c "select * into table teststr from test" $1 || exit
		rm -rf __tmpf__
	fi
	psql $pargs -c "create unique index i_test on test (k)" $1 || exit
	psql $pargs -c "create unique index i_testoid on testoid (oid)" $1 || exit
	psql $pargs -c "create unique index i_teststr on teststr (i)" $1 || exit
	psql $pargs -c vacuum $1 || exit
}

############################################################################

echo
echo
echo '                            ATTENTION'
echo
echo This script will destroy databases with names MASTER and SLAVE
echo
echo -n "Are you going to continue ? [Y/N] "

read answ

case $answ in
    Y*|y*)
        ;;
    *)
        exit
        ;;
esac

echo
echo

sql="drop database $masterdb"
echo $sql
psql $pargs -c "$sql" template1
sql="create database $masterdb"
echo $sql
psql $pargs -c "$sql" template1 || exit

echo Setup master system
psql $pargs $masterdb < $RSERV_SQL/master.sql || exit

echo Wait for template1 to become available...
sleep 1

sql="drop database $slavedb"
echo $sql
psql $pargs -c "$sql" template1
sql="create database $slavedb"
echo $sql
psql $pargs -c "$sql" template1 || exit

echo Setup slave system
psql $pargs $slavedb < $RSERV_SQL/slave.sql || exit

echo Create and fill test, testoid and teststr tables in master db
fill $masterdb
echo
echo Register test, testoid and teststr tables for replication on master
echo
$RSERV_BIN/MasterAddTable $masterdb test k
$RSERV_BIN/MasterAddTable $masterdb testoid oid
$RSERV_BIN/MasterAddTable $masterdb teststr i

echo Create and fill test, testoid and teststr tables in slave db
fill $slavedb
echo
echo Register test, testoid and teststr tables for replication on slave
echo
$RSERV_BIN/SlaveAddTable $slavedb test k
$RSERV_BIN/SlaveAddTable $slavedb testoid oid
$RSERV_BIN/SlaveAddTable $slavedb teststr i

echo 
echo 
echo 
echo 
echo 
echo 
echo 
echo 
echo "            Now make changes in $masterdb db and run"
echo 
echo "                Replicate $masterdb $slavedb"
echo 
echo "            to replicate the master on the slave."
echo 
echo "            You may also use the RservTest tcl utility"
echo "            to demonstrate this functionality."
echo 
echo 
echo 
echo 
echo 
echo 
echo 
echo 

exit

############################################################################