You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/postgresql/flexible-server/how-to-autovacuum-tuning.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ This article provides an overview of the autovacuum feature for [Azure Database
17
17
18
18
Internal data consistency in PostgreSQL is based on the Multi-Version Concurrency Control (MVCC) mechanism, which allows the database engine to maintain multiple versions of a row and provides greater concurrency with minimal blocking between the different processes.
19
19
20
-
PostgreSQL databases need appropriate maintenance. For example, when a row is deleted, it is not removed physically. Instead, the row is marked as “dead”. Similarly for updates, the row is marked as "dead" and a new version of the row is inserted. These operations leave behind dead records, called dead tuples, even after all the transactions that might see those versions finish. Unless cleaned up, dead tuples remain, consuming disk space and bloating tables and indexes which result in slow query performance.
20
+
PostgreSQL databases need appropriate maintenance. For example, when a row is deleted, it isn't removed physically. Instead, the row is marked as “dead”. Similarly for updates, the row is marked as "dead" and a new version of the row is inserted. These operations leave behind dead records, called dead tuples, even after all the transactions that might see those versions finish. Unless cleaned up, dead tuples remain, consuming disk space and bloating tables and indexes which result in slow query performance.
21
21
22
22
PostgreSQL uses a process called autovacuum to automatically clean up dead tuples.
23
23
@@ -26,14 +26,14 @@ PostgreSQL uses a process called autovacuum to automatically clean up dead tuple
26
26
27
27
Autovacuum reads pages looking for dead tuples, and if none are found, autovacuum discard the page. When autovacuum finds dead tuples, it removes them. The cost is based on:
28
28
29
-
-`vacuum_cost_page_hit`: Cost of reading a page that is already in shared buffers and does not need a disk read. The default value is set to 1.
30
-
-`vacuum_cost_page_miss`: Cost of fetching a page that is not in shared buffers. The default value is set to 10.
29
+
-`vacuum_cost_page_hit`: Cost of reading a page that is already in shared buffers and doesn't need a disk read. The default value is set to 1.
30
+
-`vacuum_cost_page_miss`: Cost of fetching a page that isn't in shared buffers. The default value is set to 10.
31
31
-`vacuum_cost_page_dirty`: Cost of writing to a page when dead tuples are found in it. The default value is set to 20.
32
32
33
33
The amount of work autovacuum does depends on two parameters:
34
34
35
-
-`autovacuum_vacuum_cost_limit` is the amount of work autovacuum does in one go and once the cleanup process is done, the amount of time autovacuum is asleep.
36
-
-`autovacuum_vacuum_cost_delay` number of milliseconds.
35
+
-`autovacuum_vacuum_cost_limit` is the amount of work autovacuum does in one go.
36
+
-`autovacuum_vacuum_cost_delay` number of milliseconds that autovacuum is asleep after it has reached the cost limit specified by the `autovacuum_vacuum_cost_limit` parameter.
37
37
38
38
39
39
In Postgres versions 9.6, 10 and 11 the default for `autovacuum_vacuum_cost_limit` is 200 and `autovacuum_vacuum_cost_delay` is 20 milliseconds.
@@ -121,7 +121,7 @@ Use the following query to list the tables in a database and identify the tables
121
121
```
122
122
123
123
> [!NOTE]
124
-
> The query does not take into consideration that autovacuum can be configured on a per-table basis using the "alter table" DDL command.
124
+
> The query doesn't take into consideration that autovacuum can be configured on a per-table basis using the "alter table" DDL command.
125
125
126
126
127
127
## Common autovacuum problems
@@ -137,7 +137,7 @@ By default, `autovacuum_vacuum_cost_limit` is set to –1, meaning autovacuum
137
137
138
138
If `autovacuum_vacuum_cost_limit` is set to `-1` then autovacuum uses the `vacuum_cost_limit` parameter, but if `autovacuum_vacuum_cost_limit` itself is set to greater than `-1` then `autovacuum_vacuum_cost_limit` parameter is considered.
139
139
140
-
In case the autovacuum is not keeping up, the following parameters may be changed:
140
+
In case the autovacuum isn't keeping up, the following parameters may be changed:
141
141
142
142
|Parameter |Description |
143
143
|---------|---------|
@@ -146,7 +146,7 @@ In case the autovacuum is not keeping up, the following parameters may be change
146
146
|`autovacuum_vacuum_cost_delay`|**Postgres Versions 9.6,10,11** - Default: `20 ms`. The parameter may be decreased to `2-10 ms`. </br> **Postgres Versions 12 and above** - Default: `2 ms`. |
147
147
148
148
> [!NOTE]
149
-
> The `autovacuum_vacuum_cost_limit` value is distributed proportionally among the running autovacuum workers, so that if there is more than one, the sum of the limits for each worker does not exceed the value of the `autovacuum_vacuum_cost_limit` parameter
149
+
> The `autovacuum_vacuum_cost_limit` value is distributed proportionally among the running autovacuum workers, so that if there is more than one, the sum of the limits for each worker doesn't exceed the value of the `autovacuum_vacuum_cost_limit` parameter
150
150
151
151
### Autovacuum constantly running
152
152
@@ -165,12 +165,12 @@ Autovacuum tries to start a worker on each database every `autovacuum_naptime`
165
165
166
166
For example, if a server has 60 databases and `autovacuum_naptime` is set to 60 seconds, then the autovacuum worker starts every second [autovacuum_naptime/Number of DBs].
167
167
168
-
It is a good idea to increase `autovacuum_naptime` if there are more databases in a cluster. At the same time, the autovacuum process can be made more aggressive by increasing the `autovacuum_cost_limit` and decreasing the `autovacuum_cost_delay` parameters and increasing the `autovacuum_max_workers` from the default of 3 to 4 or 5.
168
+
It's a good idea to increase `autovacuum_naptime` if there are more databases in a cluster. At the same time, the autovacuum process can be made more aggressive by increasing the `autovacuum_cost_limit` and decreasing the `autovacuum_cost_delay` parameters and increasing the `autovacuum_max_workers` from the default of 3 to 4 or 5.
169
169
170
170
171
171
### Out of memory errors
172
172
173
-
Overly aggressive `maintenance_work_mem` values could periodically cause out-of-memory errors in the system. It is important to understand available RAM on the server before any change to the `maintenance_work_mem` parameter is made.
173
+
Overly aggressive `maintenance_work_mem` values could periodically cause out-of-memory errors in the system. It's important to understand available RAM on the server before any change to the `maintenance_work_mem` parameter is made.
174
174
175
175
176
176
### Autovacuum is too disruptive
@@ -184,11 +184,11 @@ Evaluate the parameters `autovacuum_vacuum_cost_delay`, `autovacuum_vacuum_cost_
184
184
If autovacuum is too disruptive, consider the following:
185
185
186
186
- Increase `autovacuum_vacuum_cost_delay` and reduce `autovacuum_vacuum_cost_limit` if set higher than the default of 200.
187
-
- Reduce the number of `autovacuum_max_workers` if it is set higher than the default of 3.
187
+
- Reduce the number of `autovacuum_max_workers` if it's set higher than the default of 3.
188
188
189
189
#### Too many autovacuum workers
190
190
191
-
Increasing the number of autovacuum workers will not necessarily increase the speed of vacuum. Having a high number of autovacuum workers is not recommended.
191
+
Increasing the number of autovacuum workers will not necessarily increase the speed of vacuum. Having a high number of autovacuum workers isn't recommended.
192
192
193
193
Increasing the number of autovacuum workers will result in more memory consumption, and depending on the value of `maintenance_work_mem` , could cause performance degradation.
194
194
@@ -203,7 +203,7 @@ However, if we have changed table level `autovacuum_vacuum_cost_delay` or
203
203
When a database runs into transaction ID wraparound protection, an error message like the following can be observed:
204
204
205
205
```
206
-
Database is not accepting commands to avoid wraparound data loss in database ‘xx’
206
+
Database isn't accepting commands to avoid wraparound data loss in database ‘xx’
207
207
Stop the postmaster and vacuum that database in single-user mode.
208
208
```
209
209
@@ -215,7 +215,7 @@ The wraparound problem occurs when the database is either not vacuumed or there
215
215
216
216
#### Heavy workload
217
217
218
-
The workload could cause too many dead tuples in a brief period that makes it difficult for autovacuum to catch up. The dead tuples in the system add up over a period leading to degradation of query performance and leading to wraparound situation. One reason for this situation to arise might be because autovacuum parameters aren't adequately set and it is not keeping up with a busy server.
218
+
The workload could cause too many dead tuples in a brief period that makes it difficult for autovacuum to catch up. The dead tuples in the system add up over a period leading to degradation of query performance and leading to wraparound situation. One reason for this situation to arise might be because autovacuum parameters aren't adequately set and it isn't keeping up with a busy server.
219
219
220
220
221
221
#### Long-running transactions
@@ -266,7 +266,7 @@ When the database runs into transaction ID wraparound protection, check for any
266
266
267
267
### Table-specific requirements
268
268
269
-
Autovacuum parameters may be set for individual tables. It is especially important for small and big tables. For example, for a small table that contains only 100 rows, autovacuum triggers VACUUM operation when 70 rows change (as calculated previously). If this table is frequently updated, you might see hundreds of autovacuum operations a day. This will prevent autovacuum from maintaining other tables on which the percentage of changes aren't as big. Alternatively, a table containing a billion rows needs to change 200 million rows to trigger autovacuum operations. Setting autovacuum parameters appropriately prevents such scenarios.
269
+
Autovacuum parameters may be set for individual tables. It's especially important for small and big tables. For example, for a small table that contains only 100 rows, autovacuum triggers VACUUM operation when 70 rows change (as calculated previously). If this table is frequently updated, you might see hundreds of autovacuum operations a day. This will prevent autovacuum from maintaining other tables on which the percentage of changes aren't as big. Alternatively, a table containing a billion rows needs to change 200 million rows to trigger autovacuum operations. Setting autovacuum parameters appropriately prevents such scenarios.
270
270
271
271
To set autovacuum setting per table, change the server parameters as the following examples:
272
272
@@ -283,7 +283,7 @@ To set autovacuum setting per table, change the server parameters as the follo
283
283
284
284
In versions of PostgreSQL prior to 13, autovacuum will not run on tables with an insert-only workload, because if there are no updates or deletes, there are no dead tuples and no free space that needs to be reclaimed. However, autoanalyze will run for insert-only workloads since there is new data. The disadvantages of this are:
285
285
286
-
- The visibility map of the tables is not updated, and thus query performance, especially where there are Index Only Scans, starts to suffer over time.
286
+
- The visibility map of the tables isn't updated, and thus query performance, especially where there are Index Only Scans, starts to suffer over time.
287
287
- The database can run into transaction ID wraparound protection.
288
288
- Hint bits will not be set.
289
289
@@ -304,4 +304,4 @@ Autovacuum will run on tables with an insert-only workload. Two new server p
304
304
305
305
- Troubleshoot high CPU utilization [High CPU Utilization](./how-to-high-cpu-utilization.md).
306
306
- Troubleshoot high memory utilization [High Memory Utilization](./how-to-high-memory-utilization.md).
307
-
- Configure server parameters [Server Parameters](./howto-configure-server-parameters-using-portal.md).
307
+
- Configure server parameters [Server Parameters](./howto-configure-server-parameters-using-portal.md).
0 commit comments