Skip to content

Setting up PostgreSQL

ArthurClemens edited this page Aug 29, 2012 · 4 revisions

We assume you have followed the instructions in Setting up a virtual machine, using VirtualBox and Vagrant. If you use a different system, you will probably have a newer version of PostgreSQL.

We refer to the working machine as "host" and the Ubuntu client inside the virtual Vagrant box as "client".

  1. Install PostgreSQL: sudo apt-get install postgresql. This will install version 8.4.
  2. Create a user account for the postgres deamon: sudo adduser postgres and enter a new password for this user.
  3. Initialize postgres to use UTF8 instead of Latin1. Do this inside the new postgres user session (note the hyphen after su):
    sudo su - postgres
    rm -rf /var/lib/postgresql/8.4/main
    /usr/lib/postgresql/8.4/bin/initdb -D /var/lib/postgresql/8.4/main -E 'UTF-8' --lc-collate='en_US.UTF-8' --lc-ctype='en_US.UTF-8'
  4. Inside a postgres user session (sudo su - postgres) you can control the database server:
    /usr/lib/postgresql/8.4/bin/pg_ctl -D /var/lib/postgresql/8.4/main -l logfile start
    /usr/lib/postgresql/8.4/bin/pg_ctl -D /var/lib/postgresql/8.4/main stop
    /usr/lib/postgresql/8.4/bin/pg_ctl -D /var/lib/postgresql/8.4/main status
  5. Start the server. Create a database user and a new database with the same names as in your config/postgresql.yml file (or modify this file later to make it correspond again):
    psql template1
    CREATE USER <name> WITH PASSWORD '<pwd>';
    CREATE DATABASE <dbname>;
    GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <name>;
    \q
    Later you can edit the database using:
    psql <dbname>
  6. In another window ssh to the client. Go to the Yesod project folder (likely in a shared folder, like /vagrant/appname/.
  7. Install pgconfig (part of libpq): sudo apt-get install libpq-dev.
  8. Automatically install the Haskell lib for PostgreSQL using cabal clean & cabal install.
  9. Test run Yesod: yesod devel. If all is well, you'll see something like:
    Devel application launched: http://localhost:3000
    Migrating: CREATE TABLE "user"
Clone this wiki locally