Archive

Posts Tagged ‘psycopg2’

[django] using PostgreSQL for local development

August 4, 2014 Leave a comment

PostgreSQL is highly recommended for Django. In the book “Two Scoops of Django” it is written that you should use the same DBMS that you will use in production. Many people use SQLite3 for local development and PostgreSQL in production but that will lead to surprises. So, if you plan to use PostgreSQL in production, then use PostgreSQL on your localhost too.

Question
How to set up and configure PostgreSQL on localhost? How to make it work with Django?

Answer
I found the answers to these questions here: How To Install and Configure Django with Postgres, Nginx, and Gunicorn.

PostgreSQL for local development
Long version:

# switch to user "postgres"
$ sudo su - postgres
[sudo] password for jabba:
# notice "postgres" in the prompt
postgres@jabba-uplink:~$ createdb mydb

# create a database user if you don't have one yet
postgres@jabba-uplink:~$ createuser myuser -P
Enter password for new role: 
Enter it again:

# grant access
postgres@jabba-uplink:~$ psql
psql (9.3.5)
Type "help" for help.

postgres=# GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
GRANT
postgres=#

Short version (if you already have a database user):

$ sudo su - postgres
postgres$ createdb mydb
postgres$ psql
psql (9.3.5)
Type "help" for help.

postgres=# GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
GRANT
postgres=#
Categories: django Tags: , , ,
Design a site like this with WordPress.com
Get started