SlideShare a Scribd company logo
PostgreSQL
worst practices
Ilya Kosmodemiansky
ik@postgresql-consulting.com
Best practices are just boring
• Never follow them, try worst practices
• Only those practices can really help you to screw the things up
most effectively
• PostgreSQL consultants are nice people, so try to make them
happy
1. Use as many count(*) as you can
• Figure 301083021830123921 is very informative for the end
user
• If it changes in a second to 30108302894839434020, it is still
informative
• select count(*) from sometable is a quite light query
• Tuple estimation from pg_catalog can never be precise
enough for you
2. Try to create as many indexes as you can
• Indexes consume no disk space
• Indexes consume no shared_bufers
• There is no overhead on DML if one and every column in a
table covered with bunch of indexes
• Optimizer will definitely choose your index once you created it
• Keep calm and create more indexes
3. Turn autovacuum off
• It is quite auxiliary process, you can easily stop it
• There is no problem at all to have 100Gb data in a database
which is 1Tb in size
• 2-3Tb RAM servers are cheap, IO is a fastest thing in modern
computing
• Besides of that, everyone likes BigData
4. Reinvent Slony
• If you need some data replication to another database, try to
implement it from scratch
• That allows you to run into all problems, PostgreSQL have
had since introducing Slony
5. Move joins to your application
• Just select * a couple of tables into the application written in
your favorite programming language
• Than join them at the application level
• Now you only need to implement nested loop join, hash join
and merge join as well as query optimizer and page cache
6. Never use graphical monitoring
• You do not need graphs
• Because it is an easy task to guess what was happened
yesterday at 2 a.m. using command line and grep only
7. Never use Foreign Keys
• Consistency control at application level always works as
expected
• You will never get data inconsistency without constraints
8. Always use text type for all columns
• It is always fun to reimplement date or ip validation in your
code
• You will never mistaken converting ”12-31-2015 03:01AM” to
”15:01 12 of undef 2015” using textfields
Questions?
ik@postgresql-consulting.com

More Related Content

What's hot (20)

PDF
Presto in my_use_case
wyukawa
 
PPTX
Compression talk
Ilya Ganelin
 
PDF
Big Data and PostgreSQL
PGConf APAC
 
PPTX
Your Guide to Streaming - The Engineer's Perspective
Ilya Ganelin
 
PPTX
Presto Meetup 2016 Small Start
Hiroshi Toyama
 
PPTX
Realtime classroom analytics powered by apache druid
Karthik Deivasigamani
 
PPTX
TPC-H in MongoDB
Aung Thu Rha Hein
 
PDF
Query Parallelism in PostgreSQL: What's coming next?
PGConf APAC
 
PDF
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Matt Fuller
 
PDF
Presto at Facebook - Presto Meetup @ Boston (10/6/2015)
Martin Traverso
 
PPTX
Ambry : Linkedin's Scalable Geo-Distributed Object Store
Sivabalan Narayanan
 
PDF
Architecture for building scalable and highly available Postgres Cluster
Ashnikbiz
 
PDF
Oracle 12c Parallel Execution New Features
Randolf Geist
 
PDF
Internals of Presto Service
Treasure Data, Inc.
 
PDF
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
PDF
Presto in my_use_case2
wyukawa
 
PDF
Migrating Oracle database to PostgreSQL
Umair Mansoob
 
PDF
Go faster with_native_compilation Part-2
Rajeev Rastogi (KRR)
 
PDF
Presto changes
N Masahiro
 
PDF
Presto - Analytical Database. Overview and use cases.
Wojciech Biela
 
Presto in my_use_case
wyukawa
 
Compression talk
Ilya Ganelin
 
Big Data and PostgreSQL
PGConf APAC
 
Your Guide to Streaming - The Engineer's Perspective
Ilya Ganelin
 
Presto Meetup 2016 Small Start
Hiroshi Toyama
 
Realtime classroom analytics powered by apache druid
Karthik Deivasigamani
 
TPC-H in MongoDB
Aung Thu Rha Hein
 
Query Parallelism in PostgreSQL: What's coming next?
PGConf APAC
 
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Matt Fuller
 
Presto at Facebook - Presto Meetup @ Boston (10/6/2015)
Martin Traverso
 
Ambry : Linkedin's Scalable Geo-Distributed Object Store
Sivabalan Narayanan
 
Architecture for building scalable and highly available Postgres Cluster
Ashnikbiz
 
Oracle 12c Parallel Execution New Features
Randolf Geist
 
Internals of Presto Service
Treasure Data, Inc.
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
Presto in my_use_case2
wyukawa
 
Migrating Oracle database to PostgreSQL
Umair Mansoob
 
Go faster with_native_compilation Part-2
Rajeev Rastogi (KRR)
 
Presto changes
N Masahiro
 
Presto - Analytical Database. Overview and use cases.
Wojciech Biela
 

Viewers also liked (20)

PDF
PostgreSQL WAL for DBAs
PGConf APAC
 
PDF
PostgreSQL on Amazon RDS
PGConf APAC
 
PDF
PostgreSQL: Past present Future
PGConf APAC
 
PDF
Security Best Practices for your Postgres Deployment
PGConf APAC
 
PDF
How to teach an elephant to rock'n'roll
PGConf APAC
 
PDF
Introduction to Vacuum Freezing and XID
PGConf APAC
 
PDF
Use Case: PostGIS and Agribotics
PGConf APAC
 
PDF
Swapping Pacemaker Corosync with repmgr
PGConf APAC
 
PDF
Secure PostgreSQL deployment
Command Prompt., Inc
 
PDF
Past, Present, and Future Analysis of the Architectural & Engineering Design ...
Lisa Dehner
 
PDF
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
JAXLondon_Conference
 
PDF
pg_hba.conf 이야기
PgDay.Seoul
 
PDF
24/7 Monitoring and Alerting of PostgreSQL
InMobi Technology
 
PDF
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
Mark Wong
 
PDF
Achieving Pci Compliace
Denish Patel
 
PDF
PgDay Asia 2016 - Security Best Practices for your Postgres Deployment
Ashnikbiz
 
ODP
Microservices Past, Present, Future
David Dawson
 
PDF
Postgres in Production - Best Practices 2014
EDB
 
PDF
(Ab)using 4d Indexing
PGConf APAC
 
PDF
5 Steps to PostgreSQL Performance
Command Prompt., Inc
 
PostgreSQL WAL for DBAs
PGConf APAC
 
PostgreSQL on Amazon RDS
PGConf APAC
 
PostgreSQL: Past present Future
PGConf APAC
 
Security Best Practices for your Postgres Deployment
PGConf APAC
 
How to teach an elephant to rock'n'roll
PGConf APAC
 
Introduction to Vacuum Freezing and XID
PGConf APAC
 
Use Case: PostGIS and Agribotics
PGConf APAC
 
Swapping Pacemaker Corosync with repmgr
PGConf APAC
 
Secure PostgreSQL deployment
Command Prompt., Inc
 
Past, Present, and Future Analysis of the Architectural & Engineering Design ...
Lisa Dehner
 
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
JAXLondon_Conference
 
pg_hba.conf 이야기
PgDay.Seoul
 
24/7 Monitoring and Alerting of PostgreSQL
InMobi Technology
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
Mark Wong
 
Achieving Pci Compliace
Denish Patel
 
PgDay Asia 2016 - Security Best Practices for your Postgres Deployment
Ashnikbiz
 
Microservices Past, Present, Future
David Dawson
 
Postgres in Production - Best Practices 2014
EDB
 
(Ab)using 4d Indexing
PGConf APAC
 
5 Steps to PostgreSQL Performance
Command Prompt., Inc
 
Ad

Similar to Lightening Talk - PostgreSQL Worst Practices (20)

PDF
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
PDF
Five steps perform_2013
PostgreSQL Experts, Inc.
 
DOC
Quick guide to PostgreSQL Performance Tuning
Ron Morgan
 
PPTX
PGDay India 2016
Himanchali -
 
PDF
Rails DB migrate SAFE.pdf
GowthamvelPalanivel
 
PDF
PostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
PPTX
High Performance and Scalability Database Design
Tung Ns
 
PDF
Writeable CTEs: The Next Big Thing
PostgreSQL Experts, Inc.
 
PPTX
Scaling a SaaS backend with PostgreSQL - A case study
Oliver Seemann
 
PDF
FOSSASIA 2016 - 7 Tips to design web centric high-performance applications
Ashnikbiz
 
PDF
Indexes don't mean slow inserts.
Anastasia Lubennikova
 
KEY
Writeable ct es_pgcon_may_2011
David Fetter
 
PPTX
SQL Server 2012 Best Practices
Microsoft TechNet - Belgium and Luxembourg
 
PPTX
Sql server infernals
Gianluca Sartori
 
PDF
Teaching PostgreSQL to new people
Tomek Borek
 
KEY
PostgreSQL
Reuven Lerner
 
PDF
The Accidental DBA
PostgreSQL Experts, Inc.
 
PPTX
Building scalable application with sql server
Chris Adkin
 
PDF
ETL Patterns with Postgres
Martin Loetzsch
 
DOCX
Mohan Testing
smittal81
 
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
Five steps perform_2013
PostgreSQL Experts, Inc.
 
Quick guide to PostgreSQL Performance Tuning
Ron Morgan
 
PGDay India 2016
Himanchali -
 
Rails DB migrate SAFE.pdf
GowthamvelPalanivel
 
PostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
High Performance and Scalability Database Design
Tung Ns
 
Writeable CTEs: The Next Big Thing
PostgreSQL Experts, Inc.
 
Scaling a SaaS backend with PostgreSQL - A case study
Oliver Seemann
 
FOSSASIA 2016 - 7 Tips to design web centric high-performance applications
Ashnikbiz
 
Indexes don't mean slow inserts.
Anastasia Lubennikova
 
Writeable ct es_pgcon_may_2011
David Fetter
 
SQL Server 2012 Best Practices
Microsoft TechNet - Belgium and Luxembourg
 
Sql server infernals
Gianluca Sartori
 
Teaching PostgreSQL to new people
Tomek Borek
 
PostgreSQL
Reuven Lerner
 
The Accidental DBA
PostgreSQL Experts, Inc.
 
Building scalable application with sql server
Chris Adkin
 
ETL Patterns with Postgres
Martin Loetzsch
 
Mohan Testing
smittal81
 
Ad

More from PGConf APAC (18)

PDF
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PDF
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PDF
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PDF
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
PDF
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PDF
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PDF
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PDF
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PDF
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PDF
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PDF
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PDF
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PDF
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
PDF
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PDF
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PDF
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
PDF
Amazon (AWS) Aurora
PGConf APAC
 
PDF
Go Faster With Native Compilation
PGConf APAC
 
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
Amazon (AWS) Aurora
PGConf APAC
 
Go Faster With Native Compilation
PGConf APAC
 

Recently uploaded (20)

PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 

Lightening Talk - PostgreSQL Worst Practices

  • 2. Best practices are just boring • Never follow them, try worst practices • Only those practices can really help you to screw the things up most effectively • PostgreSQL consultants are nice people, so try to make them happy
  • 3. 1. Use as many count(*) as you can • Figure 301083021830123921 is very informative for the end user • If it changes in a second to 30108302894839434020, it is still informative • select count(*) from sometable is a quite light query • Tuple estimation from pg_catalog can never be precise enough for you
  • 4. 2. Try to create as many indexes as you can • Indexes consume no disk space • Indexes consume no shared_bufers • There is no overhead on DML if one and every column in a table covered with bunch of indexes • Optimizer will definitely choose your index once you created it • Keep calm and create more indexes
  • 5. 3. Turn autovacuum off • It is quite auxiliary process, you can easily stop it • There is no problem at all to have 100Gb data in a database which is 1Tb in size • 2-3Tb RAM servers are cheap, IO is a fastest thing in modern computing • Besides of that, everyone likes BigData
  • 6. 4. Reinvent Slony • If you need some data replication to another database, try to implement it from scratch • That allows you to run into all problems, PostgreSQL have had since introducing Slony
  • 7. 5. Move joins to your application • Just select * a couple of tables into the application written in your favorite programming language • Than join them at the application level • Now you only need to implement nested loop join, hash join and merge join as well as query optimizer and page cache
  • 8. 6. Never use graphical monitoring • You do not need graphs • Because it is an easy task to guess what was happened yesterday at 2 a.m. using command line and grep only
  • 9. 7. Never use Foreign Keys • Consistency control at application level always works as expected • You will never get data inconsistency without constraints
  • 10. 8. Always use text type for all columns • It is always fun to reimplement date or ip validation in your code • You will never mistaken converting ”12-31-2015 03:01AM” to ”15:01 12 of undef 2015” using textfields