April 27, 2014 by Daniel P. Clark

/var/run/postgresql/.s.PGSQL.5432 with a Virtual “var” Folder

Well if you’re reading this you’ve likely run into a problem with accessing your postgresql DB.  Whatever your situation this information should be useful for you. In my case I’m using it with Rails.  And this is the Rails error I received:

PG::ConnectionBad

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?

Just so you know.  This is not a Rails related problem.  It is postgresql related.  I happen to work on a netbook with a 8GB SSD drive built in (first of it’s kind).  Seeing as how space is limited and SSD’s do wear out after so much use I’ve taken proactive measures to protect my drive.  So may /var and /tmp directory are virtual drives and stay in memory. Note: the info I will provide should help you regardless. But if you want more context of other kinds of system state that cause this problem see this forum thread http://ubuntuforums.org/showthread.php?t=869080 Now any system command such as ‘psql’ would produce the same kind of error

The command that will inform you of your troubles is /etc/init.d/postgresql

So I tried it with the status option and got Running clusters:.  Then I tried the force-reload option and got this error:

So to fix this I had to do the following:

Note: you need to start the service as the postgres user, which is why the sudo su postgrescommand was included.  After this everything works! ^_^  Of course since this is only a temporary fix what needs to be done is to add the folder creation of /var/log/postgresql to the bootup script as well as creating the file postgresql-9.1-main.log with postgres ownership.  This should all be done before the service starts on bootup. Most of you won’t have my particular case of the var directory being a virtual drive and wiped at every reboot.  But this info is still useful.  Use the /etc/init.d/postgresql command for figuring out what’s going on.

And NOW this is how I modified my system startup to have my system work each reboot.

pico: Is a command line text editor, originally called pine from the alpine package.  It is also aliased with nano.  You can use any text editor, just make sure you sudo.  Go down to the line that has start() { and on the first line after that enter the following:

And now every time your system boots up the appropriate log file will be there and PostgreSQL works.  ^_^

Please comment, share, subscribe to my RSS Feed,and follow me on twitter @6ftdan!

God Bless! – Daniel P. Clark

#error#linux#postgresql#socket#ssd#virtual drive

Leave a Reply

avatar
  Subscribe  
Notify of