SlideShare a Scribd company logo
How Databases Work 
• Gurjeet Singh | 09.18.14 
© 2013 EDB All rights reserved. 1
Who Am I 
Database Architect @ EDB 
– Index Advisor 
– Optimizer Hints 
– Postgres Enterprise Manager 
– Postgres Plus Cloud Database 
Postgres Contributor 
– Postgres Hibernator and others 
Learnt From Mistakes 
© 2013 EDB All rights reserved. 2
Goal 
Impart some new knowledge, that helps you do your 
job better. 
(The “Full Monty” slides is where the meat of the talk 
is) 
© 2013 EDB All rights reserved. 3
Agenda 
• ACID 
• Application Interaction 
• Backend Operations 
• Concurrent/Cooperating Operations 
• OS/Disk Interaction 
• NoSQL 
© 2013 EDB All rights reserved. 4
ACID 
© 2013 EDB All rights reserved. 5
ACID 
Traits of a transaction in an RDBMS 
• Atomicity 
– Changes done by a transaction are one unit; all or 
nothing. 
• Consistency 
– Transaction end leaves database in a consistent 
state; constraints cannot be violated. 
• Isolation 
– Transactions behave as if only one transaction is 
in progress at a time. 
• Durability 
– Transactions, once committed, will not be lost. 
© 2013 EDB All rights reserved. 6
NoSQL 
© 2013 EDB All rights reserved. 7
NoSQL 
• We are not going to discuss NoSQL databases. 
• They compromise on at least one of ACID properties 
© 2013 EDB All rights reserved. 8
Application Interaction 
© 2013 EDB All rights reserved. 9
Application Interaction 
• Applications use a database driver 
• The driver uses a custom protocol (language) 
• Enables Client-Server/n-Tier architectures 
Java 
Ruby 
Python 
JavaScript 
C/C++ 
© 2013 EDB All rights reserved. 10
Backend Operations 
© 2013 EDB All rights reserved. 11
Backend Operations 
• Query Processing 
– Tokenize/Parse 
– Parse Analysis 
– Plan/Optimize 
– Execute 
© 2013 EDB All rights reserved. 12
Backend Operations – Tokenize/Parse 
SELECT e.id, d.name 
FROM emp e JOIN dept d 
ON e.dept = d.id 
WHERE emp.name = 'Agent Smith'; 
SELECT e . id , d . name 
FROM emp e JOIN dept d 
ON e . dept = d . id 
WHERE emp . name = 'Agent Smith' ; 
© 2013 EDB All rights reserved. 13
Backend Operations – Tokenize/Parse 
SELECT List FROM List WHERE List 
e.id d.name emp dept = 
= 
© 2013 EDB All rights reserved. 14 
e.name 'Agent Smith' 
Parse Tree 
ON 
e.dept d.id
Backend Operations – Parse Analysis 
• Ensure that 
– The objects (tables, columns, functions, etc.) exist 
– Resolve/expand views 
• Type Coercion 
© 2013 EDB All rights reserved. 15
Backend Operations – Plan/Optimize 
Generate all possible plans to access objects 
• Compare cost of 
– Accessing tables using various methods 
● Full Table Scan, Index Scan, Bitmap Index, etc. 
– Joining tables using various methods 
● Nested Loop join, Hash Join, Sort-Merge Join 
– Other operations like distinct, ordering, grouping. 
• Choose the best plan 
• Best may mean 
– Fastest (e.g. LIMIT clause) 
– Cheapest 
© 2013 EDB All rights reserved. 16
Backend Operations – Plan/Optimize 
Plan/Execution Tree 
Result 
Nested Loop 
Index Scan - emp 
Condition: name = 
'Agent Smith' 
Filter: e.dept = 
© 2013 EDB All rights reserved. 17 
Full Table Scan - dept 
d.id 
To Client
Backend Operations - Execute 
• Traverse the Execution Tree recursively 
• Pull rows from each execution node, until exhausted 
• Insert/Update rows 
– Delete in Postgres is just an update of row header 
– Update is similar to Delete + Insert 
– Multi-Version Concurrency Control (MVCC) 
• Send result/rows to the client 
© 2013 EDB All rights reserved. 18
Concurrent/Cooperating 
Operations 
© 2013 EDB All rights reserved. 19
Concurrent/Cooperating Operations 
• Read data from disk 
• Share data 
• Locks to prevent concurrent update 
• Write data to disk 
© 2013 EDB All rights reserved. 20
Block Structure 
© 2013 EDB All rights reserved. 21 
Free Space 
Block Header 
Row Pointers 
Row Header
MVCC 
Isolation; A transaction will: 
• Ignore changes done by newer transactions 
• Ignore changes done by running transactions 
• Ignore changes done by rolled-back transactions 
• Only “see” changes by older and committed 
transactions 
Effectively: 
• Readers don't block writers 
• Writers don't block readers 
© 2013 EDB All rights reserved. 22
MVCC 
Provides 
• Atomicity; with the help of commit log (clog) 
• Isolation 
Consistency 
• Ensured by the individual backends 
© 2013 EDB All rights reserved. 23
Full Monty 
Client 1 Client 2 Client 3 Client n 
Network 
Backend 1 Backend 2 Backend n Postmaster 
© 2013 EDB All rights reserved. 24 
Checkpointer 
Autovacuum 
RAM 
Disk Cache 
Shared Buffers 
WAL Buffers 
Controller Cache Controller Cache 
BGWriter
Full Monty 
• WAL – Write Ahead Log 
– Record change before the actual change 
– Sequential, always growing infinite log 
• Checkpoint 
– Flush dirty data blocks to database 
– Truncate WAL; prevent infinite growth 
• Autovacuum 
– Clean up dead row versions 
• BGWriter 
– Write dirty blocks so backends don't have to 
© 2013 EDB All rights reserved. 25
Be Curious 
Thank You 
© 2013 EDB All rights reserved. 26

More Related Content

What's hot (19)

PPTX
Scale out Magento 2 at AWS
root360 GmbH
 
PDF
Google Cloud platform: GKE with CI/CD using CircleCI and Flux
komaldevg
 
PDF
Building & Testing Scalable Rails Applications
evilmike
 
PPT
Architecture Of Large Scale Websites
Feng Yu
 
PPT
Data Collection & Caching using redis | Swatantra Kumar
Swatantra Kumar
 
PPTX
RedisConf18 - Video Experience Operational Insights in Real Time.
Redis Labs
 
PPT
Siebel CRM in Production - What Now?
Frank
 
PPTX
When and how to migrate from a relational database to Cassandra
Ben Slater
 
PDF
Nginx caching
reneedv
 
PDF
Writing HTTP Middleware In Go
Shiju Varghese
 
PPTX
Microservices Architecture and Containers.
imjacobclark
 
PDF
Cassandra summit 2015 - Simplifying Streaming Analytics
Brenden Matthews
 
PDF
Google Cloud & Your Data
Mike Fowler
 
PDF
Introduction to CloudStack Storage Subsystem
buildacloud
 
PDF
eCommerce Series Part 4 - Data Center
Ashwinee Kumar
 
PDF
Apache Gobblin
Mike Frampton
 
PDF
CDN implmentation consideration
Avi Shalisman
 
PDF
JS Lab`16. Андрей Колодницкий: "Разработка REST сервисов на SailsJS"
GeeksLab Odessa
 
PDF
Ingress controller present, past and future
Juraj Hantak
 
Scale out Magento 2 at AWS
root360 GmbH
 
Google Cloud platform: GKE with CI/CD using CircleCI and Flux
komaldevg
 
Building & Testing Scalable Rails Applications
evilmike
 
Architecture Of Large Scale Websites
Feng Yu
 
Data Collection & Caching using redis | Swatantra Kumar
Swatantra Kumar
 
RedisConf18 - Video Experience Operational Insights in Real Time.
Redis Labs
 
Siebel CRM in Production - What Now?
Frank
 
When and how to migrate from a relational database to Cassandra
Ben Slater
 
Nginx caching
reneedv
 
Writing HTTP Middleware In Go
Shiju Varghese
 
Microservices Architecture and Containers.
imjacobclark
 
Cassandra summit 2015 - Simplifying Streaming Analytics
Brenden Matthews
 
Google Cloud & Your Data
Mike Fowler
 
Introduction to CloudStack Storage Subsystem
buildacloud
 
eCommerce Series Part 4 - Data Center
Ashwinee Kumar
 
Apache Gobblin
Mike Frampton
 
CDN implmentation consideration
Avi Shalisman
 
JS Lab`16. Андрей Колодницкий: "Разработка REST сервисов на SailsJS"
GeeksLab Odessa
 
Ingress controller present, past and future
Juraj Hantak
 

Similar to How Databases Work - for Developers, Accidental DBAs and Managers (20)

PPTX
The Evolution of the Oracle Database - Then, Now and Later (Fontys Hogeschool...
Lucas Jellema
 
PDF
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
PDF
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
Ashnikbiz
 
PDF
Reducing Database Pain & Costs with Postgres
EDB
 
PPTX
UNIT3 DBMS.pptx operation nd management of data base
shindhe1098cv
 
PPTX
Hbase hivepig
Radha Krishna
 
PDF
8. Software Development Security
Sam Bowne
 
PDF
PostgreSQL as Enterprise Solution v1.1.pdf
Equnix Business Solutions
 
PPTX
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Lucas Jellema
 
PPTX
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB
 
PDF
Flash Camp Chennai - Social network with ORM
RIA RUI Society
 
PDF
Hpts 2011 flexible_oltp
Jags Ramnarayan
 
PDF
CISSP Prep: Ch 9. Software Development Security
Sam Bowne
 
PDF
Optimizing Open Source for Greater Database Savings & Control
EDB
 
PPTX
Python Ireland Conference 2016 - Python and MongoDB Workshop
Joe Drumgoole
 
PDF
The Central View of your Data with Postgres
EDB
 
PPTX
Doing More with Postgres - Yesterday's Vision Becomes Today's Reality
EDB
 
KEY
Appengine Nljug
Paul Bakker
 
PPTX
Fontys Lecture - The Evolution of the Oracle Database 2016
Lucas Jellema
 
PDF
8. Software Development Security
Sam Bowne
 
The Evolution of the Oracle Database - Then, Now and Later (Fontys Hogeschool...
Lucas Jellema
 
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
Ashnikbiz
 
Reducing Database Pain & Costs with Postgres
EDB
 
UNIT3 DBMS.pptx operation nd management of data base
shindhe1098cv
 
Hbase hivepig
Radha Krishna
 
8. Software Development Security
Sam Bowne
 
PostgreSQL as Enterprise Solution v1.1.pdf
Equnix Business Solutions
 
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Lucas Jellema
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB
 
Flash Camp Chennai - Social network with ORM
RIA RUI Society
 
Hpts 2011 flexible_oltp
Jags Ramnarayan
 
CISSP Prep: Ch 9. Software Development Security
Sam Bowne
 
Optimizing Open Source for Greater Database Savings & Control
EDB
 
Python Ireland Conference 2016 - Python and MongoDB Workshop
Joe Drumgoole
 
The Central View of your Data with Postgres
EDB
 
Doing More with Postgres - Yesterday's Vision Becomes Today's Reality
EDB
 
Appengine Nljug
Paul Bakker
 
Fontys Lecture - The Evolution of the Oracle Database 2016
Lucas Jellema
 
8. Software Development Security
Sam Bowne
 
Ad

More from EDB (20)

PDF
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
PDF
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
PDF
Migre sus bases de datos Oracle a la nube
EDB
 
PDF
EFM Office Hours - APJ - July 29, 2021
EDB
 
PDF
Benchmarking Cloud Native PostgreSQL
EDB
 
PDF
Las Variaciones de la Replicación de PostgreSQL
EDB
 
PDF
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
PDF
Is There Anything PgBouncer Can’t Do?
EDB
 
PDF
Data Analysis with TensorFlow in PostgreSQL
EDB
 
PDF
Practical Partitioning in Production with Postgres
EDB
 
PDF
A Deeper Dive into EXPLAIN
EDB
 
PDF
IOT with PostgreSQL
EDB
 
PDF
A Journey from Oracle to PostgreSQL
EDB
 
PDF
Psql is awesome!
EDB
 
PDF
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
PPTX
Comment sauvegarder correctement vos données
EDB
 
PDF
Cloud Native PostgreSQL - Italiano
EDB
 
PDF
New enhancements for security and usability in EDB 13
EDB
 
PPTX
Best Practices in Security with PostgreSQL
EDB
 
PDF
Cloud Native PostgreSQL - APJ
EDB
 
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
Migre sus bases de datos Oracle a la nube
EDB
 
EFM Office Hours - APJ - July 29, 2021
EDB
 
Benchmarking Cloud Native PostgreSQL
EDB
 
Las Variaciones de la Replicación de PostgreSQL
EDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
Is There Anything PgBouncer Can’t Do?
EDB
 
Data Analysis with TensorFlow in PostgreSQL
EDB
 
Practical Partitioning in Production with Postgres
EDB
 
A Deeper Dive into EXPLAIN
EDB
 
IOT with PostgreSQL
EDB
 
A Journey from Oracle to PostgreSQL
EDB
 
Psql is awesome!
EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
Comment sauvegarder correctement vos données
EDB
 
Cloud Native PostgreSQL - Italiano
EDB
 
New enhancements for security and usability in EDB 13
EDB
 
Best Practices in Security with PostgreSQL
EDB
 
Cloud Native PostgreSQL - APJ
EDB
 
Ad

Recently uploaded (20)

PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 

How Databases Work - for Developers, Accidental DBAs and Managers

  • 1. How Databases Work • Gurjeet Singh | 09.18.14 © 2013 EDB All rights reserved. 1
  • 2. Who Am I Database Architect @ EDB – Index Advisor – Optimizer Hints – Postgres Enterprise Manager – Postgres Plus Cloud Database Postgres Contributor – Postgres Hibernator and others Learnt From Mistakes © 2013 EDB All rights reserved. 2
  • 3. Goal Impart some new knowledge, that helps you do your job better. (The “Full Monty” slides is where the meat of the talk is) © 2013 EDB All rights reserved. 3
  • 4. Agenda • ACID • Application Interaction • Backend Operations • Concurrent/Cooperating Operations • OS/Disk Interaction • NoSQL © 2013 EDB All rights reserved. 4
  • 5. ACID © 2013 EDB All rights reserved. 5
  • 6. ACID Traits of a transaction in an RDBMS • Atomicity – Changes done by a transaction are one unit; all or nothing. • Consistency – Transaction end leaves database in a consistent state; constraints cannot be violated. • Isolation – Transactions behave as if only one transaction is in progress at a time. • Durability – Transactions, once committed, will not be lost. © 2013 EDB All rights reserved. 6
  • 7. NoSQL © 2013 EDB All rights reserved. 7
  • 8. NoSQL • We are not going to discuss NoSQL databases. • They compromise on at least one of ACID properties © 2013 EDB All rights reserved. 8
  • 9. Application Interaction © 2013 EDB All rights reserved. 9
  • 10. Application Interaction • Applications use a database driver • The driver uses a custom protocol (language) • Enables Client-Server/n-Tier architectures Java Ruby Python JavaScript C/C++ © 2013 EDB All rights reserved. 10
  • 11. Backend Operations © 2013 EDB All rights reserved. 11
  • 12. Backend Operations • Query Processing – Tokenize/Parse – Parse Analysis – Plan/Optimize – Execute © 2013 EDB All rights reserved. 12
  • 13. Backend Operations – Tokenize/Parse SELECT e.id, d.name FROM emp e JOIN dept d ON e.dept = d.id WHERE emp.name = 'Agent Smith'; SELECT e . id , d . name FROM emp e JOIN dept d ON e . dept = d . id WHERE emp . name = 'Agent Smith' ; © 2013 EDB All rights reserved. 13
  • 14. Backend Operations – Tokenize/Parse SELECT List FROM List WHERE List e.id d.name emp dept = = © 2013 EDB All rights reserved. 14 e.name 'Agent Smith' Parse Tree ON e.dept d.id
  • 15. Backend Operations – Parse Analysis • Ensure that – The objects (tables, columns, functions, etc.) exist – Resolve/expand views • Type Coercion © 2013 EDB All rights reserved. 15
  • 16. Backend Operations – Plan/Optimize Generate all possible plans to access objects • Compare cost of – Accessing tables using various methods ● Full Table Scan, Index Scan, Bitmap Index, etc. – Joining tables using various methods ● Nested Loop join, Hash Join, Sort-Merge Join – Other operations like distinct, ordering, grouping. • Choose the best plan • Best may mean – Fastest (e.g. LIMIT clause) – Cheapest © 2013 EDB All rights reserved. 16
  • 17. Backend Operations – Plan/Optimize Plan/Execution Tree Result Nested Loop Index Scan - emp Condition: name = 'Agent Smith' Filter: e.dept = © 2013 EDB All rights reserved. 17 Full Table Scan - dept d.id To Client
  • 18. Backend Operations - Execute • Traverse the Execution Tree recursively • Pull rows from each execution node, until exhausted • Insert/Update rows – Delete in Postgres is just an update of row header – Update is similar to Delete + Insert – Multi-Version Concurrency Control (MVCC) • Send result/rows to the client © 2013 EDB All rights reserved. 18
  • 19. Concurrent/Cooperating Operations © 2013 EDB All rights reserved. 19
  • 20. Concurrent/Cooperating Operations • Read data from disk • Share data • Locks to prevent concurrent update • Write data to disk © 2013 EDB All rights reserved. 20
  • 21. Block Structure © 2013 EDB All rights reserved. 21 Free Space Block Header Row Pointers Row Header
  • 22. MVCC Isolation; A transaction will: • Ignore changes done by newer transactions • Ignore changes done by running transactions • Ignore changes done by rolled-back transactions • Only “see” changes by older and committed transactions Effectively: • Readers don't block writers • Writers don't block readers © 2013 EDB All rights reserved. 22
  • 23. MVCC Provides • Atomicity; with the help of commit log (clog) • Isolation Consistency • Ensured by the individual backends © 2013 EDB All rights reserved. 23
  • 24. Full Monty Client 1 Client 2 Client 3 Client n Network Backend 1 Backend 2 Backend n Postmaster © 2013 EDB All rights reserved. 24 Checkpointer Autovacuum RAM Disk Cache Shared Buffers WAL Buffers Controller Cache Controller Cache BGWriter
  • 25. Full Monty • WAL – Write Ahead Log – Record change before the actual change – Sequential, always growing infinite log • Checkpoint – Flush dirty data blocks to database – Truncate WAL; prevent infinite growth • Autovacuum – Clean up dead row versions • BGWriter – Write dirty blocks so backends don't have to © 2013 EDB All rights reserved. 25
  • 26. Be Curious Thank You © 2013 EDB All rights reserved. 26