Postgresql – Problems running Postgres “createuser” command

command linemac os xpostgresql

I'm trying to run the createuser command on an MacOS 10.15 installation of Postgres 11.6. I have enabled root but there is no postgres user to su as – there's a _postgres user instead:

dd@finglas:~ $ cat /etc/passwd | grep 'post'
_postfix:*:27:27:Postfix Mail Server:/var/spool/postfix:/usr/bin/false
_postgres:*:216:216:PostgreSQL Server:/var/empty:/usr/bin/false

The $PATH is valid for Postgres tools, and which createuser points to the correct binary:

dd@finglas:~ $ which createuser

I was expecting to be able to execute something like:

dd@finglas:~ createuser dev_user

I can login to Postgres itself as the postgres user, but I'm unable to run a createuser from the terminal. Any suggestions?

Best Answer

The database user defaults to the same name as your operating system user. Try to specify it explicitly:

createuser -U postgres dev_user

If that causes authentication problens, try again as operating system user _postgres.