0

I normally get to the console in UBUNTU by typing:

sudo -u postgres psql

But I need to delete a database owned by a different user.

When I type:

sudo -u username psql

It tells me "database "username" does not exist.

But... I wasn't trying to connect to a database, I was trying to connect as a user.

  • I did make a lot of research effort, I went through the documentation linked below and somehow I still did not arrive at the answer below. – Sephethus Dec 26 '12 at 20:57
2

psql assumes you want to connect to the database named as the current user if you don't provide any login details.

But you can ovverride the defaults using parameters to psql, there is no need to use sudo in order to connect as a different username.

Simply run:

psql -U username -d databasename

where username is the user you want to use and databasename the database you want to connect to.

If you don't know which database you can connect to, use

psql -l

to show them all.

All this and a lot more is nicely documented in the manual: http://www.postgresql.org/docs/current/static/app-psql.html

|improve this answer|||||
  • Thanks I finally got in as myself. Yet despite my database showing up under \l I can't seem to delete it using DROP DATABASE databasename; It says it doesn't exist. – Sephethus Dec 26 '12 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.