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

postgresql, psql

Solution

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;

Problem

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 | | {} ```

Original source