Creating a Simple Postgres Database


Download and install Postgres

Edit the Path Variable

On a Mac

Open a Terminal Session

Add the following line to your .profile
export PATH=$PATH:/Applications/Postgres.app/Contents/MacOS/bin/

run your .profile
. ./.profile

Start the Postgres Database by clicking the Postgres app

Create a Database

psql

# create database mydb;
CREATE DATABASE

#\q

psql mydb

# create table person( personId serial, name varchar(30), age integer, height decimal (4,2) );
NOTICE: CREATE TABLE will create implicit sequence “person_personid_seq” for serial column “person.personid”

# insert into person (name,age,height) values (‘John Dunning’,21,1.8);
INSERT 0 1

# select * from person;
personid | name | age | height
———-+————–+—–+——–
1 | John Dunning | 21 | 1.80
(1 row)

# create user john with password ‘secret’;
CREATE ROLE

# grant all on person to john;
GRANT

#\q

Leave a comment