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.
- Start the postgres shell by running
psql
in a terminal window. - Run:
CREATE USER jeff WITH PASSWORD 'apassword';
CREATE DATABASE mydb;
GRANT ALL PRIVILEGES ON DATABASE mydb to jeff;
- 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;