SlideShare a Scribd company logo
Tuning Autovacuum in PostgreSQL
Mohammad Zaid Patel
Database Consultant
Mydbops
Mydbops 16th MyWebinar
• Database Consultant for PostgreSQL
• Active Learner
• Technophile
• Intrigued in PostgreSQL and open source software
• Likes Cricket & Music
About Me
• Founded in 2016
• Services on top open source databases
• 80+ Member team
• AWS Partner
• PCI & ISO Certified Organisation
About Mydbops
Database
Consulting
Services
Managed
Database
Services
Focuses on Top Opensource database MySQL,MariaDB, MongoDB and
PostgreSQL both ON Premises and Cloud
Mydbops Services
500 + Clients In 6 Yrs. of Operations
Our Clients
Follow us on LinkedIN !
Agenda
• Database Bloat
• What is Vacuum
• What is Autovacuum
• Why Autovacuum
• Tuning Autovacuum
• Best Practices
ID NAME
1 TONY
2 STEVE
3 THOR
AVENGERS
>> UPDATE AVENGERS SET NAME='BRUCE' WHERE ID=3 ;
ID NAME
1 TONY
2 STEVE
3 BRUCE
ID NAME
1 TONY
2 STEVE
3 THOR
3 BRUCE
• SELECTS, INSERTS, UPDATES and DELETES are some of the common actions in
any database
• UPDATE = Deletion of Old value + Insertion of New Value
User A
Introduction
• Rows marked invisible or as 'dead tuple'
• UNDO log maintained inside the table
• No space reclaimed
• Dead tuples accumulation
Introduction
PostgreSQL's MVCC model !
ID NAME
1 TONY
2 STEVE
3 THOR
3 BRUCE
ID NAME
1 TONY
2 STEVE
3 BRUCE
User A
User B
>> SELECT NAME FROM AVENGERS WHERE ID=3 ;
ID NAME
1 TONY
2 STEVE
3 THOR
ID NAME
3 THOR
User B
ID NAME
1 TONY
2 STEVE
3 THOR
MVCC model
• Data consistency is maintained
• Past image and latest image
• Every row of PostgreSQL table has a version number
• Transaction isolation for each database session
• Locks acquired for querying data don't conflict with locks
acquired for writing
MVCC model
Database Bloat
Query to check bloat :


postgres=# SELECT pg_size_pretty(pg_relation_size('test')) as
table_size,pgstattuple('test')).dead_tuple_percent;








• Bloating of the Database is caused due to dead tuples
• Increased Dead Tuples = Increased Bloat
Database bloat
Why is bloat bad ?
• Slow Sequential scans
• Transaction id wraparound
• Eats up Storage
• Dead tuples > Live tuple = No more updates on the table
ID NAME
3 THOR
Xmin Xmax
1 10
Postgres uses 32 bit Transaction ID i.e 2^32 transaction IDs
Transaction ID wraparound
Transaction ID wraparound
• Limited Transaction IDs
• Once upper limit is reached , ids get wraparound
• Difficult for Postgres to figure out if data is transaction is in past or future
• Postgres shuts down daatabase to protect the data
• Warnings by Postgres
• Very Tedious to bring the database back
Transaction ID wraparound
How to remove bloat ?
VACUUM IT !
What is Vacuum ?
• An important PostgreSQL feature
• Removes the dead tuples
• Reclaims storage
• Various options
Vacuum
syntax :

VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ]

Vacuum
VACUUM FULL :
• Reclaimed storage is returned back to the OS
• High on resource consumption
• Holds up lock
• Slower than Vacuum
• Requires extra disk space
Vacuum
Vacuum
VACUUM FREEZE :
• Marks a table's contents with a very special transaction timestamp
• Freezes committed transaction IDs
• Next update will unfreeze it.
VERBOSE :
• Prints a detailed vacuum activity report for each table
Vacuum
Vacuum
ANALYZE :
• Updates statistics used by the planner
• Determines the most efficient way to execute a query
Is VACUUM perfect solution ?
• Manual
• High in Cost
• Employs Locking
• Needs extra disk space
Downsides of Vacuum
We've got Autovacuum !
What is Autovacuum ?
• Released with Postgresql version 8.3
• Background utility
• Automate the execution of VACUUM and ANALYZE
• Not required to be triggered manually
• Does not free up the space
• Reallocates deleted blocks
Autovacuum
The autovacuum daemon consists of multiple processes :
• Autovacuum launcher
• Distributes the work across time, attempting to start one worker within each database
every  'autovacuum_nap' seconds
• Maximum of 'autovacuum_max_worker' worker processes are allowed to run at the
same time
• Checks each table within its database and execute VACUUM and/or ANALYZE as
needed
• Functionality of Autovacuum depends on the settings available inside postgresql.conf
file.
Autovacuum
Disabling AUTOVACUUM on a Table:
ALTER TABLE table_name SET (autovacuum_enabled = false);

Autovacuum
Why Autovacuum ?
• Table bloating is prevented
• No locking on Tables
• Not resource-intensive
• Better Storage space utilization
• Improves FSM
Advantages of Autovacuum
• Prevents transaction id wraparound
• Faster query execution
• Faster sequential scans
• Better performance of Database
Advantages of Autovacuum
TUNING AUTOVACUUM
Tuning Autovacuum
autovacuum = ON
autovacuum = OFF
track_counts = on
Tuning Autovacuum
autovacuum_vacumm_threshold :


Specifies the minimum number of updated or deleted tuples needed to trigger a VACUUM in any
one table




Tuning Autovacuum
Tuning Autovacuum
autovacuum_analyze_threshold :


Specifies the minimum number of inserted, updated or deleted tuples needed to trigger
an ANALYZE in any one table
autovacuum_vacuum_scale_factor:


Specifies a fraction of the table size to add to autovacumm_vacuum_threshold when
deciding whether to trigger a VACUUM












Tuning Autovacuum
Tuning Autovacuum
autovacuum_analyze_scalefactor:


Specifies a fraction of the table size to add to autovacuum_analyze_threshold when deciding
whether to trigger an ANALYZE
autovacuum_naptime:


Minimum time that postgresql wait between each auto vacuum.




Tuning Autovacuum
Tuning Autovacuum
autovacuum_max_workers:


Specifies the maximum number of autovacuum processes
autovacuum_vacuum_cost_limit:
Specifies the cost delay value that will be used in automatic VACUUM operations after cost
limit is reached.
Tuning Autovacuum
Tuning Autovacuum
autovacuum_vacuum_cost_delay:
Specifies the cost limit value that will be used in automatic VACUUM operations
Tuning Autovacuum
max_parallel_maintenance_workers:
Sets the maximum number of parallel workers that can be started by a single utility
command
Tuning Autovacuum
hot_standby_feedback:
Specifies whether or not a hot standby will send feedback to the primary or upstream
standby about queries currently executing on the standby
• autovacuum = on
• autovacuum_vacuum_threshold = 50 , default
• autovacuum_analyze_threshold = 50 , default
• autovacuum_vacuum_scale_factor = 0.20 , default
• autovacuum_analyze_scale_factor = 0.20 , default
• autovacuum_naptime = 60 , default
Parameters Overview
• autovacuum_max_workers = 3, default
• autovacuum_vacuum_cost_limit = -1
• autovacuum_vacuum_cost_delay = 2ms
• max_parallel_maintenance_workers = 2
• hot_standby_feedback = on
Parameters Overview
Best practises
• Detecting Bloat
• Configuring Autovacuum suitable for most of the tables
• Maintenance windows
• Removing bloat for Indexes
• Avoid running manual vacuum/analyze for no reason
• Considering important and critical queries
• Performance after vacuum/analyze should be studied
Best Practises
Reach Us : Info@mydbops.com
Thank You

More Related Content

What's hot (20)

PDF
Galera cluster for high availability
Mydbops
 
PDF
PostgreSQL replication
NTT DATA OSS Professional Services
 
PDF
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PDF
Deep review of LMS process
Riyaj Shamsudeen
 
PDF
Tanel Poder - Scripts and Tools short
Tanel Poder
 
PDF
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
PDF
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
PDF
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Tanel Poder
 
PDF
Oracle RAC - New Generation
Anil Nair
 
PDF
MySQL Administrator 2021 - 네오클로바
NeoClova
 
DOCX
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
NeoClova
 
PDF
PostgreSQL and RAM usage
Alexey Bashtanov
 
PDF
Oracle RAC 19c: Best Practices and Secret Internals
Anil Nair
 
PDF
MySQL 상태 메시지 분석 및 활용
I Goo Lee
 
PPTX
MariaDB Galera Cluster
Abdul Manaf
 
PDF
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
PDF
PostgreSQL WAL for DBAs
PGConf APAC
 
PPTX
SQL Plan Directives explained
Mauro Pagano
 
PPTX
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
SolarWinds
 
PDF
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 
Galera cluster for high availability
Mydbops
 
PostgreSQL replication
NTT DATA OSS Professional Services
 
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
Deep review of LMS process
Riyaj Shamsudeen
 
Tanel Poder - Scripts and Tools short
Tanel Poder
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Tanel Poder
 
Oracle RAC - New Generation
Anil Nair
 
MySQL Administrator 2021 - 네오클로바
NeoClova
 
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
NeoClova
 
PostgreSQL and RAM usage
Alexey Bashtanov
 
Oracle RAC 19c: Best Practices and Secret Internals
Anil Nair
 
MySQL 상태 메시지 분석 및 활용
I Goo Lee
 
MariaDB Galera Cluster
Abdul Manaf
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
PostgreSQL WAL for DBAs
PGConf APAC
 
SQL Plan Directives explained
Mauro Pagano
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
SolarWinds
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Jaime Crespo
 

Similar to Tuning Autovacuum in Postgresql (20)

PDF
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
PostgreSQL-Consulting
 
PDF
Strategic Autovacuum
Scott Mead
 
PDF
Strategic autovacuum
Jim Mlodgenski
 
PDF
Optimizing Autovacuum: PostgreSQL's vacuum cleaner
SamaySharma10
 
PDF
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL-Consulting
 
PDF
Understanding Autovacuum
Dan Robinson
 
PPTX
Migrating To PostgreSQL
Grant Fritchey
 
PDF
Fraught Feedback: Trying and Failing to Implement Adaptive Behavior in Postgres
Melanie Plageman
 
PPTX
PostgreSQL 12: What is coming up?, Enterprise Postgres Day
EDB
 
PDF
Vacuum more efficient than ever
Masahiko Sawada
 
PDF
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Jignesh Shah
 
PDF
Nine Circles of Inferno or Explaining the PostgreSQL Vacuum
Alexey Lesovsky
 
PDF
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PPTX
The Magic of Tuning in PostgreSQL
Ashnikbiz
 
PDF
PostgreSQL High_Performance_Cheatsheet
Lucian Oprea
 
PDF
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Severalnines
 
PPTX
PostGreSQL Performance Tuning
Maven Logix
 
PPTX
Postgresql Database Administration Basic - Day1
PoguttuezhiniVP
 
DOC
Quick guide to PostgreSQL Performance Tuning
Ron Morgan
 
PDF
Islamabad PUG - 7th meetup - performance tuning
Umair Shahid
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
PostgreSQL-Consulting
 
Strategic Autovacuum
Scott Mead
 
Strategic autovacuum
Jim Mlodgenski
 
Optimizing Autovacuum: PostgreSQL's vacuum cleaner
SamaySharma10
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL-Consulting
 
Understanding Autovacuum
Dan Robinson
 
Migrating To PostgreSQL
Grant Fritchey
 
Fraught Feedback: Trying and Failing to Implement Adaptive Behavior in Postgres
Melanie Plageman
 
PostgreSQL 12: What is coming up?, Enterprise Postgres Day
EDB
 
Vacuum more efficient than ever
Masahiko Sawada
 
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Jignesh Shah
 
Nine Circles of Inferno or Explaining the PostgreSQL Vacuum
Alexey Lesovsky
 
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
The Magic of Tuning in PostgreSQL
Ashnikbiz
 
PostgreSQL High_Performance_Cheatsheet
Lucian Oprea
 
Webinar slides: An Introduction to Performance Monitoring for PostgreSQL
Severalnines
 
PostGreSQL Performance Tuning
Maven Logix
 
Postgresql Database Administration Basic - Day1
PoguttuezhiniVP
 
Quick guide to PostgreSQL Performance Tuning
Ron Morgan
 
Islamabad PUG - 7th meetup - performance tuning
Umair Shahid
 
Ad

More from Mydbops (20)

PDF
Scaling TiDB for Large-Scale Application
Mydbops
 
PDF
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 
PDF
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mydbops
 
PDF
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Mydbops
 
PDF
AWS Blue Green Deployment for Databases - Mydbops
Mydbops
 
PDF
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
Mydbops
 
PDF
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
Mydbops
 
PDF
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Mydbops
 
PDF
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
PDF
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Mydbops
 
PDF
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
Mydbops
 
PDF
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
PDF
Demystifying Real time Analytics with TiDB
Mydbops
 
PDF
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
PDF
Efficient MySQL Indexing and what's new in MySQL Explain
Mydbops
 
PDF
Scale your database traffic with Read & Write split using MySQL Router
Mydbops
 
PDF
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Mydbops
 
PDF
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mydbops
 
PDF
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mydbops
 
PDF
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Mydbops
 
Scaling TiDB for Large-Scale Application
Mydbops
 
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mydbops
 
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Mydbops
 
AWS Blue Green Deployment for Databases - Mydbops
Mydbops
 
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
Mydbops
 
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
Mydbops
 
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Mydbops
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Mydbops
 
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
Mydbops
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
Demystifying Real time Analytics with TiDB
Mydbops
 
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Efficient MySQL Indexing and what's new in MySQL Explain
Mydbops
 
Scale your database traffic with Read & Write split using MySQL Router
Mydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mydbops
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Mydbops
 
Ad

Recently uploaded (20)

PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PPTX
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
PPT
Testing and final inspection of a solar PV system
MuhammadSanni2
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
Distribution reservoir and service storage pptx
dhanashree78
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
Testing and final inspection of a solar PV system
MuhammadSanni2
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 

Tuning Autovacuum in Postgresql