- PostgreSQLZola2014-01-18T00:00:00+00:00https://www.fullstackstanley.com/tags/postgresql/atom.xmlVagrant, RBENV, Rails 4 and PostgreSQL headaches2014-01-18T00:00:00+00:002014-01-18T00:00:00+00:00https://www.fullstackstanley.com/articles/vagrant-rbenv-rails-4-and-postgresql-headaches/<p><strong>Forewarning:</strong> This post is more of a rambling and future reference to myself.</p>
<p>I've been working on a project in Ruby on Rails for a little while and a few days ago I made the mistake of upgrading to OS X Mavericks with the thoughts "What's the worst that could happen?" running through my mind.</p>
<p>Well for some reason the PG gem really doesn't like my computer anymore. Long story short I decided that I would fire up a Ubuntu development environment on Vagrant and well, it has been a difficult ride.</p>
<p>To keep it short. First time around I had many issues.</p>
<span id="continue-reading"></span>
<p>Vagrant was making rails take forever to download. The solution to this can be found here:</p>
<p><a href="https://github.com/rubygems/rubygems/issues/513">https://github.com/rubygems/rubygems/issues/513</a></p>
<p>TL;DR: Add this to your vagrant file and restart it.</p>
<pre data-lang="ruby" style="background-color:#2b303b;color:#c0c5ce;" class="language-ruby "><code class="language-ruby" data-lang="ruby"><span>config.vm.provider "</span><span style="color:#a3be8c;">virtualbox</span><span>" </span><span style="color:#b48ead;">do </span><span>|</span><span style="color:#bf616a;">vb</span><span>|
</span><span> vb.customize ["</span><span style="color:#a3be8c;">modifyvm</span><span>", </span><span style="color:#a3be8c;">:id</span><span>, "</span><span style="color:#a3be8c;">--natdnsproxy1</span><span>", "</span><span style="color:#a3be8c;">off</span><span>"]
</span><span> vb.customize ["</span><span style="color:#a3be8c;">modifyvm</span><span>", </span><span style="color:#a3be8c;">:id</span><span>, "</span><span style="color:#a3be8c;">--natdnshostresolver1</span><span>", "</span><span style="color:#a3be8c;">off</span><span>"]
</span><span style="color:#b48ead;">end
</span></code></pre>
<p>Make sure you <code>rbenv rehash</code> after installing both Ruby and Rails.</p>
<p>After mucking up with Nokogiri and PG dependancies I hit a wall with folder permissions and Bundler.</p>
<p>I decided to start again following this guide:</p>
<p><a href="http://gorails.com/setup/ubuntu/13.10">http://gorails.com/setup/ubuntu/13.10</a></p>
<p>This went much smoother, installing all dependences beforehand. Note that Adding a new Repository to Ubuntu didn't work without first running</p>
<pre data-lang="bash" style="background-color:#2b303b;color:#c0c5ce;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#bf616a;">sudo</span><span> apt-get update
</span><span style="color:#bf616a;">sudo</span><span> apt-get install software-properties-common
</span><span style="color:#bf616a;">sudo</span><span> apt-get install python-software-properties
</span></code></pre>
<p>But besides that everything worked fine. Bundle install worked with no issues which makes me very happy!</p>
<p>My final issue was creating and migrating the database via rake.</p>
<pre data-lang="ruby" style="background-color:#2b303b;color:#c0c5ce;" class="language-ruby "><code class="language-ruby" data-lang="ruby"><span style="color:#ebcb8b;">PG</span><span>::InvalidParameterValue: </span><span style="color:#a3be8c;">ERROR:</span><span> encoding "</span><span style="color:#a3be8c;">UTF8</span><span>" does not </span><span style="color:#96b5b4;">match</span><span> locale "</span><span style="color:#a3be8c;">en_US</span><span>"
</span><span style="color:#a3be8c;">DETAIL: </span><span style="color:#bf616a;">The</span><span> chosen </span><span style="color:#bf616a;">LC_CTYPE</span><span> setting requires encoding "</span><span style="color:#a3be8c;">LATIN1</span><span>".
</span></code></pre>
<p>This was a real pain and seemed to be a default for PostgresSQL conflicting with Rails.</p>
<p>To fix I logged into psql with <code>sudo su postgres -c psql</code> and followed the advise posted by tokhi on Stackoverflow <a href="https://stackoverflow.com/questions/16736891/pgerror-error-new-encoding-utf8-is-incompatible">https://stackoverflow.com/questions/16736891/pgerror-error-new-encoding-utf8-is-incompatible</a></p>
<p>Or alternatively this post: <a href="https://marcinraczkowski.wordpress.com/2013/03/13/fixing-incorrect-postgresql-locale/">https://marcinraczkowski.wordpress.com/2013/03/13/fixing-incorrect-postgresql-locale/</a></p>
<p>Now it all works and hopefully this will resolve any future issues I have with rails deployments!</p>