1

Full error is:

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


pg (1.2.3) lib/pg.rb:58:in `initialize'
pg (1.2.3) lib/pg.rb:58:in `new'
pg (1.2.3) lib/pg.rb:58:in `connect'
activerecord (6.0.2.2) lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:889:in `new_connection'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:933:in `checkout_new_connection'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:912:in `try_to_checkout_new_connection'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:873:in `acquire_connection'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:595:in `checkout'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:439:in `connection'
activerecord (6.0.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:1121:in `retrieve_connection'
activerecord (6.0.2.2) lib/active_record/connection_handling.rb:238:in `retrieve_connection'
activerecord (6.0.2.2) lib/active_record/connection_handling.rb:206:in `connection'
activerecord (6.0.2.2) lib/active_record/migration.rb:562:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.2) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.2.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.2) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.2) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.2) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.2.2) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.2.2) lib/rails/engine.rb:526:in `call'
puma (3.12.4) lib/puma/configuration.rb:227:in `call'
puma (3.12.4) lib/puma/server.rb:675:in `handle_request'
puma (3.12.4) lib/puma/server.rb:476:in `process_client'
puma (3.12.4) lib/puma/server.rb:334:in `block in run'
puma (3.12.4) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

I tried rm the postmaster.pid but then it prints no such file. I also tried restarting postgresql multiple times but it keeps printing the same exact error. I know that there is not much thats all the info I have regarding the problem

diego
  • 409
  • 4
  • 12
  • What platform? Versions? Have you rebooted the entire system? Can you you run `psql` and connect? Please read the guidelines on how to ask questions. – Beartech Apr 30 '20 at 02:13
  • 1
    I had a similar issue, just posted my solution [here](https://stackoverflow.com/a/64020320/5725619). – Ben Sep 23 '20 at 02:49

2 Answers2

3

I will send you some steps that help me with this issue:

  1. CHECKING POSTGRES STATUS AND RUNNING PORT (if it is on 5432):

Ubuntu/Linux Distros (Terminal):

$ pg_lsclusters

or

$ systemctl status postgresql.service

or

$ service postgresql status

Windows:

Ctrl+R type services.msc

You should find the postgres status and the port which it is running

  1. STARTING POSTGRES SERVICE:

Ubuntu/Linux Distros (Terminal):

$ systemctl start postgresql.service

or

$ sudo service postgresql start

Windows

Ctrl + R type services.msc find your postgres service and just start it.

  1. CHECKING AND CREATING USER ROLE ON POSTGRES

    First connect to the database:

    $ sudo su postgres

    $ psql

Then check if your role is created with the command:

$ \du

If it's not created yet you can create by using:

$ CREATE role name_of_your_role_here WITH createdb login password 'your_password_here';

After that you could try again to connect to the database:

don't forget to use

rake db:create
rake db:migrate

and configure database.yml file on your application

  1. Change Client Authentication Method on PG_HBA.CONF

You can see more details of it right here: pg_hba.conf

You would probably use md5 password method or no auth at all for tests purpose

To do that, you could change the METHOD column of your localhost from peer(default) to md5

You can find this file on:

LINUX DISTROS:

cd /etc/postgresql/your postgres version here/main/pg_hba.conf

WINDOWS:

C:/Porgram Files/PostgresSQL/your postgres version her/data/pg_hba.conf

Option method with simple user/password:

TYPE  DATABASE        USER            ADDRESS                 METHOD

IPv4 local connections:

host  all             all             127.0.0.1/32            md5 <= CHANGE HERE

Option method with no Password:

TYPE  DATABASE        USER            ADDRESS                 METHOD

IPv4 local connections:

host  all             all             127.0.0.1/32            trust <= CHANGE HERE
despin
  • 94
  • 1
  • 7
0

Windows 10

In my case, PostgreSQL Server wasn't running so I had to start it as follows:

  1. Open the Run app
  2. Type services.msc
  3. Find postgresql-x64-13 - PostgreSQL Server 13 (Its description is: Provides relational database storage.)
  4. Right click, and select Start
almawhoob
  • 382
  • 3
  • 5