Monitoring Autovacuum in Azure PostgreSQL Flexible Server
Published Feb 08 2023 07:16 PM 4,922 Views
Microsoft

PostgreSQL is a powerful open-source relational database management system that is widely used in many applications. One of the key features of PostgreSQL is its automatic vacuuming process, which is designed to reclaim space and improve performance by removing dead tuples and cleaning up the database. However, monitoring this process can be challenging, as it is performed automatically in the background and can have a significant impact on your database's performance. Today, we are releasing #12 new metrics to monitor autovacuum performance. Each metric is emitted at a 30 minute frequency and has up to 93 days of retention. Customers can configure alerts on the metrics and can also access the new metrics dimensions, to split and filter the metrics data on database name. In this blog post, we will discuss how to use the new metrics to monitor and optimize the autovacuum process in Azure database for postgres – flexible server. For a complete list monitoring metrics, please refer Monitor metrics on Azure Database for PostgreSQL - Flexible Server.

What is a dead tuple?

Let us first understand what a dead tuple is in PostgreSQL. A "dead tuple" is an older version of a row on a table that has been marked as no longer needed. This occurs when a row is updated or deleted, and the latest version of the row is created. Dead tuples will eventually be reclaimed by the system's automatic vacuum process, which removes them by marking their space as available for future reuse. The removal of dead tuples is important because it helps to reduce space utilization and improve performance by avoiding unnecessary I/O fetches. Autovacuum is a background process that runs automatically in PostgreSQL to reclaim space and improve database performance. It works by removing dead tuples and cleaning up the database. This process is triggered automatically when a certain threshold of dead tuples is reached and can be configured to run at specific intervals.

Why monitor autovacuum?

 

Typically, once you have enabled auto vacuuming in Azure Database for Postgres Flexible Server, you don't need to think about how or when the vacuuming is performed, as the process is automatically handled by the database. However, on a busy server with a very high transactional workload, vacuuming schedules may not be able to keep up with the pace of the changes. In some worse situations, vacuum processes may not be running at all, that in turn will negatively impact database performance and resource usage. With autovacuum metrics, our goal is to expose some key monitoring metrics, that will help our customers to ensure automatic vacuuming is working as expected.

 

To monitor the performance of autovacuum, the first thing to verify following server parameters:

  1. autovacuum_vacuum_cost_limit - Controls the cost of the vacuuming process within a round.
  2. autovacuum_vacuum_cost_delay - Is the cost delay value in milliseconds that will be used in autovacuum operations.
  3. autovacuum_vacuum_scale_factor - Decides how often the autovacuum process should run.

For example, if the autovacuum_vacuum_scale_factor is set to too low, autovacuum may run too frequently and consume too many resources. If it is set too high, the autovacuum may not run frequently enough and the database may become cluttered with dead tuples.

 

Another important data to observe is the number of dead tuples in the database. Now you can do this by simply watching Estimated Dead Rows User Tables and Estimated Live Rows User Tables metrics. If you notice a high number of dead tuples, you can manually trigger a vacuum on that database (or table) to clean it up.

 

Picture1.png

 

If a table is manually vacuumed or analyzed, this can now be easily monitored using Analyze Counter User Tables and Vacuum Counter User Tables. In addition, you can use User Tables AutoVacuumed and User Tables AutoAnalyzed metrics to find the number of tables that were auto-vacuumed and auto-analyzed in a database, and corelate this with the User Tables Counter metrics.

 

Picture2.png

 

Finally, it is also important to understand and perfect the vacuuming process to ensure that it is running efficiently. You can check the number of times user tables have been auto-vacuumed or auto-analyzed using AutoVacuum Counter User Tables and AutoAnalyze Counter User Tables metrics, respectively. If you notice the autovacuum process is running too often or otherwise, then tune this by adjusting the server parameters I discussed above.

 

In conclusion, monitoring and optimizing the autovacuum process in PostgreSQL is essential for maintaining the performance and health of your Azure postgres database instance. By understanding how autovacuum works, monitoring key metrics, and optimizing the process, you can ensure that your database is running at peak performance and avoid any potential issues.

 

Summary

 

In this post, I shared with you a list of metrics that you can use to monitor and tune autovacuum performance for Azure database for postgres flexible server. To start using autovacuum metrics, please refer Monitoring Azure Postgres Flexible ServerI hope that this post provides you with a better understanding of autovacuum in Azure database for PostgreSQL and helps make your life as a database owner easier and more productive. We are always eager to get your feedback, please reach out via email to us at Ask Azure  DB for PostgreSQL

 

Acknowledgement


Special thanks to Sergiu Ernu and Sarat Balijepalli for co-authoring this post.

Version history
Last update:
‎Feb 10 2024 02:52 PM
Updated by: