1

I have a rails app that I am trying to run tests on. The day before I was able to run rake test:all successfully and everything was in perfect order. Today, when I run rake test:all I receive this error:

enter image description here

I know what this error means and know how to solve this error based on pg_hba.conf connections etc. etc. I've done it time and time again and have no problems with it.

However, I've found that the real underlying problem is that my Postgresql has been upgraded to 9.4 but my application requires 9.3. Running brew info postgresql gives me the output shown below:

enter image description here

Basically, the output is saying that I need to upgrade to 9.4 and that 9.3 specific configurations are no longer updated (also shown below)

enter image description here

So now with the background info out of the way, this leads towards my real question. What is the 'correct' way to resolve this?

As a relatively new ruby/rails developer and programmer in general, I've always had someone to assist with installing my environment and have never really dove deep into the system installation layer and what happens under the hood. I know that I can't and shouldn't put this off any longer so after reading a few articles pertaining to the subject, this is what I've come across.

Homebrew demystified

RVM Demystified

Official Bundler site

How to install Ruby on Mac

And a few stack overflow questions related to the subject.

What is the difference between all of these in relation to my Postgresql problem?

For example, based on the article from Homebrew, by running brew info postgresql, I can deduce that someone installed postgresql onto my Mac and somehow now I have 9.4 instead of 9.3 (despite to my knowledge never typingbrew update or upgrade`)

So does this mean PGSQL is installed on my MAC system? What about the Gemfile and Gemfile.lock?

According to the bundler documentation.....

Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.

Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install.

If that is the case, why isn't my bundle install resolving the discrepancy? Isn't the pg 0.18.1 supposed to install PGSQL for me? Why do I have to brew install postgresql and bundle install postgresql?

To make things even more confusing the bundler documentation states that in order to use bundler you have to execute gem install bundler. What is this gem install command, how is it different than the rest and why can't I brew install bundler?

(I know that brew has no bundler formula to install, but theoretically why couldn't do this?)

Once again, in the 'Why you should use RVM and How to install Ruby on MAC', the guide states that RVM is used to install multiple versions of Ruby making it easy to switch around between versions, and to install gems I need to run gem install. But why do I need to do this if bundle install does this for me? Why would I ever use bundle install if I can use gem install?

I know there's a lot of questions in this post, but an explanation would be great so I can understand what to do with this Postgresql problem I'm having. In my eyes, I either have to dump all my 9.3 data into 9.4 or somehow figure out how to downgrade back to 9.3. This would be easier if I knew what these moving parts are doing to determine how to approach this.

A million thanks before hand for anyone willing to answer this. I know I should have learned this a while ago but later is better than never. Much appreciated!

Dan Rubio
  • 4,709
  • 10
  • 49
  • 106
  • What's up Rubio! Are you ok to migrate all your databases to 9.4? – Anthony Feb 17 '15 at 19:03
  • Anthony, my friend! Long time. I want to say yes that I can upgrade to 9.4 but I'm not entirely sure, I need to check with my team mates but they're all on vacation except for me lol. Anyways, if upgrading to 9.4 will fix the problem, I'll do it. Like I've said in my post though, I don't really know how that will fix things in the larger picture. Usually when I have these problems, I go for the quick fix but this time around I feel like I should know what I'm doing. You think upgrading is the way to go? – Dan Rubio Feb 17 '15 at 19:09
  • Hey Anthony, I think I got it now. Thanks for the quick reply btw and I hope you're living the dream over at NC! – Dan Rubio Feb 17 '15 at 19:29
  • Thanks buddy - see ya around! – Anthony Feb 17 '15 at 19:30

1 Answers1

5

You have a lot of questions here and I'll try my best to give an overview of all the moving pieces here as well as some solutions to solve your psql problem.

First, some background:

Ruby gems

These are packages that contain ruby code that you want to be used by your application ex. rails, psql, bundler. In the case of the postgres gem, you are installing a library that connects to postgres. This gem does not install postgres for you. To install gems, you can run gem install gem_name.

Bundler

A library that essentially calls gem install gem_name for you for each one of the gems listed in your Gemfile. It checks each of your gems dependencies and attempts to intelligently use the versions that you specify or that other gems require.

RVM

Imagine you working on 2 projects. The first is a legacy application that uses ruby 1.8.7 and the other is a new pet project you are working on that uses ruby 2.2. The legacy application has lots of gem dependencies that may or may not work on the newer ruby versions so you want to isolate your environments for each ruby version. RVM allows you to have as many ruby versions installed as you need them, each with a separate environment. Imagine RVM to be akin to a virtual machine. You want to have Mac OSX and linux both installed on your computer, but you want them to be 'separate' so they don't butt heads.

Homebrew

An application that allows a somewhat easier way to install packages on your Mac. Generally speaking, ruby gems can only contain ruby code so what happens when you want to install postgres, which I'll assume is written in C? You can have homebrew install it for you with brew install psql.

Back to your problem at hand:

You correctly installed postgres via homebrew and ran bundler to install all the gems necessary to run your project (including the psql gem). Your problem is that you have a project that stored data with postgres 9.3 but at some point you upgraded your postgres version to 9.4. You have 2 options:

If the data you had was important to you you can use the pg_upgrade utility to transfer the 9.3 data to your 9.4 installation.

If your data doesn't matter you can just use homebrew to delete the postgres installation and install a fresh copy which should work out of the box.

Josh
  • 5,631
  • 1
  • 28
  • 54