-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgbench-bloating
executable file
·260 lines (228 loc) · 9.63 KB
/
pgbench-bloating
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
260
#!/bin/bash
set -e
here="$(dirname "${BASH_SOURCE[0]}")"
start="$(date +%s)"
shared_buffers=260000 # 2031MB (leave room for additional shared memory)
#shared_buffers=262143 # 2 GB (INT_MAX / block size)
#shared_buffers=1048576 # 8 GB
global_pgoptions="-c shared_buffers=$shared_buffers"
locale=uk_UA.UTF-8
encoding=unicode
wordlist=/usr/share/dict/ukrainian
# ???
scale=2
duration=$(( 1 * 24 * 60 * 60 ))
pgbenchoptions="-c 8 -j 1"
dbname="pgbench_$scale"
MINPORT=5400
# ???
du_interval=60
du_files=~/src/retropg/du.files
du_out=~/src/retropg/du.out
pgbench=/usr/local/pgsql/bin/pgbench
export LC_ALL=$locale
export LC_COLLATE=$LC_ALL
export LC_CTYPE=$LC_ALL
export LC_NUMERIC=C # c.f. REL7_3~975
export LC_TIME=C
export LC_MESSAGES=C
# only major releases so exclude *~*
RELS="$(for v in /usr/local/oldpgsql/*/bin/initdb ; do echo "$v" | sed '/~/d;/ALPHA/d;/BETA/d;/RC/d;s,.*/[0-9]*-[0-9]*-[0-9]*-\([^/]*\)/bin/initdb,\1,' ; done | sort -R)"
NRELS="$(for v in $RELS; do echo "$v" ; done | wc -l)"
TESTDIR="/var/tmp/oldpgsql"
if [[ ! -d $TESTDIR ]] ; then
mkdir $TESTDIR
fi
du_pid=""
pgbench_pids=""
function cleanup {
echo "--------------------------------------------------------------------------------"
echo "Cleaning up"
for pid in $pgbench_pids; do
kill $pid
done
if [[ -n $du_pid ]] ; then
kill $du_pid;
fi
mv "$du_files" "${du_files}.`LC_ALL=C date`" 2>/dev/null || echo no du_files to clean up
mv "$du_out" "${du_out}.`LC_ALL=C date`" 2>/dev/null || echo no du_out to clean up
for ver in $RELS; do
d="$(echo /usr/local/oldpgsql/*-$ver)"
rel="$(basename $d)"
bin="$d/bin"
db="$TESTDIR/d-$rel"
if [[ -e $db/postmaster.pid ]]; then
$bin/pg_ctl -D $db stop -m fast || echo "$bin/pg_ctl exited with status $?"
fi
done
}
trap cleanup EXIT
abort=
for s in /tmp/.s.PGSQL.*; do
if [[ -e $s ]] ; then
echo $s already exists
echo $s already exists 1>&2
abort=1
fi
done
if [[ $abort ]]; then
echo exiting
echo exiting 1>&2
exit 1
fi
for ver in $RELS; do
d="$(echo /usr/local/oldpgsql/*-$ver)"
rel="$(basename $d)"
db="$TESTDIR/d-$rel"
if [[ ! -d $db ]]; then
echo "Didn't find $db directory"
exit 1;
fi
if [[ -e $db/postmaster.pid ]] ; then
echo "Found $db/postmaster.pid"
exit 1;
fi
if [[ ! -f $d/bin/initdb ]] ; then
echo "Didn't find $d/bin/initdb"
exit 1
fi
done
if [[ -e $du_files ]] ; then
echo "du_files=$du_files exists"
exit 1
fi
if [[ -e $du_out ]] ; then
echo "du_out=$du_out exists"
exit 1
fi
port=$MINPORT
for ver in $RELS ; do
d="$(echo /usr/local/oldpgsql/*-$ver)"
rel="$(basename $d)"
db="$TESTDIR/d-$rel"
bin="$d/bin"
lib="$d/lib"
log="$TESTDIR/lb-$rel.log"
out="$TESTDIR/ob-$rel.out"
port=$(( $port + 1 ))
# start up
$bin/pg_ctl -D $db -l $log -o "$pgoptions -p $port" start || PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/postmaster -D $db $pgoptions -p $port > $log 2>&1 &
echo -n "Waiting for $rel to start up..."
for i in `seq 1 120` ; do
sleep 1
PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port -o /dev/null -X template1 -c 'select 1' 2>/dev/null && break
echo -n .
done
if PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port -o /dev/null -X template1 -c 'select 1' ; then
echo done
else
echo "Failed to start $rel..."
exit 1
fi
# createdb dedicated database for this scale
if ! PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -o /dev/null -X -c 'select 1'; then
createdbargs=""
if PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/createdb --help | grep -e '--encoding' >/dev/null; then
createdbargs="$createdbargs --encoding unicode"
fi
if PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/createdb --help | grep -e '--locale' >/dev/null; then
createdbargs="$createdbargs --locale $locale"
fi
if PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/createdb --help | grep -e '--lc_collate' >/dev/null; then
createdbargs="$createdbargs --lc_collate $locale"
fi
if PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/createdb --help | grep -e '--lc_ctype' >/dev/null; then
createdbargs="$createdbargs --lc_ctype $locale"
fi
echo "Running CREATEDB for $rel with -p $port $createdbargs $dbname"
PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/createdb -p $port $createdbargs $dbname
fi
if ! PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -o /dev/null -X -c 'select 1'; then
echo "Could not connect to $rel -p $port $dbname"
exit 1
fi
# pgbench -i
echo -n "Verifying pgbench database for $scale on $rel..."
branches=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c 'select count(*) from pgbench_branches' 2>/dev/null || echo 0)
tellers=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c 'select count(*) from pgbench_tellers' 2>/dev/null || echo 0)
accounts=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c 'select count(*) from pgbench_accounts' 2>/dev/null || echo 0)
npkey=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "select count(*) from pg_class where relname like 'pgbench%pkey'" 2>/dev/null || echo 0)
nrels=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "select count(*) from pg_class where relname like 'pgbench%'" 2>/dev/null || echo 0)
echo done
if [[ $branches -ne $scale || $accounts -ne $(( $scale * 100000 )) || $tellers -ne $(( $scale * 10 )) || $npkey -ne 3 || $nrels -ne 7 ]] ; then
echo -n "Initializing pgbench scale factor $scale on $rel..."
echo "========================================================================" >> $out
echo "Initializing $rel (scale $scale)" >> $out
echo "Start Time: $(LC_ALL=C TZ=GMT date --rfc-3339=seconds)" >> $out
TIMEFORMAT=%0lR
time ( ( $pgbench -p $port $dbname -X -i -s $scale ) >>$out 2>&1 || echo pgbench exited with status $?)
unset TIMEFORMAT
echo "End Time: $(LC_ALL=C TZ=GMT date --rfc-3339=seconds)" >> $out
echo "========================================================================" >> $out
branches=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c 'select count(*) from pgbench_branches' 2>/dev/null || echo 0)
tellers=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c 'select count(*) from pgbench_tellers' 2>/dev/null || echo 0)
accounts=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c 'select count(*) from pgbench_accounts' 2>/dev/null || echo 0)
npkey=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "select count(*) from pg_class where relname like 'pgbench%pkey'" 2>/dev/null || echo 0)
nrels=$(PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "select count(*) from pg_class where relname like 'pgbench%'" 2>/dev/null || echo 0)
if [[ $branches -ne $scale || $accounts -ne $(( $scale * 100000 )) || $tellers -ne $(( $scale * 10 )) || $npkey -ne 3 || $nrels -ne 7 ]] ; then
echo "Found discrepancy in initialized database"
echo "rel=$rel port=$port"
echo "branches=$branches accounts=$accounts tellers=$tellers npkey=$npkey nrels=$nrels"
exit 1
fi
fi
# We want to run without vacuuming so that we can get the right
# filenodes here so vacuum ourselves manually
PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "truncate pgbench_history"
PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "vacuum analyze"
# Get list of files to monitor
PATH=$bin:$PATH LD_LIBRARY_PATH=$lib $bin/psql -p $port $dbname -t -X -c "select relname,d||'/'||relfilenode::text from (select oid::text as d from pg_database where datname = '$dbname') as x, (select relfilenode,relname from pg_class where relname like '%pgbench%') as y" \
| while read tab x file; do
if [[ -n "$tab" ]] ; then
if [[ ! -e "$db/base/${file}" ]] ; then
echo "Didn't find $db/base/${file} for table $tab in $rel"
exit 1
fi
size=$(du -kc $db/base/${file}* | awk 'END {print $1}')
echo "Monitoring $rel $tab at $db/base/${file} initial size: $size"
echo "$rel $port $dbname $tab $db base/${file}" >> $du_files
fi
done
done
MAXPORT=$port
echo "========================================================================"
echo "All databases created and initialized for scale $scale"
echo "========================================================================"
n_du_files=$(wc -l $du_files)
echo "Starting du monitoring of $n_du_files files to $du_out"
while true ; do
start=$(date +%s)
oldrel=''
while read mon_rel mon_port mon_dbname mon_tab mon_db mon_prefix; do
if [[ $mon_rel != $oldrel ]] ; then
oldrel=$mon_rel
bin=/usr/local/oldpgsql/$mon_rel/bin
xid=$(LC_ALL=C TZ=GMT $bin/pg_controldata $mon_db | sed -n "/^Latest checkpoint's NextXID:/s/Latest checkpoint's NextXID: *//p")
fi
size=$(du -kc ${mon_db}/${mon_prefix}* | awk 'END {print $1}')
echo "$(( $(date +%s) - $start )) $mon_rel $mon_port $mon_dbname $mon_tab $mon_db $mon_prefix $xid $size" >> $du_out ;
done < $du_files;
sleep $du_interval ;
done &
du_pid=$!
echo "Starting pgbench duration $duration for every instance"
pgbench_pids=""
for port in `seq $MINPORT $MAXPORT`; do
if [[ -e /tmp/.s.PGSQL.$port ]] ; then
# -n to not vacuum. See above.
$pgbench -p $port -s $scale -T $duration -n $dbname $pgbenchoptions &
pgbench_pids="$pgbench_pids $!"
fi
done
# use wait somehow
sleep $duration
echo
echo "========================================================================"
echo " All done "
echo "========================================================================"
cleanup()