I've had a very difficult time trying to set up a postgres database. I am using Mac OS X 10.9.2.

I am using this tutorial: http://tutorials.jumpstartlab.com/topics/environment/environment.html

The Postgres section can be found 2/3 of the way down the page.

After installing Homebrew and commanding brew install postgresql

we create a database by:

sudo mkdir -p /usr/local/pgsql/data
sudo chown postgres:postgres /usr/local/pgsql/data
sudo su postgres
initdb -D /usr/local/pgsql/data
createuser `whoami`

When I do

sudo chown postgres:postgres /usr/local/pgsql/data

it returns the error

chown: postgres: illegal user name

I can't seem to find a simple command to add a user - adduser and useradd have returned "command not found", with and without sudo. I am not sure what the problem is. Is there a simple command I can do?

  • Well, is there a user named "postgres" on your system? May 23, 2014 at 11:27
  • 1
    You likely don't have a postgres user on your system. Try creating one by running sudo dscl . -create /Users/postgres
    – Stratus3D
    Oct 13, 2015 at 22:02
  • 1
    Refer to this answer for more information: stackoverflow.com/a/6815565/1245380
    – Stratus3D
    Oct 13, 2015 at 22:04

1 Answer 1


If the username is not existent, you should not have been able to enter a login session using su. MacOS uses a Directory Service to store and keep track of user accounts. Create the user account (and respective group, as the syntax of chown is chown user:group /path/to/file/or/dir) using dscl and dseditgroup prior to attempting to chown files/directories to it:

sudo dscl . create /Groups/postgres
sudo dscl . create /Users/postgres
sudo dseditgroup -o edit -a postgres -t user postgres

More advanced settings (UIDs, Group description and passwords) are possible too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.