The Postgres installers kindly provided to the community by EnterpriseDB.com creates a postgres
user account on macOS as is common.
In a console session in Terminal.app, I need to switch to that user. My goal is to run a text editor with that user’s privileges so that I can edit the pg_hba.conf
file controlling Postgres user-authentication rules.
When I try:
su - postgres
…I am prompted for the user's password, which I enter successfully, yet get the error message:
su: Sorry
I am sure the password is correct. What can I do to access the postgres
user?
Best Answer
The EBD installer asks for a password during the installation but it is meant for the database user, not the
postgres
Unix user, which doesn't have a password.This is mentioned in Postgres, Passwords and Installers on EDB site. Quote:
The most plausible explanation to
su - postgres
not working is for you is that you're confusing the database password with the OS password.To make
su - postgres
usable, the OS password would need to be set first, which could be done with:This is also true for PostgreSQL packaged in Linux distributions. In fact, the PostgreSQL packages for Linux even go one step further and don't ask a password for the database superuser, which allows for a fully automated installation. Just like the OS password is not necessary if
sudo
is always used, a database password is not necessary if only the defaultpeer
authentication method is ever used by thepostgres
user.