Skip to content

Latest commit

 

History

History
99 lines (80 loc) · 1.89 KB

File metadata and controls

99 lines (80 loc) · 1.89 KB

PostgreSQL Setup

Other Commands
#version check
postgres -V
PSQL commands:
#Display Users
\du

#List Databases
\l

#Current Database and User
\c

#Display Tables
\dt

#Describe Tables
\d+ <table_name>

# Connect to database
\c <db_name>

Installation

Brew

#install
brew update
brew install postgres

#start for local development, on-demand
postgres -D /usr/local/var/postgres

Yum

Source

sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
sudo service postgresql initdb
  • Edit your pg_hba.conf file:
sudo vi /var/lib/pgsql9/data/pg_hba.conf

#ubuntu
sudo vi /etc/postgresql/9.5/main/pg_hba.conf

local   all             all                                     trust
host    all             all           0.0.0.0/0                 md5
host    all             all             ::1/128                 md5
  • Edit postgresql.conf
sudo vi /var/lib/pgsql9/data/postgresql.conf

#ubuntu
sudo vi /etc/postgresql/9.5/main/postgresql.conf

listen_addresses='*'
port = 5432
  • start
sudo service postgresql start

Connecting to a PostgreSQL Database

psql -d postgres -h localhost -p 5432 -U postgres -W postgres

create user

-- postgres started using the term 'role' around version 9.x
CREATE ROLE tradebutler PASSWORD 'tradebutlersecret'
   VALID UNTIL 'infinity';
-- in case the default user create has no login permission
ALTER ROLE tradebutler WITH LOGIN;
create database
DROP DATABASE tradebutler_data_core_dev;

CREATE DATABASE tradebutler_data_core_dev
  WITH ENCODING='UTF8'
       OWNER=tradebutler
       CONNECTION LIMIT=-1
       TABLESPACE=pg_default;
Resources: