Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logged in as postgres but getting the error createuser: creation of new role failed: ERROR: must be superuser to create superusers

I need to create a superuser so I can create a db, but I'm having trouble with this. I'm logged in as the user postgres:

sudo su - postgres

But when I try to create a superuser, I get the following problem:

$createuser glassboard;
Shall the new role be a superuser? (y/n) y

createuser: creation of new role failed: ERROR: must be superuser to create superusers

This also happens if I try to create a new user in psql and then make him a superuser:

$ psql -U postgres
psql (9.1.4)
Type "help" for help.

postgres=> create user glassboard
postgres-> ;
ERROR:  permission denied to create role

How do I create a superuser?

output of \du in postgres:

postgres=> \du

                             List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
 main      | Superuser, Create role, Create DB, Replication | {}
 postgres  |                                                | {}
like image 393
Eric Baldwin Avatar asked Apr 03 '13 15:04

Eric Baldwin


2 Answers

Some OSX packages don't create a postgres superuser database account. The superuser is named differently, in your case it's main.

When you do psql -U main without specifying a database, it defaults to the same name as the user. If you don't have a database named main, indicate a different database with the -d option.

If you have no database to connect to, use template1

psql -U main -d template1

If still you want to grant superuser to postgres, do once logged inside psql:

alter user postgres superuser;
like image 178
Daniel Vérité Avatar answered Oct 13 '22 16:10

Daniel Vérité


In my case on PostgreSQL 9.2, the postgres superuser was created, but when I went to create additional superusers from the postgres user, I was never prompted with Shall the new role be a superuser? (y/n) so the new user was created with default permissions. To fix this, I just ran this command as the postgres user: ALTER USER myuser WITH SUPERUSER;

like image 33
yellavon Avatar answered Oct 13 '22 15:10

yellavon