Creating a new Postgres Database

How to set up a new Postgres database for use in a web framework like Django or an ORM like Prisma. This assumes Postgres has been installed and is running.

  1. Start the postgres shell by running psql in a terminal window.
  2. Run: CREATE USER jeff WITH PASSWORD 'apassword';
  3. CREATE DATABASE mydb;
  4. GRANT ALL PRIVILEGES ON DATABASE mydb to jeff;
  5. Then set DATABASE_URL='postgres://jeff:apassword@localhost:5432/mydb' in your .env file

Other Permissions

If the user also needs to be able to create dbs (like for testing or for Prisma migrations), run: ALTER USER <username> CREATEDB;

References