Unable to create database with rake db:create command

Eaten Taik

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!

Ben Garcia

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!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive