#!/usr/bin/env bash # profiling/stop_postgres.sh # # Explicit, manual teardown of the profiling Postgres container. Not called # automatically by run_with_postgres.sh -- run this yourself once you're # done with a profiling session, so a seeded `large`-scale dataset can be # reused across several script runs first. Terminates any active backends # before stopping, so a stuck query can't stall `docker stop` waiting for # a graceful Postgres shutdown that never comes. set -euo pipefail CONTAINER_NAME="pngx-profiling-pg" if docker inspect "$CONTAINER_NAME" >/dev/null 2>&1; then docker exec "$CONTAINER_NAME" psql -U paperless -d paperless -v ON_ERROR_STOP=0 -c " SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid(); " >/dev/null 2>&1 || true docker stop "$CONTAINER_NAME" >/dev/null echo "Stopped and removed profiling Postgres container." else echo "No profiling Postgres container was running." fi