Can't go back to root from postgres: forces to enter postgres password which it finds invalid
I've installed postgres on Ubuntu and it switched me to postgres user. I've opened psql
created a database and then decided to switch back to root. However, it doesn't allow me:
sudo su -
results in it asking me
[sudo] password for postgres:
which I tried entering only to get
Sorry, try again
Then I decided to try to change postgres password using this answer:
ALTER USER postgres WITH PASSWORD 'postgres';
It seemingly worked, but after trying to switch to root again, it still doesn't let me.
It appears you are confusing two things:
-
postgres
the system user -
postgres
the SQL database user
The only relation between both is that at PostgreSQL installation, the database user postgres
is authenticated with the peer authentication method: the database server checks that the system user requesting access to the database as database user postgres
is also called postgres
. Also, the database server itself runs as the system user postgres
.
It's not possible from the database to alter the system. Giving a password on the database account will not alter the fact that the system user postgres
has no sudo rights, and most certainly a disabled password, thus allowing only root to use it by default (but not the reverse).
So, if you want to become root
, you cannot do this from the postgres
system account, and that's a good thing: should ever the database server (its processes also running as system user postgres
) be compromised, there will be no way to escalate to root
access from it.
Just login again to the account you used to install postgreSQL: either directly the root
account (usually not done on Ubuntu) or (usually done on Ubuntu) the user configured at installation of the system, with uid 1000, which on Ubuntu is allowed by default to do sudo su -
.
If you want to exit the postgres user, just type "exit".
It will go back to the root user