I had postgresql service running but when I run rake db:create
it abort the rake and throws error
ActiveRecord::NoDatabaseError: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database “chat_development" does not exist
In my database.yml
I have
development:
<<: *default
database: chat_development
By running the rake command it should create the database but it didn't. I did a lot research and try out the solutions given but nothing work. I did check on this discussion here but when I run rm /usr/local/var/postgres/postmaster.pid
it throws error
rm: /usr/local/var/postgres/postmaster.pid: No such file or directory
If I run command ps auxwww | grep postgres
it will show /opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres
If I remember correctly I had issue with the postgres installation when I was getting started (about 4 weeks ago) and did install using Postgres.app, then I had also installed with brew install postgresql
(since I am using mac). I am not sure if there are conflict due to multiple installation.
But just now I uninstalled postgres.app and also ran gem uninstall pg
and re-install using command gem install pg -- --with-pg-config=/usr/local/bin/pg_config
(ref here)
The issue is still there. I don't know what to do anymore. Glad if someone can help. Thank you!
Had this issue and never quite figured out why rails was doing this, but below should fix it.
psql template1
CREATE USER <username from config/database.yml if specified> with password '<password from config/database.yml if specified>';
ALTER USER <username ...> WITH SUPERUSER;
CREATE DATABASE chat_development WITH OWNER = '<username ...>';
CREATE DATABASE chat_test WITH OWNER = '<username ...>';
you don't need step 2/3, or the WITH OWNER = '<username>';
unless you specify a user/password in config/database.yml
.
Some common mistakes, pay close attention to where I have put single quotes, and don't forget the semi-colons!