2

I have psql installed in my Ubuntu system. There is a database named tmpdb in it. I want to delete it but get an error message:

must be owner of database tmpdb".

I open psql with

  $psql postgres
  psql (9.5.6)
  Type "help" for help.

  postgres=>DROP DATABASE tmpdb;
  ERROR:  must be owner of database tmpdb
  postgres=>

How can I see owner, change it, so I can delete the database?

1

You don't have to do any of that if you want to delete it the simple way is to use dropdb as a database super-user. Assuming that postgres is still a database super-user.

sudo -u postgres dropdb tmpdb;

See man dropdb for more information.

0

To see the owner of a database, the easiest way is to use the \l command (or \l+ for some extra nerdy details) in psql. The owner can then be changed with

ALTER DATABASE tmpdb OWNER TO yournewowner;

In case you did not remember this exact syntax, you could have gotten some help with:

\h ALTER DATABASE

After this, you could delete your database with the DROP DATABASE command or with the dropdb executable.

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.