What Went Wrong With Postgres

The Beginnings

A couple of days ago I started at my job working for the up and coming ventured back Quottly! It’s a starting intern position and I am incredibly excited to for them. For me it’s more than just a job, it means progress and growth from when I started a little over a year ago with my first ever programming book. I remember opening the first few pages of that programming book while there was some down time at my waitressing job. A customer has just turned my day from okay to miserable with a few nasty comments and I remembered the book that had been given to me by my good friend James when I had shown some interest in what he did for a living. I had at first taken it a little skeptically, thinking that someone like me could/would never learn to program, that it was already too late for me to start. But after glaring at the customer who had just left I was ready to try to do anything to get out of ever waiting another table again. If there was one thing I knew, it was that I had way too little patience and too much pride to wait on tables for the rest of my life.

Sixth months later I quit my waitressing job to focus on programming and to live life as a broke college student. Seven months later I got hired as a Developer Intern at Quottly, working for the same friend who had given me the book in the first place. I had often come to Quottly’s office to work on self-teaching programming books that James had given me or that I had downloaded from various sites after working hours. I would stay up until late at night and would drink copious amounts of coffee until I had learned just enough to get started. Now that my foot is in the door I am hoping that nothing will hold me back!

That enthusiastic attitude that I had my first day nearly died earlier today once faced with the task of setting up. What is it about setting up the workspace that always takes me forever? In the very beginning, it was issues with Git, then it was issues with Rails servers, and today, it was an issue with postgres.

It appeared that setting up a Development Environment on OSX would be easy enough. I doubled check to make sure I had Homebrew up and working

$ brew --version

Used RVM to install the correct Ruby version and then… came the trouble. Installing postgres can be very simple if everything is going right (which it rarely does for me);

$ brew install postgres

Then launch the following commands;

$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

It appeared to be installing properly, everything looked nice, green, and working. Then there was this message right under a few paragraphs;

...fixing permissions on existing directory /usr/local/var/postgres ... initdb: could not change permissions of directory "/usr/local/var/postgres": Operation not permitted

hmmm. The first few times I tried installing and re-installing postgres (after failure to migrate) I hadn’t noticed the message. If this message goes unnoticed, you’re not able to rake db:create db:migrate db:seed. When I tried to rake db:migrate with the above mentioned error, I a long block of code (this is just the snippet);

…/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in initialize' /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:innew' /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in connect' /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:329:ininitialize' /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new' ….. ……

Yikes!

A teammate suggested typing;

$ psql

and I received back;

...Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432

Fishy stuff. That at least got us on the right track. At this point I had uninstalled and re-installed postgres multiple times to no avail. The files existed for postgres! I check them multiple times at

$ ls /usr/local/var/postgres/

But it still wouldn’t work. Then, I did something that I should’ve done from the very, very, very beginning. Would have saved me and others hours. I went to the troubleshooting link that was in the message sent to me after installing postgres;

https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Troubleshooting.md#troubleshooting

It was there that we realized that we had a failure with permission errors.

$ sudo chown -R $(whoami) /usr/local and changing it to my username fixed everything!

Now it’s time to get to work!

Comments