Setting up Postgres for Django on Debian Linux

Assumptions: Debian-based linux distro

1. Install postgres

sudo apt-get install postgresql

2. Create a password for the default postgres user

sudo passwd postgres

3. Login as PostGres user

su - postgres

4. Connect to postgres

psql

5. Start Database as root (automatically runs initdb)

service postgresql start

6. Create a role (the Django user in the DATABASES dictionary in settings.py is actually a role)

CREATE ROLE somebody WITH LOGIN PASSWORD 'secret123';

7. Create  a database

create database mydatabase

8. Now configure settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'somebody',
        'PASSWORD': 'secret123',
        'HOST': ''  #localhost
    }
}

Done!

Advertisements

2 thoughts on “Setting up Postgres for Django on Debian Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s