New Postgres database and user for use in Django
Another one I always forget - how to create a new Postgres database and user for a new Django app. This is possible in one step as long as your Postgres configuration allows you to connect as the ‘postgres’ user:
$ createdb -Upostgres name-of-database
Mine does not so I first switch to the ‘postgres’ user and run the following:
$ sudo -i -u postgres
Then use the ‘createdb’ and ‘createuser’ commands:
$ createdb name-of-database
$ createuser -P name-of-user
Then start psql and grant privileges to the user:
$ psql
postgres=# GRANT ALL PRIVILEGES ON DATABASE name-of-database TO name-of-user;