I'm trying to setup postgres on OSX. I was having problems with a rails app ('cannot connect to database') and reinstalled postgres with homebrew. I cannot issue postgres commands from terminal now though:
$ sudo -u _postgres psql
Password:
psql: FATAL: role "_postgres" does not exist
$ brew list
autoconf libksba openssl python sqlite
automake libtool ossp-uuid rbenv
gdbm libyaml pkg-config readline
libgpg-error mongodb postgresql ruby-build
$ postgresql
zsh: command not found: postgresql
$ psql
psql: FATAL: database "connorleech" does not exist
This command does work though:
$ sudo -u _postgres
usage: sudo -h | -K | -k | -L | -V
usage: sudo -v [-AknS] [-g groupname|#gid] [-p prompt] [-u user name|#uid]
usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U user name] [-u
user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user
name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user
name|#uid] file ...
After I reinstalled postgresql with homebrew my rails app began working with this app/config/database.yml
:
development:
adapter: postgresql
encoding: utf8
host: localhost
database: project_development
pool: 5
username:
password:
Questions:
- How do I issue
postgres
commands from the terminal? - How is rails running an app if I never created a local
postgres
user or database?
sudo -u postgres psql
instead. Or if your OSX user is actually called _postgres:sudo -u _postgres psql postgres
– Zinn$ sudo -u postgres psql
gives error:sudo: unknown user: postgres
– Almeria$ sudo -u _postgres psql postgres
after my password gives:psql: FATAL: role "_postgres" does not exist
– Almeriasudo -u _postgres psql -u postgres postgres
EXPLANATION: postgres has it's own administration for users. Which might differ from the unix user-adminstration. Your OS has named your postgres-user "_postgres"; in pg it is called "postgres". The database "superuser" is also called "postgres". If no username is given when logging on to the DBMS, the DBMS assumes the system-username ( "_postgres" in your case) which does not exist inside the DBMS administration of users. – Zinn