Apple, Computers, Linux, Open-source, Ruby, Software, Thoughts, Web

PostgreSQL for Ruby on Rails on Ubuntu

My new desktop came in at work this week, and the installation was painless thanks to the great driver support of Ubuntu 11.10. For anyone setting up a Rails development box based on Linux, I have some tips to get around some pain points when using a PostgresSQL database.

Installation:

Postgres can be quickly and easily installed using apt-get on Debian or Ubuntu based distributions. Issue the command:

apt-get install postgresql

Ruby Driver

In order for Ruby to connect to PostgreSQL databases, you will need to install the pg gem. This gem will need the development package of PostgreSQL to successfully build its native extension. To install the PostgreSQL development package, issue the following command:

apt-get install libpq-dev # EDIT: postgresql-dev was replaced by this package on Ubuntu 11.10

Setup A PostgreSQL Role

You can configure PostgreSQL to allow your account to have superuser access, allowing your Rails tasks to create and drop databases. This is useful for development, but is strongly discouraged for a production. That being said, we can create a PostgreSQL role by logging into psql as postgres as follows:

su postgres -c psql

This will open a PostgreSQL prompt as the database owner postgres. Next, we need to create an account for our user. This should match the response from “whoami”:

create role  superuser login;

We can now exit from psql by issuing “q“. Try to connect to psql directly by issuing the following command from your shell account:

psql postgres

This should allow you to connect to the default database postgres without being prompted for credentials. You should now be able to issue the rake commands for creating, and dropping the database:

rake db:create

Rspec Prompts for Credentials

I was being prompted by Rspec for credentials when running my test suite. If you would like to remove this credential prompt, please read the following:

There are differences in how the PostgreSQL package is configured in Homebrew on OS X, and how it is packaged in the Ubuntu and across other distributions. One difference is in the level of security configured in the pg_hba.conf file. This file is responsible for identifying which sources using which authentication mechanisms should be allowed or denied. By default, Rspec will cause a prompt for a password even if your shell account has trusted permissions. This is because Rspec connects not as a local process, but to localhost. To allow connections to localhost to be trusted, you will need to modify the pg_hba.conf file.

Next, we can modify the pg_hba.conf file located at /etc/postgresql/<version>/main/pg_hba.conf

Comment out the lines any lines at the bottom of the file and append the following:

local   all             all                                      trust
host    all             all              127.0.0.1/32            trust
host    all             all              ::1/128                 trust

This will allow connections from the shell, as well as connections to 127.0.0.1 (localhost) using both IPv4 and IPv6.

You will need to restart PostgreSQL for the changes from this file to take affect:

/etc/init.d/postgresql restart

PostgreSQL Extensions

If you want to make use of any of the additional extensions to Postgres, including fuzzystrmatching, you will need to install the postgresql-contrib package:

apt-get install postgresql-contrib

The extensions will install to /usr/share/postgresql/<version>/extension/

Using the Postgres version 9, you can create these extensions in your database by using the new CREATE EXTENSION syntax. In the case of the fuzzystrmatch extensions, you can issue the following command from inside a PostgresSQL command prompt to load the extensions:

psql ;

Once inside your database:

create extension fuzzystrmatch;
Computers, Hardware, Linux, Open-source, Software, Web, Windows

Its Almost Here

Laptopmag.com has just reviewed a pre-production unit of the Dell Inspiron Mini 9. It seems pretty impressive, with the following specs:

  • $349 base pricetag
  • 1.6-GHz Intel Atom processor
  • Tailored version of Ubuntu (or Windows XP)
  • 9.1 x 6.8 x 1.3 inches
  • 2.3 lbs
  • 8.9 inch 1024 x 600-pixel resolution
  • 1.3-megapixel webcam
  • 3 USB 2.0 slots, , VGA out, Ethernet, headphone and a microphone jacks, 4-in-1 memory card reader
  • Bluetooth and wireless G (with Mobile broadband)
  • 4GB solid state drive (also available with a larger 8GB and 16GB SSD)
  • 3 1/2 hour battery

Looks pretty tasty…

Computers, Hardware, Linux, Open-source, Personal, Software, Thoughts, Windows

Ubuntu – How I Have Missed You…

Since I started working in Administrative Systems, I have been tasked with supporting a myriad of Windows-only applications. I assumed that it would be close to impossible to try and continue running any form of Linux on my work machines – especially with my boss popping in my office and telling me to pull up application X at any given second.

However, now I am tasked to work with Solaris about 90% of my day and I have to say that despite how great Putty can be – it just isn’t the best solution. Nothing beats a native terminal connection. Especially given that Windows doesn’t know jack about any filesystems other than its own. This makes editing files on the Solaris machine difficult and slow.

Slowly Linux started creeping back into my mind, and it made me homesick everytime I would go visit Scott and Chris over in VS (Well that problem took care of itself…). I have had much time to ponder how feasible a switchover would be (and what I would need to take care of as prerequisites) and I came up with a list of issues I would have to resolve first:

  1. Where can I place files that would be common to both Windows and Linux?
  2. How could I synchronize my email clients, and web browsers (history, bookmarks, passwords)?
  3. How can I access Windows applications if there is no other alternative?

These issues required some research on my part, but I finally found the following solutions:

  • ntfs-3g:  This particular piece of software is the read/write driver for NTFS partitions for Mac/Linux.  am counting on this to read/write data on the NTFS partition. It has matured so much recently that the latest version of Ubuntu can be installed inside the Windows NTFS partition. Condition #1 satistied – the files can stay where they are.
  • Mozilla Thunderbird / Mozilla Firefox: The Mozilla corporation did something so clever I have to applaud them (*clap clap clap*) – they made all application data, as well as settings reside in a profile folder. On Windows, Firefox is located at “C:Documents and Settings<user>Application DataMozillaFirefoxProfiles<profile instance>”. In Linux, this is located at “/home/<user>/.mozilla/firefox/profiles/<profile instance>”. Mozilla Thunderbird is essentially the same. The applause is becase the settings are the same on any OS! I placed the folders on the Linux partition by symlinking them to the Windows partition. Condition #2 satisfied – Email and Web browsers are always in sync because it is the same instance.
  • VMWare Server: No surprises here – this kind of software is a dime a dozen today. However VMWare offers a feature where with a bit of configuration the Operating System you can run can be the physical partition of your existing Windows partition. Pretty slick – that is after Windows throws a bitch fit that its configuration has been change and you absolutely positively must activate it again. The solution for that is to create a seperate hardware profile for Windows (a configuration that Windows made mandatory because of its bitch fits). Condition #3 satisfied – if I need Windows I can just flip over to Workspace 4 (I named it hell) and Windows is waiting for my input.
Computers, Linux, Open-source, Software, Thoughts, Windows

Thoughts on Hardy Heron’s Release

An interesting quote from Mark Shuttleworth:

Most people would assume that precise release management would depend on having total control of all the moving parts – and hence only be possible in a proprietary setting. Microsoft writes (almost) every line of code in Windows, so you would think they would be able to set, and hit, a precise target date for delivery. But in fact the reverse is true – free software distributions or OSV’s can provide much better assurances with regard to delivery dates than proprietary OSV’s, because we can focus on the critical role of component selection, integration, testing, patch management and distribution rather than the pieces which upstream projects are better able to handle – core component feature development.

Computers, Linux, Open-source, Personal, Software, Thoughts, Web, Windows

The Obligatory Ubuntu 8.04 Post

You knew this was coming the day you saw the counter in the right hand column of my blog. I jumped at the opportunity to download the final product tonight. Bittorrent is really the best option for download at this point because the number of seeders are in the thousands.

If you have never tried / setup Linux do yourself a favor and download this version of Ubuntu now. This release includes a Windows installer (codename “Wubi”). I mounted my .iso file from the link previous into Daemon tools, and clicked on “Install” in the autorun screen. This installs Ubuntu into your Windows NTFS partition the same as any other application. You type in a password to use for the account, and you are ready to install!

Wubi Instlaler

When the computer restarts, you have a new boot option for Ubuntu, the same as if you had a combination of Windows 2000/XP/Vista on your machine. The initial boot launches a streamlined setup where I answered a grand total of zero questions. After about 10 minutes of hardware detection and configuration, I was sitting on the login screen with a fully working system. This means that the entire setup from mounting the .iso to sitting on a Linux desktop took less than 15 minutes!

Congratulations Ubuntu for bring your A game out with this release!

FYI: Everything else is shaping up to be quite sexy too…

Computers, Linux, Open-source, Software, Web, Windows

Ubuntu: connect to MySQL from remote host

Just a quick gotcha that I always stumble upon in Ubuntu. By default, the MySQL database is set only to listen to requests on the localhost (for security reasons). If you want to connect to the database remotely, say using MySQL Admin GUI Tools, you will need to make a quick change.

First run this to edit the MySQL config file with root permissions:

sudo vim /etc/mysql/my.cnf

Next, look for the property “bind-address” (press “/” in VIM to start a search). In Ubuntu server 7.04 it is on line 47 but this is total subject to change. Instead of it reading 127.0.0.1, change it to the static IP of the server. In most *nix distributions, this can be found by running “ifconfig”. My server configuration line now looks like this:

bind-address = 168.28.245.99

All that remains is to give the MySQL database a quick restart to apply the change:

sudo /etc/init.d/mysql restart