I want to be able to run dropdb mydb
. However, when I try to as my normal user I get:
dropdb: error: database removal failed: ERROR: must be owner of database mydb
Now I know that I can just do:
sudo -u postgres dropdb mydb
but that's annoying if I'm trying to script the dropping and re-creation of a DB, because I have to manually enter my sudo
password.
I've mostly been able to avoid having to sudo
to the postgres user by having a pg_hba.conf
with:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
But for some reason dropdb
doesn't seem to respect my pg_hba.conf
. Is there some way to make it, so that I can just run dropdb
as my regular user?
EDIT: And the same question applies with createdb
. I can actually change the DB owner to be able to drop it (thanks stickybit!) ... but then I can't re-create it after.