Friday, April 22, 2016

Software and Sharp Tools


In software, we are often tempted to use the most powerful, most flexible, most adaptable tool available. It might be more expensive, more complex, more error-prone, harder-to-debug, etc. But hey, we think, we're smart and careful and we're not afraid to use sharp tools to get the job done.

In the world of electonics, a soldering iron is the ultimate "sharp tool". It allows you to connect anything to anything.  But, when was the last time you used a soldering iron to connect your computer to a network cable, USB cable, video cable, power cable, speaker cable, etc? When was the last time you soldered a new video card or RAM board into your computer? The answer is "never". Outside of specialized applications (e.g. research & manufacturing), one never solders components together. At the user level (& even systems assembly), it is always better to have well-defined and unambiguous pluggable interfaces. I cannot accidentally mix up my USB cable and my power cord. I need not worry about getting my video card and memory cards mixed up plugging them into the motherboard. I don't have to worry about reversing the power and data cables to my disk drive.

Similar unique and "type-enforcing" interfaces are used in most other areas where humans can combine simpler elements, including light bulbs & sockets, plumbing pipes & fittings, hardware nuts & bolts, car keys & ignition switches, even CD/DVD disks vs LP, cassette, 8-track (the idea of a unique interface type isn't very new).

While nothing involving humans can ever be guarenteed 100% correct, simply preventing the obvious errors (e.g. power cable <-> USB plug) will eliminate 99.9% of the problem.  Shouldn't software take advantage of this simple idea?

Friday, January 8, 2016

Installing PostgreSQL 9.5 on Ubuntu/Kubuntu 15.10 (Wily)

The Ubuntu packages for PostgreSQL 9.5 have been released, but the installation instructions on postgresql.org are a little unclear.  After googling to a very helpful blog post (thanks Raony Cardenas!) and some experimentation, here is the succinct version:

    > sudo vim /etc/apt/sources.list.d/pgdg.list

add a line for the repositorydeb 

    > http://apt.postgresql.org/pub/repos/apt/ wily-pgdg main 

The mystery bit is the name "wily-pgdg"  The first part (wily) should match your Ubuntu release.  You can find out the correct name by using:

    > lsb_release --all
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 15.10
    Release: 15.10
    Codename: wily

Import the repository signing key, and update the package lists (cut & paste the following 3 lines)

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

sudo apt-get install -y postgresql-9.5

The last line (with "install") is the one that was missing; everything before that just provides the settings to access the postgresql.org Ubuntu package libraries.

At this point, you should be able to see both your old version of postgresql and the new 9.5 version:

    > alias d="ls -ldF"
    > d /etc/postgresql/*
    drwxr-xr-x 3 postgres postgres 4096 May 26  2015 /etc/postgresql/9.4/
    drwxr-xr-x 3 postgres postgres 4096 Jan  8 08:49 /etc/postgresql/9.5/

If you still have PostgreSQL 9.4 installed (as above), the new 9.5 will not be on the default port of 5432, but will instead take the next one (5433).  You may wish to edit your postgresql.conf to both rearrange the ports (I put the old postgresql on 5439 and the new one on 5432) and also to copy over any modifications to the parameters you have made:

    > sudo vim -d /etc/postgresql/*/main/postgresql.conf

You will also want to copy over any changes to pg_hba.conf:

    > sudo vim -d /etc/postgresql/*/main/pg_hba.conf    

At this point, all you need to do is restart both servers, and away you go!

    > sudo systemctl restart postgresql
    > psql --version
    psql (PostgreSQL) 9.5.0

Try to log in:

      > psql
   psql: FATAL:  role "alan" does not exist

Doh!  We forgot to create our users for the new install:

    > sudo -u postgres createuser alan 
    > sudo -u postgres createdb   alan

Viola!  Now it works:

    > psql
    psql (9.5.0)
    Type "help" for help.
    alan=> select version();
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 9.5.0 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010, 64-bit
(1 row)

alan=> \q

Enjoy!!!