2

I opened the rails console and called the DatabaseTable, But it failed. I followed

psql: could not connect to server: No such file or directory (Mac OS X)

I tried to open postgres and I got the error.

$ psql

psql: 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"?

and I called the log to observe what happened.

$ tail -f /usr/local/var/postgres/server.log

FATAL:  database "ror_development" does not exist
ERROR:  database "ror_development" already exists
STATEMENT:  CREATE DATABASE "ror_development" ENCODING = 'utf8'
ERROR:  database "ror_test" already exists
STATEMENT:  CREATE DATABASE "ror_test" ENCODING = 'utf8'
FATAL:  database "harem_backend_development" does not exist
LOG:  received smart shutdown request
LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down

I can't understand what happened to my sql, and how to fix it

2 Answers 2

1

Make sure postgres is running on MacOS.

If you installed postgres using Homebrew, you should be able to start it using brew:

brew services start postgresql

Otherwise, you can start it with:

pg_ctl -D /usr/local/var/postgres start

For more info on how to install and use postgres in MacOS, read this guide.

Setup your Rails database (Rails >= 5)

Once postgres is started, you will be able to setup your Rails database.

To create the database:

 rails db:create

To migrate the database:

 rails db:migrate

To seed the database:

 rails db:seed

To create and seed the database:

 rails db:setup

Finally, to drop (delete) the database:

 rails db:drop

For Rails < 5, replace rails with bundle exec rake in the above commands.

For more info on setting up and configuring a database with Rails, read the Rails Guide.

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

2 Comments

I got new error log waiting for server to start....2017-12-16 06:39:07.180 CST [12387] FATAL: database files are incompatible with server 2017-12-16 06:39:07.180 CST [12387] DETAIL: The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 10.1. stopped waiting pg_ctl: could not start server Examine the log output.
It looks like you have an incompatible version of postgres installed. You may have tried to install it twice. If you can afford to lose the existing databases, you may want to uninstall all versions of postgres and reinstall them.
1

From the log messages it seems your Postgres is not running(It seems to like postgres process is manually killed.) . Try starting Postgres again

pg_ctl -D /usr/local/var/postgres start
psql

1 Comment

I got new error log waiting for server to start....2017-12-16 06:39:07.180 CST [12387] FATAL: database files are incompatible with server 2017-12-16 06:39:07.180 CST [12387] DETAIL: The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 10.1. stopped waiting pg_ctl: could not start server Examine the log output.

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.