1

I need to recover the superuser privilege for the postgres user, because it lost the superuser qualification.

I cannot do anything in the psql shell, it gives the message

must be superuser to create superusers

The system is Ubuntu 16.04 and PostgreSQL 9.5.
Can I recover this postgres user?

1 Answer 1

3

If you managed to remove superuser privileges from all your users, you'll have to start the database in single user mode:

  1. Stop the database server as operating system user postgres:

    /path/to/postgresql/bin/pg_ctl stop -D /path/to/data/directory
    
  2. Start the server in single user mode:

    /path/to/postgresql/bin/postgres --single -D /path/to/data/directory postgres
    

    Now you are a superuser.

  3. Restore the superuser privilege:

    ALTER ROLE postgres SUPERUSER
    
  4. Exit from the session with CTRL+D (or CTRL+Z if you are on Windows).

  5. Restart PostgreSQL the way you normally do it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Laurenz Albe
@FernandoMiranda if that answer solved your problem, then please accept it so that your question is marked as resolved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.