Postgres

Requirements

Postgres.app

Download from http://postgresapp.com/

What's In The Box? Postgres.app contains a full-featured PostgreSQL installation in a single package:

PostgreSQL 9.3.5 PostGIS 2.1.3 Procedural languages: PL/pgSQL, PL/Perl, PL/Python, and PLV8 (Javascript) Popular extensions, including hstore and uuid-ossp, and more A number of command-line utilities for managing PostgreSQL and working with GIS data

Installing Postgres.app

To install Postgres.app, just drag it to your Applications folder and double click.

On first launch, Postgres will initialise a new database cluster and create a database for your username. A few moments after launching, you should be able to click on "Open psql" to connect to the database.

If you'd like to use the command line tools delivered with Postgres.app, see the section on Command Line Tools.

Installing Postgres.app 1

Installing Postgres.app 2

PGAdmin3 1.18.1

It seems the postgress.app installation does not creat a postgress role by default. It created a username luiscberrocal. I could only connect to the database with that user.

Download from http://www.postgresql.org/ftp/pgadmin3/release/v1.18.1/osx/

PGAdmin3 1.18.1 1

PGAdmin3 1.18.1 2

Starting Postgres

Starting Postgres 1

Starting Postgres 2

Creating Database

Creating Database 1

Creating Database 2

Creating Database 3

Creating Database 4

Creating Database 5

Creating Database 6

Creating Database 7

Creating Database 8

Creating Database 9

Creating Database 10

Exporting the Postgres path

If you get an error Reading:

Error: pg_config executable not found.

You need to include in the PATH variable the postgres path

PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/

Connecting and Configuring Django to Database

Database configuration

This should have been installed with the local requirements. So DO NOT run it.

$ pip install psycopg2

Edit settings/local.py and replace database configuration for this:


########## DATABASE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": "wildbills",
        "USER": "",
        "PASSWORD": "",
        "HOST": "localhost",
        "PORT": "",
    },
}
########## END DATABASE CONFIGURATION

Pushing the Models to the Database

Running syncdb for Django 1.6 or less

$ python manage.py syncdb --settings=timesheet_project.settings.local

Run syncdb 1

Run syncdb 2

Running syncdb for Django 1.7.x

$ python manage.py syncdb --settings=timesheet_project.settings.local

Run syncdb 1.7

Problem connecting to Postgres from Windows

I encountered this error when I tried to connect with pgAdmin running on Windows 7 to a Postgres instance running on an Ubuntu 14.04 LTS.

Postgres error 1

It seems my ip address was not cleared to connect to the server. I had to edit on the ubunte server the /etc/postgresql/9.1/main/pg_hba.conf file.

Run

$ sudo nano /etc/postgresql/9.1/main/pg_hba.conf

Add your ip address range.

Postgres error 2

$ service postgresql restart