0

I accidentally removed the super user privilege from user: postgres. I don't know how to get another super user. I stopped the postgres service and tried logging in with single-user mode:

/usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data

I get this error:

"root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.

In Linux, how can I start Postgres in single-user mode so I can fix the super user privilege?

Edit: I used this link for reference, but I'm getting the error mentioned above. Accidently removed postgres default superuser privileges - can I get it back?

2
  • 2
    Just do it as user postgres, not root, and it will work like a charm. Commented Jan 13, 2020 at 17:41
  • @LaurenzAlbe: Thanks for your comment. I did a variation of this, and that fixed the issue. Commented Jan 13, 2020 at 17:58

2 Answers 2

2

I combined solutions from these three links:

  1. Accidently removed postgres default superuser privileges - can I get it back?
  2. Restoring the superuser account on the postgres server
  3. “root” execution of the PostgreSQL server is not permitted

After stopping the postgresql service, I ran this command:

sudo -u postgres /usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
  1. /usr/pgsql-10/bin/postgres is the location of my postgres binary

  2. /var/lib/pgsql/10/data is the location of my postgresql conf

This allowed me to access single user mode, where I just typed this command:

ALTER USER postgres SUPERUSER;

So if anyone is experiencing the same scenario as me, please give the posted command a try.

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

Comments

1

just adding this for postgresql 12 (Ubuntu) and possibly up

sudo -su postgres /usr/lib/postgresql/12/bin/postgres --single -D /etc/postgresql/12/main

Comments

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.