Run Postgres Locally
There are two basic ways to run Postgres locally:
- Natively on your computer
- Via Docker
Most people run Postgres natively without Docker as it’s simpler, runs all the time in the background, and because Docker uses extra resources.
Natively on your computer
On Mac
There are two very popular options.
Install via Homebrew
- Make sure you have Homebrew installed.
- Run
brew install postgresql
- Run
brew services start postgresql
And that’s it!
Install via Postgres.app
- Go to Postgres.app
- Download and install the app
- Open the app and click “initalize” to create a new server
And then you are good to go!
On Windows
The easiest way is to download and run the installer from
Via Docker
- Create a
docker-compose.yml
file inside the root of your project with the following content
version: "3.7"services: db: image: postgres:latest volumes: - data:/var/lib/postgresql/data env_file: ./.env.local #Here we are using the already existing .env.local file ports: - "5432:5432"volumes: data:
- Inside your
.env.local
file add 3 new environment variables which are required by docker
POSTGRES_USER=your_userPOSTGRES_PASSWORD=your_passwordPOSTGRES_DB=your_database_name
Given these values your
DATABASE_URL
should look like this postgresql://your_user:your_password@localhost:5432/your_database_name
- Modify your
package.json
to run the database before the start of Blitz
"scripts": { "start": "docker-compose up -d && blitz start",}
- Run
blitz db migrate
to get your new database to the latest version of your migrations