Home > django > [django] using PostgreSQL for local development

[django] using PostgreSQL for local development

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=#
Advertisements
Categories: django Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

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

%d bloggers like this: