2. THINGS I’LL TALK ABOUT
• Relational & Object Oriented Database Management Systems.
AKA( RDBMS & OODBMS )
• PostgreSQL ( Object-Relational Database Management System )
• Architecture
• Client/Server Model
• Storage and Replication
• Getting Started
3. RDBMS & OODBMS
• Born in 1980s
• Current Market Share:
Rank
DBMS Database
Model
Score
Apr
2016
Mar
2016
Apr
2015
Apr
2016
Mar
2016
Apr
2015
1 1 1 Oracle Relational
DBMS
1467.53 -4.48 +21.40
2 2 2 MySQL Relational
DBMS
1370.11 +22.39 +85.53
3 3 3 Microsoft SQL
Server
Relational
DBMS
1135.05 -1.45 -14.07
4 4 4 MongoDB Document
Store
312.44 +7.11 +33.85
5 5 5 PostgreSQL Relational 303.73 +4.10 +35.41
4. PostgreSQL
• Is an Object-Relational Database Management System (ORDBMS)
with an emphasis on extensibility and standard-compliance.
• Cross-platform and runs on many operating systems ( *nix, OS X,
Windows )
• Features
• Implements the majority of the core SQL:2011 standard
• ACID Compliant
• Transactional avoiding locking issues using multiversion concurrency control
( MVCC )
• Immunity to dirty reads and full serializability
• Handles complex SQL queries
• Updateable views and Materialized Views, triggers, foreign keys; support
6. Client/Server Model
• Types of process:
• `postmaster`, supervisory daemon process
• Utility processes (bgwriter, walwriter, syslogger, archiver, statscollector and
autovacuum launcher) and
• User Backend process (postgres process itself, Server Process)
• Connection Initialization:
• Client request for connection to the database, firstly request hit to postmaster
daemon process after performing Authentication and authorization it spawns
one new backend server process.
• Libpq allows a single frontend to make multiple connections to backend
processes.
• Single-threaded process that can only execute one query at a time.
7. • Memory
• Shared Buffers
• WAL Buffers
• Clog Buffers
• Other Buffers
• PostreSQL shared memory is very big and all the buffers are not in sync,
mean all are independent.
• Utility Process:
• BG Writer
• WAL Writer
• Stats-collector
• Archiver
• Syslogger
• WAL Sender
• WAL Receiver
8. STORAGE AND REPLICATION
• Replication
• Built-in binary replication & synchronous replcication
• Indexes
• Built-in support for regular B-tree and hash indexes, and two types of inverted
indexes
• Generalized Search Trees( GiST ), Generalized Inverted Indexes ( GIN )
• Expression indexes, Partial indexes, k-nearest neighbors ( k-NN ) indexing and
Block Range Indexes ( BRIN )
• Schemas
• A schema holds all objects.
• Schemas effectively act like namespaces, allowing objects of the same name to
co-exist in the same database.
9.
10. • User-defined Objects
• New types of almost all objets inside the database can be created, including:
• Casts
• Conversions
• Data types
• Domains
• Functions, including aggregate functions and window functions
• Indexes including custom indexes for custom types
• Operators ( existing ones can be overloaded )
• Procedural Languages
• Inheritance
• Inherit characteristics from a “parent” table.
• SELECT * FROM ONLY parent_table;
11. Getting Started
• To create a new database, in this example named mydb, you use the
following command:
• $ createdb mydb
• If you do not want to use your database anymore you can remove it:
• $ dropdb mydb
• Accessing a Database
• Running the PostgreSQL interactive terminal program, called “psql”, which allows
you to interactively enter, edit, and execute SQL commands.
• $psql mydb
• psql (version)
Type “help” for help.
mydb=>
12. • Creating a New Table
• CREATE TABLE weather(
city varchar(80),
temp_lo int, -- low temperature
temp_hi int, -- high temperature
prcp real, -- precipitaion
date date
);
• DROP TABLE tablename;
• Populating a Table With Rows
• INSERT INTO weather VALUES ('San Francisco', 46, 50, 0.25, '1994-11-27');
• COPY weather FROM '/home/user/weather.txt';
13. • Inheritance
• It opens up interesting new possibilities of database design.
• Let's create two tables: A table cities and a table capitals.
• CREATE TABLE cities (
name text,
population real,
altitude int -- (in ft)
);
• CREATE TABLE capitals (
state char(2)
) INHERITS (cities);
• In this case, a row of capitals inherits all columns (name, population, and
altitude) from its parent, cities.
• The following query finds all the cities that are not state capitals and are situated
at an altitude of 500 feet or higher:
•SELECT name, altitude
FROM ONLY cities WHERE altitude > 500;
14. Summary
• PostgreSQL has many features not touched upon in this introduction.
• PostgreSQL gives much more power for dba and developers to
design the database according to the specific application.
• It’s adopted by the major sites like yahoo, reddit etc.
• More introductory material, please visit the PostgreSQL website for
links.