Skip to content

Postgrsql problem: could not connect to server: No such file or directory #59

@FlisAnn

Description

@FlisAnn

Problem

After downloading the Legacy code challange I had a problem that I couldn't run the create db command without getting an error

rails db:create

Terminal output:

12:59 $ rails db:create
could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"rails_messaging_development"}
rails aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
.
.
.

One way to spot the problem was running brew service list:

13:46 $ brew services list
Name       Status  User        Plist
postgresql error   AnnFlismark /Users/AnnFlismark/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
unbound    stopped   

Background

In the Legacy Challange, we are to fork a repo and work together. After pulling down to my computer I ran into a problem when trying to create the database so that I could run rspec. We tried starting and stopping PostgreSQL via brew, we were going through folders and files, changing bash, etc. But it was when trying out this commando that the solution was near:

13:49 $ tail -n 10 /usr/local/var/log/postgres.log
2020-11-11 13:49:03.456 CET [8260] FATAL:  database files are incompatible with server
2020-11-11 13:49:03.456 CET [8260] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.0.
2020-11-11 13:49:13.517 CET [8300] FATAL:  database files are incompatible with server
2020-11-11 13:49:13.517 CET [8300] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.0.
2020-11-11 13:49:23.596 CET [8302] FATAL:  database files are incompatible with server
2020-11-11 13:49:23.596 CET [8302] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.0.
2020-11-11 13:49:33.653 CET [8303] FATAL:  database files are incompatible with server
2020-11-11 13:49:33.653 CET [8303] DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.0.
2020-11-11 13:49:43.812 CET [8305] FATAL:  database files are incompatible with server

After that we did the following:
In the root folder:

$ brew postgresql-upgrade-database

Postgres was then updated from 12 to 13. When running brew services we could see that it looked good

13:55 $ brew services list
Name          Status  User        Plist
postgresql    started AnnFlismark /Users/AnnFlismark/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@12 stopped             
unbound       stopped 

Screenshots

Screenshot 2020-11-11 at 14 10 23
Screenshot 2020-11-11 at 14 10 39

How did you try to solve the problem?

  1. Verify that you have the correct version of postgres and if not update it:
$ brew postgresql-upgrade-database

Thanks to @emtalen and @tochman for helping me

Markdown guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions