SlideShare a Scribd company logo
PostgreSQL - Object Relational Database
Presenter: Mubashar Iqbal
Senior Software Engineer
Object Relational Database System
Judging Criteria ??
Fast
Flexible
Powerful
Scalable
Easy Deployment
What’s in your mind ?
PostgreSQL - Object Relational Database
Introduction
The world's most advanced open source object-relational database system. The open
source Oracle. PostgreSQL has a large distributed developer and user community.
Community-owned with many companies involved.
Supported operating systems
● Linux
● Unix
● Mac OS X
● Solaris
● Windows
Native programming interfaces for:
C/C++, Java, .Net, Perl, Python, Ruby, PHP
Development Priorities
● Designed by/for Database Administrators
● Data integrity
● Security
● Reliability
● Standards
● DB Features
● Performance
● Ease-of-use
● Programmer Features
Most Common Uses
● ERP
● Data Warehouse
● Geographic
● OEM applications
● Network tools
● CRM
Prominent users
● Yahoo! for web user behavioral analysis, storing two petabytes and claimed to be
the largest data warehouse using a heavily modified version of PostgreSQL
● Sony Online multiplayer online games.
● Reddit social news website.
● Skype VoIP application, central business databases.
● Sun xVM, Sun's virtualization and datacenter automation suite.
● MusicBrainz, open online music encyclopedia.
● MyYearbook social networking site.
● Instagram, a popular mobile photo sharing service
● Disqus, an online discussion and commenting service
Features
● PostgreSQL often described as an open-source version of Oracle.
● BSD/MIT type license
● Reliability is PostgreSQL's top priority.
● Well-engineered, capable of supporting high-transaction and mission-critical
applications.
● Comprehensive documentation and manuals available for free online.
● Commercial support is available from independent vendors.
● PostgreSQL is fully ACID compliant.
● PostgreSQL is considered the solemn, full-featured, workhorse for transactional
enterprise applications, with strong ACID compliance.
Features (contd..)
● PostgreSQL supports one storage engine.
● SSL encryption
● Online backup
● Point-in-time recovery: Restore to any time in the past.
● Regular expression
Tools
● Psql: Command line front-end
● pgAdmin: GUI front-end
● phpPgadmin: Web based front-end
● MS ODBC
● MS Office + Postgres
● NaviCat: $$
● DeZign: $$
● EMS SQL Manager for PostgreSQL: $$
Data Types
● Numeric Types
● Character Types
● Hierarchical Types
● Binary Data Types
● Geometric Types
● Network Address Types
● Text Search Types
● UUID Type
● XML Type
● JSON Type
● Arrays
● Composite Types
Indexes
B-tree: B-trees can handle equality and range queries on data that can be sorted into
some ordering (<, <=,=,>=,>)
Hash: Hash indexes can only handle simple equality comparisons
GIN: GIN indexes are inverted indexes which can handle values that contain more than
one key, arrays for example, GIN operator classes for one-dimensional arrays
(<@,@>,=,&&)
GiST: Generalized Search Tree, it is a tree-structured access method and also known as
two-dimensional geometric data types (<@,@>,=,&&,>>,<<,&<,>&,~=)
Functions
A stored procedure and user-defined function is a set of SQL and procedural statements
(declarations, assignments, loops, flow-of-control) that stored on the database server and
can be invoked using the SQL interface.
CREATE FUNCTION function_name(p1 type, p2 type)
RETURNS type AS
BEGIN
-- logic
END;
LANGUAGE language_name;
Triggers
On DML (Data Manipulation Language) SELECT, INSERT, UPDATE, DELETE
CREATE TRIGGER
name { BEFORE | AFTER } { event [ OR ... ] }
ON
table [ FOR [ EACH ] { ROW | STATEMENT } ]
EXECUTE PROCEDURE
funcname ( arguments )
Cursors
● Used instead of FOR.
● Avoid memory overrun.
● Large data set.
DECLARE curs1 refcursor;
curs2 CURSOR FOR SELECT * FROM tenk1;
OPEN curs1 FOR SELECT * FROM foo WHERE key = mykey;
FETCH curs2 INTO foo, bar, baz;
CLOSE curs1;
View
View consists of a stored query accessible as a virtual table in a relational database or a
set of documents in a document-oriented database composed of the result set of a query.
Views are a great way to simplify your data model.
CREATE VIEW table_information AS
SELECT * FROM table WHERE id = 123;
Now you can simply query your new table directly:
SELECT * FROM table_information;
User-defined objects
New types of almost all objects 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
Replication Methods
1. Master/Slave
● Asynchronous
● Synchronous
2. Multi-Master
● Asynchronous
● Synchronous
3. Proxy
4. Standby system
Master/Slave Replication
Asynchronous Synchronous
High availability High availibility
Read performance Better read performance
Offline peers Worse write performance
async
M S M S
sync
Multi-Master Replication
Asynchronous Synchronous
Read performance High availiability
Faster access across WANs Read performance
Manage offline peers Difficult to get good write performance
M M M M
async sync
Scaling behaviour
Comparison of scaling behaviour
Hierarchical Database
Data is organized into a tree like structure.
Representing information using parent/child relationships.
Each parent can have many children, but each child has only one parent also known as a 1-
to-many relationship.
Different ways store data like this are
• Enumeration path (ltree)
• Adjacency List
• Nested Sets
LTree – Label Tree
● Ltree is a PostgreSQL module.
● It is implements a data type ltree for representing labels of data stored in a
hierarchical tree-like structure.
● Labels must be less than 256 bytes long. ltree stores a label path.
● A label path is a sequence of zero or more labels separated by dots.
● ltree supports several types of indexes that can speed up the indicated operators.
● Ltree performance is much better when you need to do ad-hoc queries over the tree
● Faster than recursive function that constantly needs to recalculate the branching.
● Some other databases have similar types. SQL Server 2008 has a datatype called
HierarchyID which serves the same purpose as ltree but with different syntax.
Example
Technique Adjacency Ltree
Query WITH RECURSIVE d AS (
SELECT id
FROM sponsorship WHERE id = 799
UNION ALL
SELECT s.id
FROM d JOIN sponsorship s ON
s.parent_fk = d.id
)
SELECT * FROM d ORDER BY id
LIMIT 100;
WITH p AS (
SELECT path FROM
sponsorship
WHERE id=799
)
SELECT s.id
FROM sponsorship s, p
WHERE s.path <@ p.path
ORDER BY s.id LIMIT 100;
Total Runtime 1946.48 ms 28.00 ms
More Details
1. Value Expression
http://www.postgresql.org/docs/9.2/static/sql-expressions.html
2. String Functions and Operators
http://www.postgresql.org/docs/9.2/static/functions-string.html
3. Mathematical Functions and Operators
http://www.postgresql.org/docs/9.2/static/functions-math.html
4. MySQL vs PostgreSQL
http://get.enterprisedb.com/whitepapers/Postgres_Plus_8.4_vs_MySQL_5.5.pdf
5. Scaling Behaviour
http://tweakers.net/reviews/657/1/database-test-dual-intel-xeon-5160-introduction.html
References
http://www.postgresql.org/
http://tweakers.net/reviews/657/5/database-test-dual-intel-xeon-5160-
comparison-of-scaling-behaviour.html
http://www.slideshare.net/petereisentraut/replication-solutions-for-postgresql
http://gbif.blogspot.com/2012/06/taxonomic-trees-in-postgresql.html
http://www.slideshare.net/vuhung16plus/postgre-sqlintroduction20100506
PostgreSQL - Object Relational Database

More Related Content

PDF
How to Analyze and Tune MySQL Queries for Better Performance
oysteing
 
PDF
ClickHouse Features for Advanced Users, by Aleksei Milovidov
Altinity Ltd
 
PDF
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PPTX
The path to success with graph database and graph data science_ Neo4j GraphSu...
Neo4j
 
PDF
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Altinity Ltd
 
PPTX
Oracle to Postgres Schema Migration Hustle
EDB
 
PDF
並列データベースシステムの概念と原理
Makoto Yui
 
PDF
PostgreSQL WAL for DBAs
PGConf APAC
 
How to Analyze and Tune MySQL Queries for Better Performance
oysteing
 
ClickHouse Features for Advanced Users, by Aleksei Milovidov
Altinity Ltd
 
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
The path to success with graph database and graph data science_ Neo4j GraphSu...
Neo4j
 
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Altinity Ltd
 
Oracle to Postgres Schema Migration Hustle
EDB
 
並列データベースシステムの概念と原理
Makoto Yui
 
PostgreSQL WAL for DBAs
PGConf APAC
 

What's hot (20)

PDF
Workshop - Neo4j Graph Data Science
Neo4j
 
PPT
Introduction to MongoDB
Ravi Teja
 
PPTX
MySQL Optimizer Overview
Olav Sandstå
 
PDF
Webinar: PostgreSQL continuous backup and PITR with Barman
Gabriele Bartolini
 
PPTX
「Googleを支える技術」の解説 2010.08.23
Minoru Chikamune
 
PPT
Neo4J : Introduction to Graph Database
Mindfire Solutions
 
PDF
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
Equnix Business Solutions
 
PDF
[B23] PostgreSQLのインデックス・チューニング by Tomonari Katsumata
Insight Technology, Inc.
 
PDF
Advanced SQL For Data Scientists
Databricks
 
PPTX
Deep dive into LangChain integration with Neo4j.pptx
TomazBratanic1
 
PPTX
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
DataStax
 
PDF
Patroni - HA PostgreSQL made easy
Alexander Kukushkin
 
PDF
Barman (PostgreSql) manual
Marcelo Pesallaccia
 
PPTX
Postgresql
NexThoughts Technologies
 
PPTX
Introduction to NoSQL Databases
Derek Stainer
 
PDF
pg_dbms_statsの紹介
NTT DATA OSS Professional Services
 
PDF
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
 
PDF
MongoDB very basic (Japanese) / MongoDB基礎の基礎
Naruhiko Ogasawara
 
PPTX
PostgreSQL Database Slides
metsarin
 
PDF
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 
Workshop - Neo4j Graph Data Science
Neo4j
 
Introduction to MongoDB
Ravi Teja
 
MySQL Optimizer Overview
Olav Sandstå
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Gabriele Bartolini
 
「Googleを支える技術」の解説 2010.08.23
Minoru Chikamune
 
Neo4J : Introduction to Graph Database
Mindfire Solutions
 
[EPPG] Oracle to PostgreSQL, Challenges to Opportunity
Equnix Business Solutions
 
[B23] PostgreSQLのインデックス・チューニング by Tomonari Katsumata
Insight Technology, Inc.
 
Advanced SQL For Data Scientists
Databricks
 
Deep dive into LangChain integration with Neo4j.pptx
TomazBratanic1
 
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
DataStax
 
Patroni - HA PostgreSQL made easy
Alexander Kukushkin
 
Barman (PostgreSql) manual
Marcelo Pesallaccia
 
Introduction to NoSQL Databases
Derek Stainer
 
pg_dbms_statsの紹介
NTT DATA OSS Professional Services
 
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
 
MongoDB very basic (Japanese) / MongoDB基礎の基礎
Naruhiko Ogasawara
 
PostgreSQL Database Slides
metsarin
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 
Ad

Viewers also liked (13)

PDF
Small Overview of Skype Database Tools
elliando dias
 
PDF
The Object Oriented Database System Manifesto
Beat Signer
 
PPT
Object Relational Database Management System
Amar Myana
 
PPT
A brief introduction to PostgreSQL
Vu Hung Nguyen
 
PPT
Object Oriented Database Management System
Ajay Jha
 
PPTX
Cloud Architecture best practices
Omid Vahdaty
 
PDF
Object-Relational Database Systems(ORDBMSs)
Sahan Walpitagamage
 
PPTX
Ordbms
ramandeep brar
 
PDF
Postgres in Production - Best Practices 2014
EDB
 
PPT
Object Oriented Dbms
maryeem
 
PPT
08. Object Oriented Database in DBMS
koolkampus
 
PPT
Types dbms
Avnish Shaw
 
PDF
Practical Object Oriented Models In Sql
Karwin Software Solutions LLC
 
Small Overview of Skype Database Tools
elliando dias
 
The Object Oriented Database System Manifesto
Beat Signer
 
Object Relational Database Management System
Amar Myana
 
A brief introduction to PostgreSQL
Vu Hung Nguyen
 
Object Oriented Database Management System
Ajay Jha
 
Cloud Architecture best practices
Omid Vahdaty
 
Object-Relational Database Systems(ORDBMSs)
Sahan Walpitagamage
 
Postgres in Production - Best Practices 2014
EDB
 
Object Oriented Dbms
maryeem
 
08. Object Oriented Database in DBMS
koolkampus
 
Types dbms
Avnish Shaw
 
Practical Object Oriented Models In Sql
Karwin Software Solutions LLC
 
Ad

Similar to PostgreSQL - Object Relational Database (20)

PDF
NoSQL
Radu Potop
 
PPTX
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
MhmdMk10
 
PPTX
Redis Modules - Redis India Tour - 2017
HashedIn Technologies
 
ODP
An Introduction to Postgresql
عباس بني اسدي مقدم
 
PDF
Apache Spark 101 - Demi Ben-Ari
Demi Ben-Ari
 
PPTX
U-SQL - Azure Data Lake Analytics for Developers
Michael Rys
 
PPTX
Big data technology unit 3
RojaT4
 
PPTX
Apache Hive for modern DBAs
Luis Marques
 
PDF
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
Alexey Zinoviev
 
PPTX
PostgreSQL as an Alternative to MSSQL
Alexei Krasner
 
PPTX
PASS Summit - SQL Server 2017 Deep Dive
Travis Wright
 
PPTX
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
mh3473
 
PPTX
MongoDB is a document database. It stores data in a type of JSON format calle...
amintafernandos
 
PDF
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
Command Prompt., Inc
 
PPTX
Cassandra training
András Fehér
 
PDF
No sql bigdata and postgresql
Zaid Shabbir
 
PPTX
This is training for spark SQL essential
Sudesh64
 
PDF
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
javier ramirez
 
PDF
WhereHows: Taming Metadata for 150K Datasets Over 9 Data Platforms
Mars Lan
 
PDF
Introduction to Postrges-XC
Ashutosh Bapat
 
NoSQL
Radu Potop
 
Chjkkkkkkkkkkkkkkkkkjjjjjjjjjjjjjjjjjjjjjjjjjj01_The Basics.pptx
MhmdMk10
 
Redis Modules - Redis India Tour - 2017
HashedIn Technologies
 
An Introduction to Postgresql
عباس بني اسدي مقدم
 
Apache Spark 101 - Demi Ben-Ari
Demi Ben-Ari
 
U-SQL - Azure Data Lake Analytics for Developers
Michael Rys
 
Big data technology unit 3
RojaT4
 
Apache Hive for modern DBAs
Luis Marques
 
JPoint'15 Mom, I so wish Hibernate for my NoSQL database...
Alexey Zinoviev
 
PostgreSQL as an Alternative to MSSQL
Alexei Krasner
 
PASS Summit - SQL Server 2017 Deep Dive
Travis Wright
 
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
mh3473
 
MongoDB is a document database. It stores data in a type of JSON format calle...
amintafernandos
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
Command Prompt., Inc
 
Cassandra training
András Fehér
 
No sql bigdata and postgresql
Zaid Shabbir
 
This is training for spark SQL essential
Sudesh64
 
Ingesting Over Four Million Rows Per Second With QuestDB Timeseries Database ...
javier ramirez
 
WhereHows: Taming Metadata for 150K Datasets Over 9 Data Platforms
Mars Lan
 
Introduction to Postrges-XC
Ashutosh Bapat
 

Recently uploaded (20)

PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Exploring AI Agents in Process Industries
amoreira6
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 

PostgreSQL - Object Relational Database

  • 2. Presenter: Mubashar Iqbal Senior Software Engineer Object Relational Database System
  • 11. Introduction The world's most advanced open source object-relational database system. The open source Oracle. PostgreSQL has a large distributed developer and user community. Community-owned with many companies involved. Supported operating systems ● Linux ● Unix ● Mac OS X ● Solaris ● Windows Native programming interfaces for: C/C++, Java, .Net, Perl, Python, Ruby, PHP
  • 12. Development Priorities ● Designed by/for Database Administrators ● Data integrity ● Security ● Reliability ● Standards ● DB Features ● Performance ● Ease-of-use ● Programmer Features
  • 13. Most Common Uses ● ERP ● Data Warehouse ● Geographic ● OEM applications ● Network tools ● CRM
  • 14. Prominent users ● Yahoo! for web user behavioral analysis, storing two petabytes and claimed to be the largest data warehouse using a heavily modified version of PostgreSQL ● Sony Online multiplayer online games. ● Reddit social news website. ● Skype VoIP application, central business databases. ● Sun xVM, Sun's virtualization and datacenter automation suite. ● MusicBrainz, open online music encyclopedia. ● MyYearbook social networking site. ● Instagram, a popular mobile photo sharing service ● Disqus, an online discussion and commenting service
  • 15. Features ● PostgreSQL often described as an open-source version of Oracle. ● BSD/MIT type license ● Reliability is PostgreSQL's top priority. ● Well-engineered, capable of supporting high-transaction and mission-critical applications. ● Comprehensive documentation and manuals available for free online. ● Commercial support is available from independent vendors. ● PostgreSQL is fully ACID compliant. ● PostgreSQL is considered the solemn, full-featured, workhorse for transactional enterprise applications, with strong ACID compliance.
  • 16. Features (contd..) ● PostgreSQL supports one storage engine. ● SSL encryption ● Online backup ● Point-in-time recovery: Restore to any time in the past. ● Regular expression
  • 17. Tools ● Psql: Command line front-end ● pgAdmin: GUI front-end ● phpPgadmin: Web based front-end ● MS ODBC ● MS Office + Postgres ● NaviCat: $$ ● DeZign: $$ ● EMS SQL Manager for PostgreSQL: $$
  • 18. Data Types ● Numeric Types ● Character Types ● Hierarchical Types ● Binary Data Types ● Geometric Types ● Network Address Types ● Text Search Types ● UUID Type ● XML Type ● JSON Type ● Arrays ● Composite Types
  • 19. Indexes B-tree: B-trees can handle equality and range queries on data that can be sorted into some ordering (<, <=,=,>=,>) Hash: Hash indexes can only handle simple equality comparisons GIN: GIN indexes are inverted indexes which can handle values that contain more than one key, arrays for example, GIN operator classes for one-dimensional arrays (<@,@>,=,&&) GiST: Generalized Search Tree, it is a tree-structured access method and also known as two-dimensional geometric data types (<@,@>,=,&&,>>,<<,&<,>&,~=)
  • 20. Functions A stored procedure and user-defined function is a set of SQL and procedural statements (declarations, assignments, loops, flow-of-control) that stored on the database server and can be invoked using the SQL interface. CREATE FUNCTION function_name(p1 type, p2 type) RETURNS type AS BEGIN -- logic END; LANGUAGE language_name;
  • 21. Triggers On DML (Data Manipulation Language) SELECT, INSERT, UPDATE, DELETE CREATE TRIGGER name { BEFORE | AFTER } { event [ OR ... ] } ON table [ FOR [ EACH ] { ROW | STATEMENT } ] EXECUTE PROCEDURE funcname ( arguments )
  • 22. Cursors ● Used instead of FOR. ● Avoid memory overrun. ● Large data set. DECLARE curs1 refcursor; curs2 CURSOR FOR SELECT * FROM tenk1; OPEN curs1 FOR SELECT * FROM foo WHERE key = mykey; FETCH curs2 INTO foo, bar, baz; CLOSE curs1;
  • 23. View View consists of a stored query accessible as a virtual table in a relational database or a set of documents in a document-oriented database composed of the result set of a query. Views are a great way to simplify your data model. CREATE VIEW table_information AS SELECT * FROM table WHERE id = 123; Now you can simply query your new table directly: SELECT * FROM table_information;
  • 24. User-defined objects New types of almost all objects 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
  • 25. Replication Methods 1. Master/Slave ● Asynchronous ● Synchronous 2. Multi-Master ● Asynchronous ● Synchronous 3. Proxy 4. Standby system
  • 26. Master/Slave Replication Asynchronous Synchronous High availability High availibility Read performance Better read performance Offline peers Worse write performance async M S M S sync
  • 27. Multi-Master Replication Asynchronous Synchronous Read performance High availiability Faster access across WANs Read performance Manage offline peers Difficult to get good write performance M M M M async sync
  • 30. Hierarchical Database Data is organized into a tree like structure. Representing information using parent/child relationships. Each parent can have many children, but each child has only one parent also known as a 1- to-many relationship. Different ways store data like this are • Enumeration path (ltree) • Adjacency List • Nested Sets
  • 31. LTree – Label Tree ● Ltree is a PostgreSQL module. ● It is implements a data type ltree for representing labels of data stored in a hierarchical tree-like structure. ● Labels must be less than 256 bytes long. ltree stores a label path. ● A label path is a sequence of zero or more labels separated by dots. ● ltree supports several types of indexes that can speed up the indicated operators. ● Ltree performance is much better when you need to do ad-hoc queries over the tree ● Faster than recursive function that constantly needs to recalculate the branching. ● Some other databases have similar types. SQL Server 2008 has a datatype called HierarchyID which serves the same purpose as ltree but with different syntax.
  • 32. Example Technique Adjacency Ltree Query WITH RECURSIVE d AS ( SELECT id FROM sponsorship WHERE id = 799 UNION ALL SELECT s.id FROM d JOIN sponsorship s ON s.parent_fk = d.id ) SELECT * FROM d ORDER BY id LIMIT 100; WITH p AS ( SELECT path FROM sponsorship WHERE id=799 ) SELECT s.id FROM sponsorship s, p WHERE s.path <@ p.path ORDER BY s.id LIMIT 100; Total Runtime 1946.48 ms 28.00 ms
  • 33. More Details 1. Value Expression http://www.postgresql.org/docs/9.2/static/sql-expressions.html 2. String Functions and Operators http://www.postgresql.org/docs/9.2/static/functions-string.html 3. Mathematical Functions and Operators http://www.postgresql.org/docs/9.2/static/functions-math.html 4. MySQL vs PostgreSQL http://get.enterprisedb.com/whitepapers/Postgres_Plus_8.4_vs_MySQL_5.5.pdf 5. Scaling Behaviour http://tweakers.net/reviews/657/1/database-test-dual-intel-xeon-5160-introduction.html