Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created November 20, 2019 22:10
Show Gist options
  • Select an option

  • Save twopoint718/e22fe1298966f1c809f49d4a2c5ca5bb to your computer and use it in GitHub Desktop.

Select an option

Save twopoint718/e22fe1298966f1c809f49d4a2c5ca5bb to your computer and use it in GitHub Desktop.
Script that returns all on-disk PostgreSQL database files for a given database.
#!/usr/local/bin/bash
set -e
if [ -z "$1" ]; then
echo "Must provide database name, e.g. 'my_database'"
exit 1
fi
db_dir=$(psql postgres -Atc "select (select setting from pg_settings where name = 'data_directory') || '/base/' || (select oid from pg_database where datname='$1')")
find "${db_dir}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment