SlideShare a Scribd company logo
PostgreSQL Parameter 
Tuning-I Memory and 
Optimizer Parameters
PostgreSQL 
Architecture
postgresql.conf 
- Generally located inside data directory of the cluster 
- Each line is a holds one parameter in ‘key-value’ pair 
separated by ‘=‘ 
- You can set parameters on command line on startup 
- Supports include directive to include parameters 
from additional files
Other places to edit parameters 
- Make changes at Database level for cluster hosting 
different databases of different nature 
- Make changes at user level according to nature of 
job e.g. OLTP, Reports, Batches etc 
- Make changes at session level/transaction level 
before an exceptionally costly/different query 
- Note: Some parameters can only be changed on 
startup or in postgresql.conf
Memory Parameters
Shared Buffer- shared_buffers 
- Default value is really small- 32MB 
- A Good Value: 
- Usually for better performance set this to 15%-30% of total 
available RAM on a dedicated DB server 
- On shared servers keep it large enough to accommodate indexes 
- Remember: 
- On 32-bit setup a value above 2GB is not practical 
- Tip: 
- On v9.2 and earlier set SHMMAX to proper value before setting 
shared_buffer
Sorting Memory – work_mem 
- A higher value improves query performance faster with in-memory sort 
- You can log [log_temp_files] the sorts which spills over to disk or see them in 
explain plan [e.g. Sort Method: external merge Disk: XkB] 
- A good value: 
- Either the whole sort can be performed in memory [Sort Method: quick sort] 
- at least the intermediate result can be stored in memory [xKB in our case] 
- Remember: 
- This is ‘per sorting operation’ 
- If a statement has multiple sort requirements those many sorting space will be 
allocated 
- Tip: 
- Set the global/instance level value appropriately 
- Change values at Database, User or Session/Transaction level for specific operations
Memory for Temporary Objects– 
temp_buffer 
- Amount of memory used for each session for 
caching the temporary tables 
- A good Value: 
- Change it at session level Just before creating the first temporary table 
- Remember: 
- A session will allocate temporary buffers as needed 
- About 64bytes to 8kb of over head is incurred for allocation/increment 
when session uses temporary buffer 
- Tip: 
- Don’t change if you don’t use temporary tables
Maintenance Memory– 
maintenance_work_mem 
- Helps improve the performance of maintenance operations e.g. 
- VACUUM - CREATE INDEX - ALTER TABLE ADD FOREIGN KEY 
- A good Value: 
- Set this to a larger value than work_mem- significant to hold large tables for 
INDEXING and VACUUM operations 
- e.g. on a 64GB of RAM system, 2GB for maintenance_work_mem could be 
safe 
- Remember: 
- A sessions can do only one maintenance operation at a time 
- Generally not many maintenance operations would be done in parallel 
- Tip: 
- Parallel threads for autovacuum (max_autovacuum_worker) will consume 
multiple slots of maintenance memory
Query Planner 
Parameters
Important Note 
- These parameters are input to your optimizer 
- These parameters help optimizer decide on the 
best out of all available execution plans 
- These parameters do not 
- decide the actual performance 
- Define disk speed 
- allocate memory or disk space
Cost of Accessing a random page on Disk-random_ 
page_cost 
- Default- 4.0 
- A higher value is more likely to push the optimizer to use a table scan 
(presumably sequential fetch of pages) 
- A Good Value: 
- If you have faster disks set this to smaller values e.g. 2.0 or 3.0 
- For flash disk you may infact set to even lower values 1.5 
- Remember: 
- This parameter does not define how fast Postgres ‘will’ access random pages 
- It defines how fast Postgres ‘can expect’ the request for random pages to be 
fulfilled 
- Tip: 
- Check your explain plan and effective_cache_size (to be discussed) before 
setting/changing this parameter
Cost of Accessing a page sequentially on 
Disk- sequential_page_cost 
- Default- 1.0 
- You may want to reduce this value to account for caching effect 
- A Good Value: 
- If you have faster disks (flash disk or SDD) set this to smaller values e.g. 0.8 
or 0.9 
- Remember: 
- This parameter does not define how fast Postgres ‘will’ access sequential 
pages 
- It defines how fast Postgres ‘can expect’ the request for sequential pages to 
be fulfilled 
- Tip: 
- You must always keep this lower than random_page_cost
Memory available to OS for File system cache 
– effective_cache_size 
- Default- 128MB 
- It helps optimizer envisage how much of memory is available for 
caching files specially while considering index scans 
- A Good Value: 
- 50-80% of your RAM on a dedicated DB server is a good value 
- On a shared server estimate this value by looking at OS statistics for 
Free+Cached memory 
- Remember: 
- This parameter is not allocation of memory for Postgres it is only 
indication/input of a n estimate to Postgres 
- Tip: 
- A higher value is more likely to promote index scans
Force Plans with enable_* parameters 
- Postgres has certain enable_* parameters 
- These parameters help the optimizer include (if on) or exclude (if off) 
certain optimization techniques e.g. 
- Index utilization - Index only scans, Index scans, Bitmap scans 
- Joins- merge join, nested table loop join, hash join 
- A Good Value: 
- Its wise to leave them to default 
- Remember: 
- These are not hints! If you disabling a parameter will not use that 
optimization technique and not ‘just discourage it’ [enable_materialization is 
exception] 
- Tip: 
- Change these only for specific queries or users in specific cases
If you have more questions, 
write to us at: 
success@ashnik.com 
Website: www.ashnik.com

More Related Content

PDF
Overview of Postgres Utility Processes
 
PPTX
PDF
Linux tuning to improve PostgreSQL performance
ODP
PostgreSQL Replication in 10 Minutes - SCALE
PDF
Architecture for building scalable and highly available Postgres Cluster
PPTX
The Magic of Tuning in PostgreSQL
PDF
Linux internals for Database administrators at Linux Piter 2016
PPT
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Overview of Postgres Utility Processes
 
Linux tuning to improve PostgreSQL performance
PostgreSQL Replication in 10 Minutes - SCALE
Architecture for building scalable and highly available Postgres Cluster
The Magic of Tuning in PostgreSQL
Linux internals for Database administrators at Linux Piter 2016
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...

What's hot (20)

PDF
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PDF
Get to know PostgreSQL!
PPTX
PostgreSQL Hangout Replication Features v9.4
PDF
Out of the box replication in postgres 9.4
PDF
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
PDF
PostgreSQL High Availability in a Containerized World
PDF
PostgreSQL Scaling And Failover
PDF
Best Practices with PostgreSQL on Solaris
PPTX
Streaming replication in PostgreSQL
PDF
MySQL Server Settings Tuning
PDF
Replication Solutions for PostgreSQL
PDF
MariaDB Server Performance Tuning & Optimization
PDF
What's New in PostgreSQL 9.3
 
PDF
Deploying postgre sql on amazon ec2
PDF
Percona Xtrabackup - Highly Efficient Backups
PDF
PostgreSQL replication
PPT
MySQL Performance Tuning at COSCUP 2014
PDF
MySQL Tuning
PDF
Concurrency
PDF
What is new in PostgreSQL 14?
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Get to know PostgreSQL!
PostgreSQL Hangout Replication Features v9.4
Out of the box replication in postgres 9.4
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
PostgreSQL High Availability in a Containerized World
PostgreSQL Scaling And Failover
Best Practices with PostgreSQL on Solaris
Streaming replication in PostgreSQL
MySQL Server Settings Tuning
Replication Solutions for PostgreSQL
MariaDB Server Performance Tuning & Optimization
What's New in PostgreSQL 9.3
 
Deploying postgre sql on amazon ec2
Percona Xtrabackup - Highly Efficient Backups
PostgreSQL replication
MySQL Performance Tuning at COSCUP 2014
MySQL Tuning
Concurrency
What is new in PostgreSQL 14?
Ad

Viewers also liked (20)

PPTX
Transform your DBMS to drive engagement innovation with Big Data
PDF
FOSSASIA 2016 - 7 Tips to design web centric high-performance applications
PDF
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
PPTX
NGINX Plus PLATFORM For Flawless Application Delivery
PPTX
Tuning Slow Running SQLs in PostgreSQL
PDF
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
PDF
Building Hybrid data cluster using PostgreSQL and MongoDB
PPTX
X-DB Replication Server and MMR
PDF
2016 may-countdown-to-postgres-v96-parallel-query
PPTX
Building Data Integration and Transformations using Pentaho
PDF
PostgreSQL Deep Internal
PDF
PgDay Asia 2016 - Security Best Practices for your Postgres Deployment
PPT
A brief introduction to PostgreSQL
PPTX
Big Data Business Transformation - Big Picture and Blueprints
PDF
Data Processing Inside PostgreSQL
 
PDF
GPGPU Accelerates PostgreSQL (English)
PDF
Best Practices for a Complete Postgres Enterprise Architecture Setup
 
PDF
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
PDF
MANUAL DE CREACION DE UNA BASE DE DATOS EN POSTGRESQL
PDF
Postgresql database administration volume 1
Transform your DBMS to drive engagement innovation with Big Data
FOSSASIA 2016 - 7 Tips to design web centric high-performance applications
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
NGINX Plus PLATFORM For Flawless Application Delivery
Tuning Slow Running SQLs in PostgreSQL
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Building Hybrid data cluster using PostgreSQL and MongoDB
X-DB Replication Server and MMR
2016 may-countdown-to-postgres-v96-parallel-query
Building Data Integration and Transformations using Pentaho
PostgreSQL Deep Internal
PgDay Asia 2016 - Security Best Practices for your Postgres Deployment
A brief introduction to PostgreSQL
Big Data Business Transformation - Big Picture and Blueprints
Data Processing Inside PostgreSQL
 
GPGPU Accelerates PostgreSQL (English)
Best Practices for a Complete Postgres Enterprise Architecture Setup
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
MANUAL DE CREACION DE UNA BASE DE DATOS EN POSTGRESQL
Postgresql database administration volume 1
Ad

Similar to PostgreSQL Hangout Parameter Tuning (20)

PDF
MariaDB Performance Tuning and Optimization
PDF
Dynamics ax performance tuning
PDF
PostgreSQL Table Partitioning / Sharding
PDF
071410 sun a_1515_feldman_stephen
PDF
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
PDF
The Essential postgresql.conf
PDF
MySQL & Expression Engine EEUK2013
PDF
AutoDOPandRest
PDF
Magento e commerce performance optimization
PDF
MySQL Performance - Best practices
PDF
Performance tuning in sql server
PPTX
Investigate SQL Server Memory Like Sherlock Holmes
PDF
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PPTX
Anthony Somerset - Site Speed = Success!
PPT
MySQL Performance Secrets
PPTX
SQL 2014 In-Memory OLTP
PPT
Database performance tuning and query optimization
PDF
Modernizing your database with SQL Server 2019
PPTX
515689311-Postgresql-DBA-Architecture.pptx
PDF
PuppetConf 2016: An Introduction to Measuring and Tuning PE Performance – Cha...
MariaDB Performance Tuning and Optimization
Dynamics ax performance tuning
PostgreSQL Table Partitioning / Sharding
071410 sun a_1515_feldman_stephen
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
The Essential postgresql.conf
MySQL & Expression Engine EEUK2013
AutoDOPandRest
Magento e commerce performance optimization
MySQL Performance - Best practices
Performance tuning in sql server
Investigate SQL Server Memory Like Sherlock Holmes
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Anthony Somerset - Site Speed = Success!
MySQL Performance Secrets
SQL 2014 In-Memory OLTP
Database performance tuning and query optimization
Modernizing your database with SQL Server 2019
515689311-Postgresql-DBA-Architecture.pptx
PuppetConf 2016: An Introduction to Measuring and Tuning PE Performance – Cha...

More from Ashnikbiz (20)

PPTX
CloudOps_tool.pptx
PPTX
Webinar_CloudOps final.pptx
PPTX
Autoscaling in Kubernetes (K8s)
PPTX
Why and how to use Kubernetes for scaling of your multi-tier (n-tier) appli...
PDF
Zero trust in a multi tenant environment
PPTX
Deploy and automate ‘Secrets Management’ for a multi-cloud environment
PPTX
Deploy, move and manage Postgres across cloud platforms
PPTX
Deploy, move and manage Postgres across cloud platforms
PPTX
The Best Approach For Multi-cloud Infrastructure Provisioning-2
PPTX
The Best Approach For Multi-cloud Infrastructure Provisioning
PPTX
Which PostgreSQL is right for your multi cloud strategy? P2
PPTX
Which PostgreSQL is right for your multi cloud strategy? P1
PPTX
Reduce the complexities of managing Kubernetes clusters anywhere 2
PPTX
Reduce the complexities of managing Kubernetes clusters anywhere
PPTX
Enhance your multi-cloud application performance using Redis Enterprise P2
PPTX
Enhance your multi-cloud application performance using Redis Enterprise P1
PPTX
Gain multi-cloud versatility with software load balancing designed for cloud-...
PPTX
Gain multi-cloud versatility with software load balancing designed for cloud-...
PPTX
Enterprise-class security with PostgreSQL - 1
PPTX
Enterprise-class security with PostgreSQL - 2
CloudOps_tool.pptx
Webinar_CloudOps final.pptx
Autoscaling in Kubernetes (K8s)
Why and how to use Kubernetes for scaling of your multi-tier (n-tier) appli...
Zero trust in a multi tenant environment
Deploy and automate ‘Secrets Management’ for a multi-cloud environment
Deploy, move and manage Postgres across cloud platforms
Deploy, move and manage Postgres across cloud platforms
The Best Approach For Multi-cloud Infrastructure Provisioning-2
The Best Approach For Multi-cloud Infrastructure Provisioning
Which PostgreSQL is right for your multi cloud strategy? P2
Which PostgreSQL is right for your multi cloud strategy? P1
Reduce the complexities of managing Kubernetes clusters anywhere 2
Reduce the complexities of managing Kubernetes clusters anywhere
Enhance your multi-cloud application performance using Redis Enterprise P2
Enhance your multi-cloud application performance using Redis Enterprise P1
Gain multi-cloud versatility with software load balancing designed for cloud-...
Gain multi-cloud versatility with software load balancing designed for cloud-...
Enterprise-class security with PostgreSQL - 1
Enterprise-class security with PostgreSQL - 2

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PPTX
Spectroscopy.pptx food analysis technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
KodekX | Application Modernization Development
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
Spectroscopy.pptx food analysis technology
The AUB Centre for AI in Media Proposal.docx
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
KodekX | Application Modernization Development
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

PostgreSQL Hangout Parameter Tuning

  • 1. PostgreSQL Parameter Tuning-I Memory and Optimizer Parameters
  • 3. postgresql.conf - Generally located inside data directory of the cluster - Each line is a holds one parameter in ‘key-value’ pair separated by ‘=‘ - You can set parameters on command line on startup - Supports include directive to include parameters from additional files
  • 4. Other places to edit parameters - Make changes at Database level for cluster hosting different databases of different nature - Make changes at user level according to nature of job e.g. OLTP, Reports, Batches etc - Make changes at session level/transaction level before an exceptionally costly/different query - Note: Some parameters can only be changed on startup or in postgresql.conf
  • 6. Shared Buffer- shared_buffers - Default value is really small- 32MB - A Good Value: - Usually for better performance set this to 15%-30% of total available RAM on a dedicated DB server - On shared servers keep it large enough to accommodate indexes - Remember: - On 32-bit setup a value above 2GB is not practical - Tip: - On v9.2 and earlier set SHMMAX to proper value before setting shared_buffer
  • 7. Sorting Memory – work_mem - A higher value improves query performance faster with in-memory sort - You can log [log_temp_files] the sorts which spills over to disk or see them in explain plan [e.g. Sort Method: external merge Disk: XkB] - A good value: - Either the whole sort can be performed in memory [Sort Method: quick sort] - at least the intermediate result can be stored in memory [xKB in our case] - Remember: - This is ‘per sorting operation’ - If a statement has multiple sort requirements those many sorting space will be allocated - Tip: - Set the global/instance level value appropriately - Change values at Database, User or Session/Transaction level for specific operations
  • 8. Memory for Temporary Objects– temp_buffer - Amount of memory used for each session for caching the temporary tables - A good Value: - Change it at session level Just before creating the first temporary table - Remember: - A session will allocate temporary buffers as needed - About 64bytes to 8kb of over head is incurred for allocation/increment when session uses temporary buffer - Tip: - Don’t change if you don’t use temporary tables
  • 9. Maintenance Memory– maintenance_work_mem - Helps improve the performance of maintenance operations e.g. - VACUUM - CREATE INDEX - ALTER TABLE ADD FOREIGN KEY - A good Value: - Set this to a larger value than work_mem- significant to hold large tables for INDEXING and VACUUM operations - e.g. on a 64GB of RAM system, 2GB for maintenance_work_mem could be safe - Remember: - A sessions can do only one maintenance operation at a time - Generally not many maintenance operations would be done in parallel - Tip: - Parallel threads for autovacuum (max_autovacuum_worker) will consume multiple slots of maintenance memory
  • 11. Important Note - These parameters are input to your optimizer - These parameters help optimizer decide on the best out of all available execution plans - These parameters do not - decide the actual performance - Define disk speed - allocate memory or disk space
  • 12. Cost of Accessing a random page on Disk-random_ page_cost - Default- 4.0 - A higher value is more likely to push the optimizer to use a table scan (presumably sequential fetch of pages) - A Good Value: - If you have faster disks set this to smaller values e.g. 2.0 or 3.0 - For flash disk you may infact set to even lower values 1.5 - Remember: - This parameter does not define how fast Postgres ‘will’ access random pages - It defines how fast Postgres ‘can expect’ the request for random pages to be fulfilled - Tip: - Check your explain plan and effective_cache_size (to be discussed) before setting/changing this parameter
  • 13. Cost of Accessing a page sequentially on Disk- sequential_page_cost - Default- 1.0 - You may want to reduce this value to account for caching effect - A Good Value: - If you have faster disks (flash disk or SDD) set this to smaller values e.g. 0.8 or 0.9 - Remember: - This parameter does not define how fast Postgres ‘will’ access sequential pages - It defines how fast Postgres ‘can expect’ the request for sequential pages to be fulfilled - Tip: - You must always keep this lower than random_page_cost
  • 14. Memory available to OS for File system cache – effective_cache_size - Default- 128MB - It helps optimizer envisage how much of memory is available for caching files specially while considering index scans - A Good Value: - 50-80% of your RAM on a dedicated DB server is a good value - On a shared server estimate this value by looking at OS statistics for Free+Cached memory - Remember: - This parameter is not allocation of memory for Postgres it is only indication/input of a n estimate to Postgres - Tip: - A higher value is more likely to promote index scans
  • 15. Force Plans with enable_* parameters - Postgres has certain enable_* parameters - These parameters help the optimizer include (if on) or exclude (if off) certain optimization techniques e.g. - Index utilization - Index only scans, Index scans, Bitmap scans - Joins- merge join, nested table loop join, hash join - A Good Value: - Its wise to leave them to default - Remember: - These are not hints! If you disabling a parameter will not use that optimization technique and not ‘just discourage it’ [enable_materialization is exception] - Tip: - Change these only for specific queries or users in specific cases
  • 16. If you have more questions, write to us at: [email protected] Website: www.ashnik.com