Skip to content

Commit

Permalink
wip -- vacuum
Browse files Browse the repository at this point in the history
  • Loading branch information
ransomw1c committed Oct 2, 2019
1 parent 72503d0 commit bd68590
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion hack/fuse-demo/wrap_datamon_pg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,34 @@ await_event \
'initdbupload' \
'waiting on db upload event'

# todo: vaccum
# VACUUM is a Postgres-specific SQL addition
# that allows the filesystem representation of the database
# to take less disk usage.
typeset -A db_name_to_username
for pg_db_id in $PG_DB_IDS; do
db_name_to_username=()
du_str=$(psql -p $PG_DB_PORTS[$pg_db_id] -U postgres -l | \
tail +4 | grep -v '^(.* rows)$' | \
grep -v '^ *$' | awk -F '|' '{print $1 $2}')
for du_pair in ${(f)du_str}; do
db_name=$(print -- $du_pair | awk '{print $1}')
username=$(print -- $du_pair | awk '{print $2}')
db_name_to_username[$db_name]=$username
done
for db_name in ${(k)db_name_to_username}; do
if [[ $db_name == 'postgres' || \
$db_name == 'template0' || \
$db_name == 'template1' ]]; then
continue
fi
print -- 'VACUUM;' | \
psql \
-h localhost \
-p $PG_DB_PORTS[$pg_db_id] \
-U ${db_name_to_username[$db_name]} \
$db_name
done
done

dbg_print "stopping postgres processes"

Expand Down

0 comments on commit bd68590

Please sign in to comment.