Mac OS X: role “postgres” does not exist

  1. Install Postgres

    brew install Postgres
    
  2. Try to log in.

    $ psql -h localhost -d postgres -U postgres  
    psql: error: could not connect to server: 
    FATAL:  role "postgres" does not exist
    
  3. Create the user

     $ /usr/local/opt/postgres/bin/createuser -s postgres 
    
  4. Start the server

    $ pg_ctl -D /usr/local/var/postgres start 
    pg_ctl: another server might be running; trying to start server anyway
    waiting for server to start....2020-06-27 18:12:07.784 +08 [20812]
     FATAL:  lock file "postmaster.pid" already exists
    2020-06-27 18:12:07.784 +08 [20812] HINT:  Is another postmaster (PID 4901)
     running in data directory "/usr/local/var/postgres"?
     stopped waiting
    pg_ctl: could not start server
    Examine the log output.
    

It just works!!

$ psql -h localhost -d postgres -U postgres
psql (12.3)
Type "help" for help.

postgres=#

References

Written with StackEdit.