The goals of this guide are to help you:
- Install PostgreSQL
- Create a ROLE/USER with a PASSWORD
- Create a DATABASE
- Get your database URL connection string
Check if you already have PostgreSQL installed. You can try one of the following:
- run the command
which psql
- check if it's listed in your computers Applications
If you need to install PostgreSQL see the installing PostgreSQL guides
For this project-starter template you can use any values for the username, password, and database name. The rest of this guide will assume the following values were chosen:
- PostgreSQL User/Role
- name:
ctp_user
- password:
ctp_pass
- name:
- PostgreSQL Database
- name:
ctp_appdb_development
- name:
Important
Whatever values you choose, save them or you will lose access to your database data and will have to create a new one.
If you are on Windows or installed pgAdmin follow our pgAdmin guide to create a user in PostgreSQL named ctp_user
with the password ctp_pass
and a database named ctp_appdb_development
.
Create a user in PostgreSQL named ctp_user
with the password ctp_pass
:
createuser -P -s -e ctp_user
Create a new db for this project:
createdb -h localhost -U ctp_user ctp_appdb_development
You will create a DB for each project you start based on this repo. For other projects change
ctp_appdb_development
to the new apps database name.
The database connection string takes the general form of:
postgresql://[YOUR-USERNAME]:[YOUR-PASSWORD]@[HOSTNAME]:5432/[DBNAME]
For the local DB setup described above, your string would be:
postgresql://ctp_user:ctp_pass@localhost:5432/ctp_appdb_development?sslmode=disable
Caution
the ?sslmode=disable
option should only be used for local development and should NOT be used in a deployed/production setting. For more info see the SSL Mode documentation.