Running a Postgres database from scratch

brew update && brew install postgres
sudo apt-get install postgresql
ls -lrt /usr/local/var/postgres
export PG_PATH="/usr/local/var/postgres"
sudo mkdir $PG_PATH
sudo chmod 775 $PG_PATH
sudo chown $(whoami) $PG_PATH
initdb $PG_PATH
pg_ctl -D $PG_PATH -l myDB.log start
psql -d postgres
postgres=# \l
CREATE USER myuser;
\du
CREATE DATABASE userdb WITH OWNER=myuser;
\c myusers myuser
CREATE SCHEMA users AUTHORIZATION myuser;
CREATE TABLE customers (    id char(5) CONSTRAINT firstkey PRIMARY KEY,    first_name varchar(40) NOT NULL,    age INTEGER NOT NULL,    CONSTRAINT age check (age >= 0));
pg_ctl -D $PG_PATH stop

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kubernetes vs. Docker Swarm: How to Choose? | A Complete Breakdown

Why we don’t support Compass — Forge

#freestockphoto (Monday 23rd 02PM)

KWOC Project Report

Savouring queues

NeoDash 2.0 — A Brand New Way to Visualize Neo4j

{UPDATE} Dart Scoreboard Pro Hack Free Resources Generator

History and Importance of Bit

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Senna Semakula-Buuza

Senna Semakula-Buuza

More from Medium

Postgres SQL with Micronaut on Heroku

Setting headers in postman via scripts

Introduction to Structured Query Language(SQL)

You should avoid using the IN-funtion in MySQL