forked from AXLEproject/pg-tpch
-
Notifications
You must be signed in to change notification settings - Fork 19
/
pgtpch_defaults
110 lines (98 loc) · 3.2 KB
/
pgtpch_defaults
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
#!/bin/bash
# Configuration variables
# Scale factor. 1 = 1GB, 10 = 10GB. TPC-H has rules about which scale factors
# are considered valid for comparative purposes.
SCALE=100 #GB
# Other configuration variables
BASEDIR=$(dirname "$0")
BASEDIR=$(cd "$BASEDIR"; pwd)
TPCHTMP=/AXLE/$USER/tpch_tmp
PGDATADIR=/AXLE/$USER/pgdata${SCALE}GB
PGPORT=5442
REMAKE_DATA=true
DB_NAME="tpch"
POPULATE_DB=true
CREATE_MIN_INDEXES=false
CREATE_ALL_INDEXES=true
PERFDATADIR=perfdata
CORES=`grep -c ^processor /proc/cpuinfo`
PGUSER="nobody"
PGBINDIR=$HOME/bin/postgres-bs128/bin
LOGGING=false
# Install teardown() function to kill any lingering jobs
teardown() {
echo "Cleaning up before exiting"
sudo -u $PGUSER $PGBINDIR/pg_ctl stop -m fast -D "$PGDATADIR" 2>/dev/null && sleep 1
JOBS=$(jobs -p)
test -z "$JOBS" || { kill $JOBS && sleep 2; }
JOBS=$(jobs -p)
test -z "$JOBS" || kill -9 $JOBS
}
test -z "${DEBUG-}" && trap "teardown" EXIT
# Set up perf
perf_set_kernel_params() {
if [ -r /proc/sys/kernel/kptr_restrict ] && [ $(cat /proc/sys/kernel/kptr_restrict) -ne 0 ]; then
echo "Perf requires reading kernel symbols."
echo 0 | sudo tee /proc/sys/kernel/kptr_restrict
fi
if [ -r /proc/sys/kernel/perf_event_paranoid ] && [ $(cat /proc/sys/kernel/perf_event_paranoid) -ne -1 ]; then
echo "Need to enable the reading of performance events."
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
fi
if [ -r /proc/sys/kernel/perf_event_mlock_kb ] && [ $(cat /proc/sys/kernel/perf_event_mlock_kb) -lt 1024 ]; then
echo "Need to give more memory to perf."
echo 1024 | sudo tee /proc/sys/kernel/perf_event_mlock_kb
fi
}
# Restart and drop caches
restart_drop_caches() {
echo "Restart postgres and drop caches."
sudo -u $PGUSER $PGBINDIR/pg_ctl stop -D $PGDATADIR
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
sudo -u $PGUSER taskset -c 2 $PGBINDIR/postgres -D "$PGDATADIR" -p $PGPORT &
PGPID=$!
while ! sudo -u $PGUSER $PGBINDIR/pg_ctl status -D $PGDATADIR | grep "server is running" -q; do
echo "Waiting for the Postgres server to start"
sleep 3
done
}
# Calculates elapsed time
timer() {
if [[ $# -eq 0 ]]; then
echo $(date '+%s')
else
local stime=$1
etime=$(date '+%s')
if [[ -z "$stime" ]]; then stime=$etime; fi
dt=$((etime - stime))
ds=$((dt % 60))
dm=$(((dt / 60) % 60))
dh=$((dt / 3600))
printf '%d:%02d:%02d' $dh $dm $ds
fi
}
# To perform checks
die() {
echo "$@"
exit -1;
}
# Check for the running Postgres; exit if there is any on the given port
PGPORT_PROCLIST="$(lsof -i tcp:$PGPORT | tail -n +2 | awk '{print $2}')"
if [[ $(echo "$PGPORT_PROCLIST" | wc -w) -gt 0 ]];
then
echo "The following processes have taken port $PGPORT"
echo "Please terminate them before running this script"
echo
for p in $PGPORT_PROCLIST;
do
ps -o pid,cmd $p
done
exit -1
fi
# Check if a Postgres server is running in the same directory
if sudo -u $PGUSER $PGBINDIR/pg_ctl status -D $PGDATADIR | grep "server is running" -q; then
echo "A Postgres server is already running in the selected directory. Exiting."
sudo -u $PGUSER $PGBINDIR/pg_ctl status -D $PGDATADIR
exit -2
fi
cd "$BASEDIR"