postgres sql

22
PostGres SQL Presented by : Chandan , Markandey Amit , Kiran Harshada , Prachi

Upload: otis

Post on 11-Jan-2016

40 views

Category:

Documents


3 download

DESCRIPTION

PostGres SQL. Presented by : Chandan , Markandey Amit , Kiran Harshada , Prachi. Introduction. What is ‘ PostGres ‘ ? An overview on Classes Inferitance Arrays Geometric Types. Inheritance. A class can inherit from zero or more other classes. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: PostGres SQL

PostGres SQL

• Presented by :

Chandan , Markandey

Amit , Kiran

Harshada , Prachi

Page 2: PostGres SQL

Introduction

• What is ‘ PostGres ‘ ?

• An overview on

Classes

Inferitance

Arrays

Geometric Types

Page 3: PostGres SQL

Inheritance

• A class can inherit from zero or more other classes.

• A query can reference to either all instances of a class or all instances of a class plus all of its descendents.

• The inheritance hierarchy is a directed acyclic graph.

Page 4: PostGres SQL

Inheritance ( Cont. )

• CREATE TABLE cities ( name text ,

population int,

altitude int ) ;

• CREATE TABLE capitals ( state char10 )

INHERITS ( cities ) ;

Page 5: PostGres SQL

Arrays

• Valid for variable-length & fixed-length multi-dimensional arrays.

• Array with n elements start by array[1] and ends with array[n].

• CREATE TABLE sal_emp ( name text,

pay int4[ ],

schedule text[ ][ ] ) ;

Page 6: PostGres SQL

Geometric Types

• Represent two dimensional spatial object.

• Points , Circle , Infinite Line , Rectangular Box etc.

• PostGres geometric type :

( x , y ) Point in Space

( (x1,y1) , (x2,y2)) Line

< ( x , y ) , r > Circle

Page 7: PostGres SQL

CreateUser

• Name :

createuser - Create a new postgres user• Synopsis :

createuser [ options] [username]• Inputs :

- h : host. Host specifies the hostname of machine on which postmaster is running.

Page 8: PostGres SQL

CreateUser ( Cont. )

- e : echo . Echo the queries that createdb generates and sends to the backend.

username : Specifies the name of the postgres user to be created .This name

must be unique among all postgres users.

Page 9: PostGres SQL

CreateUser ( Cont .)

• Outputs :

CREATE USER

All is well

createuser : creation of user “username” failed.

Something went wrong . The user was not created.

Page 10: PostGres SQL

CreateUser ( Cont. )

• Description :

• createuser creates a new PostGres user. Only users with usesuper set in the pg_shadow class can create new PostGres users.

Page 11: PostGres SQL

CreateUser ( Cont. )

• Usage :

To create user joe on the default database

server.

$ createuser joe

Is the new user allowed to create databases? n

CREATE USER

Page 12: PostGres SQL

DropUser

• Name :

dropuser - Drops (removes) a postgres user.

• Synopsis :

dropuser [ options] [username]

• Inputs :

- h : host .Host specifies the host name of machine on which postmaster is running.

Page 13: PostGres SQL

DropUser ( Cont. )

• - e : echo . Echo the queries that createdb generates and sends to the backend.

• Username : Specifies the name of the postgres user to be removed. This name must exist in the postgres installation.

Page 14: PostGres SQL

DropUser ( Cont. )

• Output :

DROP USER

All is well.

Dropuser : deletion of user “username” failed.

Something went wrong. The user was not removed.

Page 15: PostGres SQL

DropUser ( Cont. )

• Description :

• dropuser removes an existing user and the databases which that user owned . Only users with usesuper set in the pg_shadow class can destroy postgres users.

Page 16: PostGres SQL

DropUser ( Cont. )

• Usage :

to remove user joe from the default database server.

$ dropuser joe

DROP USER

Page 17: PostGres SQL

Applications

• Createdb - Create a new PostGres database.

• Destroydb - Remove an existing PostGres database .

• Createlang : Add a new programming language to a postgres database.

• Droplang : Remove a programming language from a postgres database.

Page 18: PostGres SQL

Pg_Dump

• Name :

pg_dump - Extract a PostGres database into a script file.

• Synopsis :

pg_dump [options] [dbname]

Page 19: PostGres SQL

Cont.

• Inputs :

• dbname : Specifies the name of the database to be extracted. Dbname defaults to the value of the USER environment variable.

• -a : Dump out only the data, no schema.

• -c : Clean schema prior to create

Page 20: PostGres SQL

Cont.

• Output

pg_dump will create a file or write to stdout

• Description

pg_dump is a utility for dumping out a postgres database into a script file containing query commands.

Page 21: PostGres SQL

Cont.

• The script files are in text format and can be used to reconstruct database ,even on other machine and other architecture.pg_dump will produce the queries necessary to regenerate all user defined types ,functions,tables,indices,aggregates and operators.

Page 22: PostGres SQL

Cont.

• Usage

To dump a database of the same name as the user:

$pg_dump > db.out

To reload this database:

$psql -e database < db.out