1

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!

2 Answers 2

5

Had this issue and never quite figured out why rails was doing this, but below should fix it.

  1. in terminal psql template1
  2. CREATE USER <username from config/database.yml if specified> with password '<password from config/database.yml if specified>';
  3. ALTER USER <username ...> WITH SUPERUSER;
  4. CREATE DATABASE chat_development WITH OWNER = '<username ...>';
  5. 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!

Sign up to request clarification or add additional context in comments.

1 Comment

Hi thank you for the solution. I can create the database with these steps.
0

In order to solve this problem, you need progress this in step-by-step fashion.

  1. Run the postgresql server
  2. Test creating a sample database using a simple client like psql, which should show whether the server is running and you have the right socket/port connection and user credential with authorization
  3. Check your application configuration to see if you have the correct connection and user credential setup

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.