cli
cli copied to clipboard
Add `supabase db shell` command to inspect databases
When working on the database, every now and then having a psql shell is crucial e.g. for debugging, for inspecting, and so on.
At the moment there are ways to get such a psql shell in the local database with
docker exec -it supabase_db_portal psql -U postgres
and in the remote database with a bit more magic e.g. what I'm using
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
if [ $# -lt 2 ]; then
echo "Usage: $(basename $0) db-cert-path project-ref"
echo
echo "You can download the ssl certificate in the supabase dashboard under Project Settings > Configuration > Database"
exit 1
fi
readonly DBCERT="$1"
readonly PROJECT="$2"
echo "You will have to enter the supabase project's database password you provided when you created the project"
docker run -it --rm --init -v "$DBCERT:/opt/supabase.crt:ro" postgres:15-bookworm \
psql "sslmode=verify-full sslrootcert=/opt/supabase.crt host=aws-0-eu-central-1.pooler.supabase.com dbname=postgres user=postgres.${PROJECT}"
It would be great to have a command like supabase db shell (or similar) that drops us into a psql shell in a postgres container with the matching postgres database version (similar to the workaround above). For both local and remote databases.