Skip to content

Instantly share code, notes, and snippets.

@seirl
Last active September 24, 2018 16:26
Show Gist options
  • Save seirl/424d5a9ffd6a86a332c016b50eba774d to your computer and use it in GitHub Desktop.
Save seirl/424d5a9ffd6a86a332c016b50eba774d to your computer and use it in GitHub Desktop.
Postgresql dev setup: It's Really Not As Complicated As You're Making It Out To Be

PostgreSQL tutorials for having a quick dev setup that just works are overcomplicated. Here's what you should do in 99.99% of cases.

postgresql installation

root# apt install postgresql

creating your user

As your main user:

antoine$ sudo -u postgres createuser -dP $USER

-d to allow database creation, -P to prompt for a password. The first argument is your UNIX username.

creating your db

As your main user:

antoine$ createdb mydb

That's it. No pg_hba.conf, no CREATE ROLE, no WITH ENCRYPTED, no ALTER USER.

using your db

antoine$ psql mydb

No password to enter.

With Django:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydb',
    }
}

No password either. The only reason for having a password at all is just to be able to log in remotely or for tools that don't handle peer auth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment