Software

This page provides information on installing the software needed (or recommended) for this class.

Virtual Machine

To make it easier to get the database running for the class, I have set up a virtual machine that includes PostgreSQL pre-configured to be usable for the class. As the project gets running, I will be making sure that this image also contains everything you need to run your project code. It also includes a web interface for interacting with PostgreSQL.

The virtual machine is a small Ubuntu installation that will run on top of your computer’s native operating system. It includes the database server software, as well as a web-based interface.

The following software is included:

Before using the image, you need to install the virtualization environment and tools to run it:

If you are on Linux, you will need to give your user permission to use VirtualBox, by running the following:

$ sudo useradd -a -G vboxusers username

And then logging out and back in again.

Once you have Vagrant and VirtualBox installed, download the Vagrant configuration, and and unpack it. Open a terminal (command prompt or PowerShell on Windows), and run:

$ cd cs4332-vm
$ vagrant up

This will start the virtual machine. You can then connect to the database by visiting the URL http://localhost:9080/teampostgresql.

The postgres user in this image has the password cs4332; use that password when creating new database connections.

PostgreSQL Connections

You can also connect to the database using the command line:

$ vagrant ssh
vagrant@trusty64:~$ psql -U postgres

If you want to connect from a program directly on your computer, rather than the web interface or terminal in the Vagrant box, you can do so. Vagrant is configured to automatically make port 5432, the default PostgreSQL port, on your computer forward to the PostgreSQL server running inside the virtual machine. Client programs can connect to the database almost as if it were running directly on your computer’s operating system2.

If you already have something else listening on port 5432, Vagrant will pick a different port. It will print out the port that it chooses when you run vagrant up. For example:

$ vagrant up
==> … elided lines …
==> default: Forwarding ports...
    default: 5432 => 2200
    default: 22 => 2222

In this case, I can connect to the Vagrant server on port 2200 rather than 5432.

Once you are done using the virtual machine, you can shut it down with vagrant halt. You can completely delete the VM, and all your data, by running vagrant destroy. All Vagrant commands must be run from the directory where you unpacked the Vagrant configuration (the one containing the Vagrantfile).

Additional Tips

Other Virtualization Packages

If you are using a Mac and already have Parallels, you do not need VirtualBox. Instead, once you have installed Vagrant, run the following to set up Vagrant to work with Parallels:

$ vagrant plugin install vagrant-parallels

If you have VMware and want to use that, the virtual machine will work, but requires the Vagrant VMware provider that costs $79.

It may be possible to get the box running with libvirt/KVM on Linux, but I have not yet successfully done so.

PostgreSQL

The most important piece of software for this course is PostgreSQL, the database engine we will be using for most of our work.

Each of you should have an account on the CS department’s PostgreSQL server, which you can access either from the lab computers or through a remote access host. You may also want to install PostgreSQL on your own computer.

TeamPostgreSQL

If you want to use your own PostgreSQL or the department’s PostgreSQL server, you can download and install TeamPostgreSQL yourself.

  1. Download the cross-platform archive from http://www.teampostgresql.com/download.jsp
  2. Unzip the archive
  3. At the command line, cd into the directory where you unpacked the archive
  4. Run the teampostgresql-run script. On Windows:

    C:\Users\user\teampostgresql> teampostgresql-run

    On Mac or Linux:

    $ /bin/sh teampostgresql-run.sh

  5. Point your browser to http://localhost:8082/teampostgresql/
  6. Create a new database connection. For the department server, use the following connection information:

    Host
    postgres.cs.txstate.edu
    User
    your NetId
    Password
    Password from your initial account e-mail

    Click the ‘Advanced’ button, turn off the ‘discover database’ checkbox and connect to the database named after your NetId

Database GUIs

Besides TeamPostgreSQL, there are several GUI applications available for working with databases in general, and PostgreSQL in particular. The PyCharm and IntelliJ IDEs have built-in database support, that I will be using in some of my class demonstrations. You may also find pgAdmin useful.

PyCharm

You can use any editor you want in order to work on the project and class assignments. Vim, Emacs, Sublime Text, JEdit, whatever.

One very nice development environment is [PyCharm][] from JetBrains. Download it, and then look in the forums for the classroom license key.

If you have IntelliJ IDEA Ultimate Edition (the for-pay version of their Java IDE), it includes PyCharm and the excellent database support as a plug-in.

Python

If you would like to install Python on your local computer, rather than just using it in the Vagrant image, you need the following pieces of software:

Mac Install

Mac OS X already has Python installed. You can install the packages directly using easy_install from a terminal:

$ sudo easy_install psycopg2
$ sudo easy_install flask

However, I recommend using Homebrew and brew-pip:

$ xcode-select --install
$ curl -o brew-install.rb https://raw.githubusercontent.com/Homebrew/install/master/install
$ ruby brew.rb
$ brew install brew-pip
$ brew install postgresql
$ brew pip psycopg2 flask ipython

You will also need to edit the file ~/.bashrc to include the following line:

sh export PYTHONPATH=/usr/local/lib/python2.7/site-packages

Linux Install

Python should already be installed on most Python distributions. Psycopg2 and Flask are available either from your distribution’s repositories (recommended), or via pip.

For example, on Ubuntu:

$ sudo apt-get install python-psycopg2 python-flask ipython

Windows Install

To install on Windows requires downloading several installers:

  1. TeamPostgreSQL is free to use but is not open-source. Therefore, the virtual machine configuration downloads the distribution and installs it rather than directly including the software. See the license by running vagrant ssh and then cat /srv/teampostgresql/license.txt.

  2. There is one caveat: Unix and Mac programs try to connect over something called a unix domain socket, which doesn’t work to connect to the virtual machine. You must tell the program to connect over TCP (specifying the IP address, 127.0.0.1, instead of localhost may do this).