A few day ago I was struggling with some strange (for me as a beginner) problem with PostgreSQL database during generate some application skeleton. Running some: rails new app —database=postgresql and after that: rake db:migrate or rake db:create cause the fallowing problem:

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"=>"Library_development"}
rake aborted!

I restart also database but the problem still appears. So I start to looking for some answer. First I check if my database it’s running, to perform some simple check:

ps auxww | grep postrges

This simple command should display all processes that are running and also connected with PostgreSQL, but of corse, in my case, output was totally different. PostgreSQL was not running at all:

andrzejdubaj     19418   0,0  0,0  2442020    896 s003  S+   12:43     0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn postgres

I have PostgreSQL data files from a previous version of PostgreSQL and they are not compatible with current one. One solution was to delete all data and get a fresh database, basically to wipe data from PostrgreSQL completely including the user and data files.

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

After that:

rake db:setup

and

rake db:migrate

from my rails application to get setup again. Next step was to check if my changes work as intended:

ps auxwww | grep postgres
andrzejdubaj 20785 0,0 0,0 2432804 852 s003 R+ 12:54 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn postgres
andrzejdubaj 20782 0,0 0,0 2476704 664 ?? Ss 12:54 0:00.00 postgres: stats collector process
andrzejdubaj 20781 0,0 0,0 2630920 1548 ?? Ss 12:54 0:00.00 postgres: autovacuum launcher process
andrzejdubaj 20780 0,0 0,0 2622728 804 ?? Ss 12:54 0:00.00 postgres: wal writer process
andrzejdubaj 20779 0,0 0,0 2621704 840 ?? Ss 12:54 0:00.00 postgres: writer process
andrzejdubaj 20778 0,0 0,0 2621704 776 ?? Ss 12:54 0:00.00 postgres: checkpointer process
andrzejdubaj 20776 0,0 0,1 2613768 14044 s002 S+ 12:54 0:00.02 postgres -D /usr/local/var/postgres

First process that is displayed gere is a masterserver process. The command shown for it are the same ones given when it was launched. Next two ones are the bacground workers processes launched automatically by the master process. Each of the remaining processes is a server process handling one client connection.

So I we can see this simple solution resolve problem with database on version 9.5.


Reference:

  1. PostgreSQL Documentation – Standard Unix Tools
  2. PostgreSQL Documentation – pg_upgrade