postgres sql presented by : chandan, markandey amit, kiran harshada, prachi
TRANSCRIPT
![Page 1: PostGres SQL Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/1.jpg)
PostGres SQL
• Presented by :
Chandan , Markandey
Amit , Kiran
Harshada , Prachi
![Page 2: PostGres SQL Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/2.jpg)
Introduction
• What is ‘ PostGres ‘ ?
• An overview on
Classes
Inferitance
Arrays
Geometric Types
![Page 3: PostGres SQL Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/3.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/4.jpg)
Inheritance ( Cont. )
• CREATE TABLE cities ( name text ,
population int,
altitude int ) ;
• CREATE TABLE capitals ( state char10 )
INHERITS ( cities ) ;
![Page 5: PostGres SQL Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/5.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/6.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/7.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/8.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/9.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/10.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/11.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/12.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/13.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/14.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/15.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/16.jpg)
DropUser ( Cont. )
• Usage :
to remove user joe from the default database server.
$ dropuser joe
DROP USER
![Page 17: PostGres SQL Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/17.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/18.jpg)
Pg_Dump
• Name :
pg_dump - Extract a PostGres database into a script file.
• Synopsis :
pg_dump [options] [dbname]
![Page 19: PostGres SQL Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/19.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/20.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/21.jpg)
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 Presented by : Chandan, Markandey Amit, Kiran Harshada, Prachi](https://reader035.vdocuments.mx/reader035/viewer/2022062421/56649dc35503460f94ab63b2/html5/thumbnails/22.jpg)
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