SlideShare a Scribd company logo
4
Most read
5
Most read
12
Most read
Getting Started with
Postgresql
For Charlotte SQL Saturday on 10/20/2018
By Ramu Pulipati
Sponsors
About Me
Cofounder / CTO at Botsplash
Software-as-a-service omnichannel
messaging platform to engage businesses
and customers.
botsplash.com
About Postgresql
• Free – Open Source RDMS alternative to Microsoft SQL Server,
MySQL, Oracle, Mongo DB or any RDBMS and NoSQL databases
• Battle tested for over 30 years with continuous improvements to
support modern applications
• Rich ANSI/ISO Complaint SQL, JSON and Multiple Languages support
• Built-in and extensions for high scalability, geolocation and time series
based applications
• Hosted Providers and Commercial Support
• Used for embedded database, web applications and data warehouses
History & What’s new Version Major Feature
V11
10/18/2018
Partition & Index Improvements
Query Parallelism Improvements
Just-in-time compilation
V10
10/05/2017
Declarative Table Partitions
Logical Replication
Improved Monitoring and Control
V9.6
09/29/2016
Parallel Query
Foreign Data Wrappers
Replication
V9.5
07/01/2016
JSONB Modifying Operators
Row level security
UPSERT statement
V9.4
12/18/2014
Introduce JSONB
Materialized View Improvements
Source: Postgresql Releases
Capabilities
• Full featured Database
• ACID Transactions
• Mature Server Side Programming
• Hot Standby and High Availability
• Online backups
• Point-in-time recovery
• Native Table Partitioning
• Spatial Functionality
• Full Text Search
• JSON and HStore support
Source: Introduction to Postgresql Slideshare
80%
Commercial
Databases
Postgresql
Capabilities (contd …)
• Replication and Read Replicas
• Built-in pub-sub queue
• Multiple schemas with security
• Row level security
• Native SSL Support
• Data Level Encryption
• Extensions
• Database sharding
• Timeseries data
• Multi-tenancy
• Extensible and Customizable
Licensing & Community
• BSD License open for Open
Source, Private and
Commercial use
• No vendor Lock-in
• Predictable releases
• Faster Bug fixes
• Active Community
Source: postgresql.org
Compare to RDBMS
• MySQL
• Has better write performance but
Postgres is ACID compliant and has
better features, reliability and
consistency.
• SQL Server
• Featureful with recently introduced
JSON support. Postgres has
superset of features and scalable
with extensions.
• Oracle
• Most comprehensive database but
very expensive.
• Mongo Db
• Postgresql outshines read/write for
unstructured with JSONB.
Source: NoSQL Performance Benchmark 02/27/2018
Getting started with postgresql
Features
• Affordability
• Technology
• Security
• Flexibility
• Stability
• Extensibility
• Reliability
• Predictability
• Community
• Auditability
Source: Introduction to Postgresql Slideshare
Getting Started
• Download and Install
• Windows packaged from EnterpriseDb
• Linux from apt or source
• Mac installations using homebrew.
• Production recommended on *nix
systems. Postgres 11 supports Windows
2012 R2 deployment.
• Cloud hosted databases from Compose,
Citus Data, AWS RDS, Goolge CloudSql,
Azure Databases are excellent choice.
• Be careful with Docker/Kubernetes
deployments.
Postgresql Client
• Instance accessed from
TCP/IP Port: 5432 default
• CLI/IDE Clients
• PSQL, PgAdmin 4, PGCLI,
TablePlus, Navicat
• Application Clients
• Python SqlAlchemy, NodeJs
Pg, C# Client, Golang pq
Sample Connection String: postgres://username:password@127.0.0.1:5432/northwind
Postgresql Architecture
• Multi-process
architecture
• Primary postmaster
• Per connection backend
process
• Background maintenance
processes
• Use pgBouncer to load
balance large number of
connections
Source: The Internals of Postgresql
Schema and SQL Support
• Basic and Complex data types
• Complex Queries
• Functions, Operators and Aggregate
functions
• Transactional Integrity
• Indexes
• Procedural Language
• Optimized for data storage
• Extend and create custom data types
• Error handling
Data Type Commonly Used Names
Number Smallint, integer, Bigint, decimal,
Money
Number
(auto)
Serial, BigSerial
Character Char, nchar, Text
Binary Bytea
Date Time Timestamp with timezone,
Timestamp without Timezone,
interval
Collections Array, JSON, JSONB
Misc Boolean, UUID, Geo Types, Network
Address Mac Address, Custom Types
Full Text
Search
TsVector, TsQuery
See details from tutorials point
Demo Sample Table and DDL functions
Table DDL
Sample Function
More SQL / NoSQL Support
• Case Sensitive Schema Names
• Case Sensitive Data Storage
• Type casting
• Date Time formatting
• Common Table Expressions
• Array Data Types
• Upserts
• Pivot Tables crosstab function
• Materialized Views
• HStore
• JSONB Structure
• Rich Functions Support
• EXPLAIN ANALYZE
• Pg_stat
Psql tricks and tips
Command Description
l List of all databases
c <db> Change database name
d Show all objects in database
d <item> Describe database item
x [auto] Show one record at a time
timing Turn on/off sql timing
e Edit in an editor (vi or preferred editor)
copy … Save results to CSV file
h Help with SQL
Ctrl + R Search previous SQL command
ir Reference SQL file
Source: pgdash.io
Concurrency - MVCC
• Postgres uses “Multi-version concurrency control”. More details from
postgres internals or interdb.
• All reads are from the snapshot of the database until committed.
• Advantage of this method is reading does not block writing and vice-
versa. Isolation at “read-committed” level
• This method supports table level and row level locking as well.
• Other databases that use this technique are Oracle, CouchDB, etc
Indexes
• Index Support
• Single Column
• Multi Column
• Unique
• Partial Indexes
• Expression Indexes
• Implicit Indexes (PK, UK)
• Index Types
• B-Tree: Balanced Trees used in most databases
• Generalized Inverted Index (GIN): Useful for full text search
• Generalized Search Tree (GIST): Useful for geometric and full text search
B-Tree
Disadvantages / Limits
• Database only solution
• Few available tools compared to
commercial. PgAdmin is catching
up but relatively new.
• CPU bound queries and table
inheritance based partitioning
before v10.
• Limited Talent pool
Source: https://www.youtube.com/watch?v=6p2TNPabt6M
Source: Postgres limits from sreenstepslive.com
Best Practices
• Performance Optimization
• Do not read from Database at all
• Use indexes efficiently
• Use pg_stats collector to monitor usage and performance
• Vacuum regularly to clean up storage
• Bench mark hardware and optimize pg parameters
• Always use SSL for connectivity in untrusted networks
References and Follow up
• Introduction to Postgresql slideshare
• The Internals of Postgresql
• Postgresql excercises
• Postgres Blogs: 2nd Quadrant, Percona and Citus Data, Citus - Craig
Kerstiens
Questions? Contact me at ramu@botsplash.com

More Related Content

PPTX
PostgreSQL Database Slides
ODP
Introduction to PostgreSQL
PPTX
PDF
Postgresql tutorial
PDF
PostgreSQL Tutorial For Beginners | Edureka
PDF
Get to know PostgreSQL!
PPTX
PostgreSQL- An Introduction
ODP
OpenGurukul : Database : PostgreSQL
PostgreSQL Database Slides
Introduction to PostgreSQL
Postgresql tutorial
PostgreSQL Tutorial For Beginners | Edureka
Get to know PostgreSQL!
PostgreSQL- An Introduction
OpenGurukul : Database : PostgreSQL

What's hot (20)

PDF
PostgreSQL Deep Internal
PDF
Mastering PostgreSQL Administration
 
PPTX
introduction to NOSQL Database
PDF
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
PPTX
Improve PostgreSQL replication with Oracle GoldenGate
PDF
PostgreSQL WAL for DBAs
PPTX
Introduction to PostgreSQL
PPTX
Introduction to Apache Spark
PDF
Cassandra Database
PDF
Introduction to Cassandra
PDF
Spark SQL
PPT
Sql Server Basics
PDF
patroni-based citrus high availability environment deployment
PDF
PostgreSQL Replication High Availability Methods
PDF
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
PDF
How to Manage Scale-Out Environments with MariaDB MaxScale
PDF
PostgreSQL HA
ODP
Ms sql-server
DOC
PDF
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
PostgreSQL Deep Internal
Mastering PostgreSQL Administration
 
introduction to NOSQL Database
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
Improve PostgreSQL replication with Oracle GoldenGate
PostgreSQL WAL for DBAs
Introduction to PostgreSQL
Introduction to Apache Spark
Cassandra Database
Introduction to Cassandra
Spark SQL
Sql Server Basics
patroni-based citrus high availability environment deployment
PostgreSQL Replication High Availability Methods
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
How to Manage Scale-Out Environments with MariaDB MaxScale
PostgreSQL HA
Ms sql-server
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Ad

Similar to Getting started with postgresql (20)

PDF
Migrating to postgresql
PDF
0292-introduction-postgresql.pdf
PDF
PostgreSQL 10; Long Awaited Enterprise Solutions
PDF
An evening with Postgresql
PDF
PostgreSQL: present and near future
PPTX
PostgreSQL as an Alternative to MSSQL
PDF
Learning postgresql
PDF
PostgreSQL Prologue
PDF
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
PDF
Beyond Postgres: Interesting Projects, Tools and forks
PDF
PostgreSQL - Case Study
PPTX
PostgreSQL - Object Relational Database
PDF
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
PDF
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
PDF
Bn 1016 demo postgre sql-online-training
PDF
PostgreSQL : Introduction
PPTX
Postgre sql best_practices
PDF
PGConf.ASIA 2019 Bali - Keynote Speech 2 - Ivan Pachenko
PDF
9.6_Course Material-Postgresql_002.pdf
PDF
Introduction to PostgreSQL for System Administrators
Migrating to postgresql
0292-introduction-postgresql.pdf
PostgreSQL 10; Long Awaited Enterprise Solutions
An evening with Postgresql
PostgreSQL: present and near future
PostgreSQL as an Alternative to MSSQL
Learning postgresql
PostgreSQL Prologue
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Beyond Postgres: Interesting Projects, Tools and forks
PostgreSQL - Case Study
PostgreSQL - Object Relational Database
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Bn 1016 demo postgre sql-online-training
PostgreSQL : Introduction
Postgre sql best_practices
PGConf.ASIA 2019 Bali - Keynote Speech 2 - Ivan Pachenko
9.6_Course Material-Postgresql_002.pdf
Introduction to PostgreSQL for System Administrators
Ad

More from botsplash.com (14)

PPTX
Bootstrap SaaS startup using Open Source Tools
PPTX
Devops Days, 2019 - Charlotte
PPTX
Building NLP solutions for Davidson ML Group
PPTX
Building NLP solutions using Python
PPTX
Chat interfaces, Extension to Digital Marketing
PPTX
Cloud computing options
PPTX
Data Science meets Digital Marketing
PPTX
botsplash deep dive
PPTX
Building Twitter bot using Python
PPTX
Python for data science
PPTX
Live development & tools
PPTX
AI Use Cases discussion
PPTX
Career advice for beginner software engineers
PPTX
Node.js Getting Started &amd Best Practices
Bootstrap SaaS startup using Open Source Tools
Devops Days, 2019 - Charlotte
Building NLP solutions for Davidson ML Group
Building NLP solutions using Python
Chat interfaces, Extension to Digital Marketing
Cloud computing options
Data Science meets Digital Marketing
botsplash deep dive
Building Twitter bot using Python
Python for data science
Live development & tools
AI Use Cases discussion
Career advice for beginner software engineers
Node.js Getting Started &amd Best Practices

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
A Presentation on Artificial Intelligence
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

Getting started with postgresql

  • 1. Getting Started with Postgresql For Charlotte SQL Saturday on 10/20/2018 By Ramu Pulipati
  • 3. About Me Cofounder / CTO at Botsplash Software-as-a-service omnichannel messaging platform to engage businesses and customers. botsplash.com
  • 4. About Postgresql • Free – Open Source RDMS alternative to Microsoft SQL Server, MySQL, Oracle, Mongo DB or any RDBMS and NoSQL databases • Battle tested for over 30 years with continuous improvements to support modern applications • Rich ANSI/ISO Complaint SQL, JSON and Multiple Languages support • Built-in and extensions for high scalability, geolocation and time series based applications • Hosted Providers and Commercial Support • Used for embedded database, web applications and data warehouses
  • 5. History & What’s new Version Major Feature V11 10/18/2018 Partition & Index Improvements Query Parallelism Improvements Just-in-time compilation V10 10/05/2017 Declarative Table Partitions Logical Replication Improved Monitoring and Control V9.6 09/29/2016 Parallel Query Foreign Data Wrappers Replication V9.5 07/01/2016 JSONB Modifying Operators Row level security UPSERT statement V9.4 12/18/2014 Introduce JSONB Materialized View Improvements Source: Postgresql Releases
  • 6. Capabilities • Full featured Database • ACID Transactions • Mature Server Side Programming • Hot Standby and High Availability • Online backups • Point-in-time recovery • Native Table Partitioning • Spatial Functionality • Full Text Search • JSON and HStore support Source: Introduction to Postgresql Slideshare 80% Commercial Databases Postgresql
  • 7. Capabilities (contd …) • Replication and Read Replicas • Built-in pub-sub queue • Multiple schemas with security • Row level security • Native SSL Support • Data Level Encryption • Extensions • Database sharding • Timeseries data • Multi-tenancy • Extensible and Customizable
  • 8. Licensing & Community • BSD License open for Open Source, Private and Commercial use • No vendor Lock-in • Predictable releases • Faster Bug fixes • Active Community Source: postgresql.org
  • 9. Compare to RDBMS • MySQL • Has better write performance but Postgres is ACID compliant and has better features, reliability and consistency. • SQL Server • Featureful with recently introduced JSON support. Postgres has superset of features and scalable with extensions. • Oracle • Most comprehensive database but very expensive. • Mongo Db • Postgresql outshines read/write for unstructured with JSONB. Source: NoSQL Performance Benchmark 02/27/2018
  • 11. Features • Affordability • Technology • Security • Flexibility • Stability • Extensibility • Reliability • Predictability • Community • Auditability Source: Introduction to Postgresql Slideshare
  • 12. Getting Started • Download and Install • Windows packaged from EnterpriseDb • Linux from apt or source • Mac installations using homebrew. • Production recommended on *nix systems. Postgres 11 supports Windows 2012 R2 deployment. • Cloud hosted databases from Compose, Citus Data, AWS RDS, Goolge CloudSql, Azure Databases are excellent choice. • Be careful with Docker/Kubernetes deployments.
  • 13. Postgresql Client • Instance accessed from TCP/IP Port: 5432 default • CLI/IDE Clients • PSQL, PgAdmin 4, PGCLI, TablePlus, Navicat • Application Clients • Python SqlAlchemy, NodeJs Pg, C# Client, Golang pq Sample Connection String: postgres://username:password@127.0.0.1:5432/northwind
  • 14. Postgresql Architecture • Multi-process architecture • Primary postmaster • Per connection backend process • Background maintenance processes • Use pgBouncer to load balance large number of connections Source: The Internals of Postgresql
  • 15. Schema and SQL Support • Basic and Complex data types • Complex Queries • Functions, Operators and Aggregate functions • Transactional Integrity • Indexes • Procedural Language • Optimized for data storage • Extend and create custom data types • Error handling Data Type Commonly Used Names Number Smallint, integer, Bigint, decimal, Money Number (auto) Serial, BigSerial Character Char, nchar, Text Binary Bytea Date Time Timestamp with timezone, Timestamp without Timezone, interval Collections Array, JSON, JSONB Misc Boolean, UUID, Geo Types, Network Address Mac Address, Custom Types Full Text Search TsVector, TsQuery See details from tutorials point
  • 16. Demo Sample Table and DDL functions Table DDL Sample Function
  • 17. More SQL / NoSQL Support • Case Sensitive Schema Names • Case Sensitive Data Storage • Type casting • Date Time formatting • Common Table Expressions • Array Data Types • Upserts • Pivot Tables crosstab function • Materialized Views • HStore • JSONB Structure • Rich Functions Support • EXPLAIN ANALYZE • Pg_stat
  • 18. Psql tricks and tips Command Description l List of all databases c <db> Change database name d Show all objects in database d <item> Describe database item x [auto] Show one record at a time timing Turn on/off sql timing e Edit in an editor (vi or preferred editor) copy … Save results to CSV file h Help with SQL Ctrl + R Search previous SQL command ir Reference SQL file Source: pgdash.io
  • 19. Concurrency - MVCC • Postgres uses “Multi-version concurrency control”. More details from postgres internals or interdb. • All reads are from the snapshot of the database until committed. • Advantage of this method is reading does not block writing and vice- versa. Isolation at “read-committed” level • This method supports table level and row level locking as well. • Other databases that use this technique are Oracle, CouchDB, etc
  • 20. Indexes • Index Support • Single Column • Multi Column • Unique • Partial Indexes • Expression Indexes • Implicit Indexes (PK, UK) • Index Types • B-Tree: Balanced Trees used in most databases • Generalized Inverted Index (GIN): Useful for full text search • Generalized Search Tree (GIST): Useful for geometric and full text search B-Tree
  • 21. Disadvantages / Limits • Database only solution • Few available tools compared to commercial. PgAdmin is catching up but relatively new. • CPU bound queries and table inheritance based partitioning before v10. • Limited Talent pool Source: https://www.youtube.com/watch?v=6p2TNPabt6M Source: Postgres limits from sreenstepslive.com
  • 22. Best Practices • Performance Optimization • Do not read from Database at all • Use indexes efficiently • Use pg_stats collector to monitor usage and performance • Vacuum regularly to clean up storage • Bench mark hardware and optimize pg parameters • Always use SSL for connectivity in untrusted networks
  • 23. References and Follow up • Introduction to Postgresql slideshare • The Internals of Postgresql • Postgresql excercises • Postgres Blogs: 2nd Quadrant, Percona and Citus Data, Citus - Craig Kerstiens Questions? Contact me at ramu@botsplash.com

Editor's Notes

  • #3: A quick comment about sponsors. SQL Saturdays cannot take place without the funding provided by sponsors. The speakers are not paid. The organizers and other folks running around making sure this event runs smoothly are all volunteers. However, his facility, the food, and other expenses that go into putting on an event of this magnitude requires money. Sponsors provide that money. So, show your appreciation by saying hi and thank you when you stop by the sponsor tables to stuff your raffle ticket into the box. You might even take a couple of minutes to ask about their product and services. You may learn something valuable that you can bring back to your work, or that might become a career opportunity. It's all part of the very important networking you should be doing while you are here.
  • #5: PostgreSQL is an object-relational database management system (ORDBMS) based on POSTGRES, Version 4.2, developed at the University of California at Berkeley Computer Science Department. POSTGRES pioneered many concepts that only became available in some commercial database systems much later.
  • #10: ACID (Atomicity, Consistency, Isolation, Durability) https://www.youtube.com/watch?v=6p2TNPabt6M
  • #24: https://www.slideshare.net/ScaleGrid/understanding-high-availability-options-in-postgresql?qid=d9d63ef4-7140-44a0-b9c6-5a5fafca02a0&v=&b=&from_search=18