-
Notifications
You must be signed in to change notification settings - Fork 0
Postgres Convenience Script
Beau Barker edited this page Oct 20, 2025
·
3 revisions
For development, add the following script to make it easy to run psql inside the container:
db/bin/postgres
#!/bin/bash
# Default to psql if first argument is not a known Postgres binary
if [[ $# -eq 0 || "$1" == -* ]]; then
set -- psql "$@"
fi
# If input is coming from a pipe or file, use -T to disable tty
if [[ ! -t 0 ]]; then
docker compose exec -T postgres "$@"
else
docker compose exec -it postgres "$@"
fiMake it executable:
chmod +x db/bin/postgresTo connect interactively (from the db directory):
bin/postgresExample output:
psql (17.5 (Debian 17.5-1.pgdg120+1))
Type "help" for help.
app=#
🗒️ By default,
bin/postgresopens apsqlshell. You can also run other commands in the container likebin/postgres bashif needed, or psql explicitly withbin/postgres psql.
You can also run SQL directly without opening an interactive shell:
bin/postgres -c 'select * from movie;'✅ Because bin/postgres defaults to psql, you don’t need to type psql
explicitly.