Postgres essential commands - RichardForshaw/dev-tools-blog GitHub Wiki

PostGres Essential Commands

Note that many of these commands need to be executed as the postgres user (so prefix with sudo -u postgres -i)

Create a new db

createdb [dbname]

Restart the DB

pg_ctl restart -D [DataDir]

where datadir is the location if postgresql.conf, usually /etc/postgresql/VERSION/main.

Create a new user

createuser -P [username]

This will prompt to set a password that you can set as blank

Grant user access

At a psql prompt:

GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;

Passwordless login with Django/psycopg2

If you get wierd results using a blank username/password, read this