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.
Best Answer
It appears you are confusing two things:
postgres
the system userpostgres
the SQL database userThe 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 userpostgres
is also calledpostgres
. Also, the database server itself runs as the system userpostgres
.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 thepostgres
system account, and that's a good thing: should ever the database server (its processes also running as system userpostgres
) be compromised, there will be no way to escalate toroot
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 dosudo su -
.