HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMinor

Switch user to 'postgres' user on macOS results in "su: Sorry" error

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sorryerrorpostgresuserresultsswitchmacos

Problem

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?

Solution

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:


On Unix-like operating systems such as Linux and Mac OS X, the account
is setup without a password and users generally never need to worry
about it again.

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:

$ sudo passwd postgres


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 default peer authentication method is ever used by the postgres user.

Code Snippets

$ sudo passwd postgres

Context

StackExchange Database Administrators Q#221043, answer score: 7

Revisions (0)

No revisions yet.