Wednesday, September 25, 2013

Postgres SQL connection error - Is the server running locally...

I ran into an issue on my Mac Mini today while setting up for a development footprint for a Rails 4 project I'm starting to work on this week.   This new project requires Postgres which I have not used before.  I ran into a snag installing it on my Mac Mini which is running OS X version 10.8.5

I proceeded to use homebrew to install by preforming these steps:

brew update
brew install postgres

In typical fashion the recipe presented some notes about continuing the setup.  The next steps were:

initdb /usr/local/var/postgres -E utf8
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Then I needed to use the postgres client to create a user and new database.  When I issued the command

psql -d template1

I received the following error:

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

The initial indication here is that postgres wasn't running.  This post suggests verifying that by using the command:

ps auxw | grep post

and confirming that postgres was actually running.  In my case it definitely was running.  Several processes were matched.

Then I stumbled across numerous post suggesting that the PATH was set wrong.  That possibly Mac OS X Mountain Lion actually has pre-installed a postgres client that looks in a different place for the connection socket.  I don't know if that's true or not.  However,  unfortunately for me, it turns out that I was actually running an older / different version of the client located in /usr/bin  instead of the newly installed on from homebrew located in /usr/local/bin

You can check by the command:

which psql

and for me that result was /usr/bin

In my case the /usr/bin directory is in my PATH prior to the /usr/local/bin so rather than reverse that (like I probably should) I opted not to have any other surprises by a PATH change and simply copied the new psql client from /usr/local/bin to /usr/local

Hopefully this helps someone recover from this issue quickly.

Tuesday, September 10, 2013

dlload for Highline::SystemExceptions::WinAPI

Ran across an issue with 1.6.19 of the highline GEM recently.  I'm supporting a cross platform development environment for two applications done in RoR.  I'm primarily working on Mac OS X while another developer is working under Windows.  We are using Ruby 1.8.7 on these applications.

I recently updated to a newer version of Capistrano and but when my colleague tried to use this update on her Windows setup she ran into an error starting up WEBrick

... system_extensions.rb:81: undefined method for 'dllload' for Highline::SystemExceptions::WinAPI:Module (NoMethodError)

Several posts suggested to update to a newer Ruby version which isn't currently an option.  It also appears that there will be other issues taking that route anyway.  So instead I opted to downgrade highline to version 1.6.12 which was reported in one post to resolve the issue.

To downgrade just update your Gemfile to use the specific version of highline.

# Force to specific version of highline to fix issue on
# Windows OS with highline version 1.6.19
gem 'highline', '1.6.12'

Then use bundle:

bundle update highline

This should get you up and running again.