Skip to content

Using PostgreSQL as default database

Joe Blankenship edited this page Oct 19, 2017 · 1 revision

Using PostgreSQL as Default Database

This is a guide for setting PostgreSQL as your database. The current default as listed in the main project is MySQL.

Installing PostgreSQL

Determine the environment in which you will be running LibreQDA (e.g., Linux, MacOS, Windows, etc.)

Download the appropriate version for your operating system (I'm currently using 9.6 for this tutorial)

Go to PostgreSQL's installation guide, select the correct version at the top of the page, and follow the instructions.

Creating the Database and User (in Linux)

Note: You can also perform this setup using the PGAdminIII tool. You can change the PASSWORD variable to a value of your choice.

At the terminal, type sudo su - postgres to access the postgres user

Type psql to enter the PostgreSQL CLI

To create the database, type CREATE DATABASE libreqda;

To create the user, type CREATE USER libreqda_rw WITH PASSWORD 'libreqda';

To allow our new user to create and manipulate tables in the database, type:

ALTER ROLE libreqda_rw SET client_encoding TO 'utf8';
ALTER ROLE libreqda_rw SET default_transaction_isolation TO 'read committed';
ALTER ROLE libreqda_rw SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE libreqda TO libreqda_rw;

Exit PostgreSQL by typing \q

Exit the shell by typing exit

Django Settings for PostgreSQL

Ensure your local_settings.py DATABASE section reads as:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'libreqda',
        'USER': 'libreqda_rw',
        'PASSWORD': 'libreqda',
        'HOST': 'localhost',
        'PORT': '',
    }
}