← back to Db Saturation Fix
2-audit-pools.sh
28 lines
#!/usr/bin/env bash
# READ-ONLY audit — run ON Kamatera as root. Finds apps whose pg pool is large/unbounded.
# Touches nothing; only greps source. The Node `pg` Pool default max is 10 — with 268 apps
# that alone is up to 2680 potential connections against a 500 ceiling.
set -uo pipefail
ROOTS="/root/public-projects /root/Projects /root/DW-Agents /var/www"
echo "== apps that construct a pg Pool/Client, and their max (blank = default 10) =="
for base in $ROOTS; do
[ -d "$base" ] || continue
grep -rlE "new (Pool|Client)\(|require\(['\"]pg['\"]\)" "$base" --include=*.js --include=*.cjs 2>/dev/null \
| grep -v node_modules | while read -r f; do
maxv=$(grep -oE "max:\s*[0-9]+" "$f" | head -1)
printf "%-70s %s\n" "${f#/root/}" "${maxv:-max:DEFAULT(10)}"
done
done | sort -u
echo
echo "== summary: apps with no explicit max (each can open up to 10) =="
cnt=0
for base in $ROOTS; do
[ -d "$base" ] || continue
for f in $(grep -rlE "new Pool\(" "$base" --include=*.js 2>/dev/null | grep -v node_modules); do
grep -qE "max:\s*[0-9]+" "$f" || cnt=$((cnt+1))
done
done
echo "unbounded-pool files: $cnt"