-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvacuumschema.sh
More file actions
38 lines (35 loc) · 968 Bytes
/
vacuumschema.sh
File metadata and controls
38 lines (35 loc) · 968 Bytes
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
#!/bin/bash
run_command() {
for table in $(psql -h ${PGHOST} -p ${PGPORT} -d ${PGDB} -U ${PGUSER} \
-c "select tablename from pg_tables where schemaname = '${PGSCHEMA}';" | \
tail -n +3 | head -n -2); do
psql -h ${PGHOST} -p ${PGPORT} -d ${PGDB} -U ${PGUSER} \
-c "VACUUM (ANALYZE) ${PGSCHEMA}.${table};";
done
}
display_help() {
echo "Usage: $0 -s schemaname" >&2
echo
echo " -s schema The schema to be analyzed."
echo
echo " The script assumes that you have a ~/.pgpass file that contains your password"
echo " information. The file is described in detail on the Postgres documentation:"
echo " https://www.postgresql.org/docs/current/libpq-pgpass.html"
echo
exit 1
}
while getopts "hw:s:" optionName; do
case "$optionName" in
h)
display_help
exit 0
;;
s)
PGSCHEMA="$OPTARG";;
[?])
display_help
exit 0
;;
esac
done
run_command