Skip to main content

Running Postgre, Redis or Minio locally

Ruslan Gainutdinov

It is really easy to run them locally, if you are using MacOS or Linux. Install them from your distribution source (or from Homebrew) and create the following script local.sh:

#!/bin/bash

if [ ! -d data/pg ]; then
  mkdir -p data/pg 
  initdb -D data/pg
fi

if [ ! -f pg.conf ]; then
  cat >pg.conf <<EOF
port = 5432
listen_addresses = 'localhost'
max_connections = 200
shared_buffers = 64MB
huge_pages = off
temp_buffers = 8MB
max_prepared_transactions = 0
work_mem = 512kB
effective_cache_size = 192MB
maintenance_work_mem = 16MB
shared_memory_type = mmap
dynamic_shared_memory_type = posix
log_destination = 'stderr'
logging_collector = off
log_error_verbosity = default
log_min_duration_statement = 100
temp_file_limit = 16000
max_files_per_process = 256
wal_buffers = 1966kB
wal_level = replica
fsync = on
synchronous_commit = on
default_statistics_target = 100
random_page_cost = 1.1
min_wal_size = 512MB
max_wal_size = 4GB
unix_socket_directories = ''
EOF
fi

function run_pg() {
  postgres -D data/pg --config-file=pg.conf
}

function run_redis() {
  mkdir -p data/redis
  redis-server --dir data/redis --bind 127.0.0.1 --pidfile redis.pid
}

function run_minio() {
  MINIO_ROOT_USER=DEV_ACCESS_KEY_ID MINIO_ROOT_PASSWORD=DEV_SECRET_ACCESS_KEY minio server --address 127.0.0.1:9000 data/s3
}

export -f run_pg
export -f run_redis
export -f run_minio

if [ $(command -v concurrently) ]; then 
  echo "Concurrently is already installed"
else
  npm i -g concurrently
fi

concurrently -k -s all "run_minio" "run_pg" "run_redis" "npm run dev"

Using this script, you can start and stop all needed services for you at once.