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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s