A friend contacted me the other day because he was having an issue starting his development environment which consists of Ruby, PostgreSQL, and Mongrel. Ruby communicates with PostgreSQL using the postgres-pr gem version 0.6.1. Starting things using “ruby script/server” from within his Ruby project had been working for months without issue and there had been no confguration changes to Ruby, Postgres, or Mongrel so it appeared to not be configuration related. After getting a brief explanation of the issue I logged into his laptop and attempted to start the server. Below is the error received when attempting to start the server using “ruby script/server” via a terminal window on the Macbook Pro.
OSX Ruby Script/Server Launch Error:
- users-macbook-pro:project-root user$ ruby script/server
- => Booting Mongrel (use 'script/server webrick' to force WEBrick)
- => Rails 2.1.0 application starting on http://0.0.0.0:3000
- => Call with -d to detach
- => Ctrl-C to shutdown server
- ** Starting Mongrel listening at 0.0.0.0:3000
- ** Starting Rails with development environment...
- Exiting
- /Library/Ruby/Gems/1.8/gems/postgres-pr-0.6.1/lib/postgres-pr/connection.rb:81:in `initialize': FATAL C57P03 Mthe database system is shutting down Fpostmaster.cL1643 RProcessStartupPacket (RuntimeError)
- from /Library/Ruby/Gems/1.8/gems/postgres-pr-0.6.1/lib/postgres-pr/connection.rb:55:in `loop'
- from /Library/Ruby/Gems/1.8/gems/postgres-pr-0.6.1/lib/postgres-pr/connection.rb:55:in `initialize'
- from /Library/Ruby/Gems/1.8/gems/postgres-pr-0.6.1/lib/postgres-pr/postgres-compat.rb:23:in `new'
- from /Library/Ruby/Gems/1.8/gems/postgres-pr-0.6.1/lib/postgres-pr/postgres-compat.rb:23:in `initialize'
- from /Users/user/Documents/code/project-root/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:814:in `connect'
- from /Users/user/Documents/code/project-root/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:814:in `connect'
- from /Users/user/Documents/code/project-root/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:251:in `initialize'
- from /Users/user/Documents/code/project-root/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `new'
- ... 66 levels...
- from /Users/user/Documents/code/project-root/vendor/rails/activesupport/lib/active_support/dependencies.rb:509:in `require'
- from /Users/user/Documents/code/project-root/vendor/rails/railties/lib/commands/server.rb:39
- from script/server:3:in `require'
- from script/server:3
Investigating The Issue:
The above error specified an issue relating to the connection between PostgreSQL and Ruby via the postgres-pr 0.6.1 version gem. I attempted to login to Postgres using psql from a terminal window and was having issues doing this so the problem appeared to be limited to the PostgreSQL server. I next attempted to restart PostgreSQL but it would not restart properly so I started to investigate any stuck Postgres processes or any other processes that may be causing the problem. When looking at the processes running on the laptop I noticed that there was a ton of applications running that had maxed out the resources available on the laptop which had been running for 16 days. Things had basically gotten to the point that even after closing many of the applications the resources were still maxed including memory and CPU.
Resolution:
To resolve the issue I had him save any open items that needed to be saved and then reboot the laptop. After rebooting the laptop everything worked without issue. If we had not been in a hurry we could have accomplished the same goal by closing applications, killing any processes that were stuck, etc. It was just much easier to restart the laptop to clean everything up. Since OSX has a Unix base you shouldn’t have problems like this very often like I do on my Windows laptop which slows way down if I don’t reboot every day. You will however have issues if you are attempting to run multiple instances of 20 different applications and never close anything out.
Comments:
I wanted to write this article to just point out that sometimes when issues can be complicated they can be resolved by the most basic methods. When troubleshooting technical issues it is always best to start off trying the easiest methods to resolve them and verifying resources on your computer is one of the most basic items to review. It is easy to become lost in complex troubleshooting when the issue could be as simple as restarting the computer to provide resources to do what you are trying to do.