Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

2 votes
2 answers
464 views
PostgreSQL: Long running auto vacuum and high wal rate
Recently a `vacuum` process triggered by `auto vacuum daemon`(PostgreSQL13) on one of our table took long 1.5hr to complete. During this period there was high `WAL` rate up to 7MB/sec and high Disk I/O. This table size around 75GB(200M rows) , and the auto vacuum count from stats table is just 2 onl...
Recently a vacuum process triggered by auto vacuum daemon(PostgreSQL13) on one of our table took long 1.5hr to complete. During this period there was high WAL rate up to 7MB/sec and high Disk I/O. This table size around 75GB(200M rows) , and the auto vacuum count from stats table is just 2 only for last 2 year. What are some auto-vacuum tuning possibilities for huge tables? My considerations are, - Should I disable auto vacuum for huge table and perform manually? - Can decreasing threshold and hence more frequent vacuum solve long running vacuum? Any other solutions?
goodfella (595 rep)
Jun 28, 2024, 01:43 AM • Last activity: Jul 30, 2025, 03:00 AM
3 votes
1 answers
474 views
On PostgreSQL 9.5, does partitioning a table prevent autovacuum from automatically running ANALYZE?
I'm trying to grasp the following sentence from https://www.postgresql.org/docs/9.5/static/sql-analyze.html > The autovacuum daemon, however, will only consider inserts or updates on the parent table itself when deciding whether to trigger an automatic analyze for that table. If that table is rarely...
I'm trying to grasp the following sentence from https://www.postgresql.org/docs/9.5/static/sql-analyze.html > The autovacuum daemon, however, will only consider inserts or updates on the parent table itself when deciding whether to trigger an automatic analyze for that table. If that table is rarely inserted into or updated, the inheritance statistics will not be up to date unless you run ANALYZE manually. Since partitioning is usually implemented through inheritance, initially, I thought this sentence implies that, being the master table empty in a partitioned table, autovacuum would never trigger an automatic ANALYZE on the whole partitioned table (including all children) leaving the planner with no statistics at all for the partitions. On the other hand, "that table" seems to refer only to the parent table (master). If this second reading is correct, autovacuum does trigger ANALYZE automatically on the children tables and, obviously, ignores the parent, empty table. There would be no need to run ANALYZE manually in this case. Which of the two interpretations is the right one?
ARX (1509 rep)
Aug 24, 2016, 10:55 PM • Last activity: Jul 26, 2025, 06:03 PM
4 votes
1 answers
200 views
Postgresql XID wrap around prevention overloading autovacuum
We have a pretty big postgres 14 database with timescaledb installed. Recently we had some issues with MXID and XID wraparound so we started to monitor these as well as autovacuum. What we noticed is that with our 1000/s transaction rate we have to vacuum the whole database every 2 days to prevent X...
We have a pretty big postgres 14 database with timescaledb installed. Recently we had some issues with MXID and XID wraparound so we started to monitor these as well as autovacuum. What we noticed is that with our 1000/s transaction rate we have to vacuum the whole database every 2 days to prevent XID wraparound. However, what is not clear is why do we have to vacuum old partitions (chunks in timescale) which are not touched sometimes for years. I see similar patterns for many of these tables, basically all but one pages are frozen. Could this one page contain some metadata about the table that cannot be cleaned up?
automatic aggressive vacuum to prevent wraparound of table "chdb._timescaledb_internal._hyper_161_172231_chunk": index scans: 0
        pages: 0 removed, 8052 remain, 0 skipped due to pins, 8051 skipped frozen
        tuples: 0 removed, 302204 remain, 0 are dead but not yet removable, oldest xmin: 987543035
        index scan not needed: 0 pages from table (0.00% of total) had 0 dead item identifiers removed
However, when i manually vacuum this partition i always see a few nonremovable rows which i guess is responsible for that page being unfrozen. Is there a way to inspect these rows? Or actually postgres has to vacuum each table every 2 billion transactions?
chdb=# VACUUM (INDEX_CLEANUP FALSE, FREEZE, VERBOSE) _timescaledb_internal._hyper_161_172231_chunk;
INFO:  aggressively vacuuming "_timescaledb_internal._hyper_161_172231_chunk"
INFO:  table "_hyper_161_172231_chunk": found 0 removable, 4 nonremovable row versions in 1 out of 8052 pages
DETAIL:  0 dead row versions cannot be removed yet, oldest xmin: 990878593
Skipped 0 pages due to buffer pins, 8051 frozen pages.
CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s.
INFO:  aggressively vacuuming "pg_toast.pg_toast_1865219981"
INFO:  table "pg_toast_1865219981": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages
DETAIL:  0 dead row versions cannot be removed yet, oldest xmin: 990878593
Skipped 0 pages due to buffer pins, 0 frozen pages.
CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s.
**Edit** I also just found out that some tables that are truncated (we cannot drop them) are still being autovacuumed although it has 0 rows. Autovacuum happened after the table was already truncated and nothing inserted to it since. The XID age (age(c.relfrozenxid)) is still growing after manually doing vacuum freeze on the table.
zerz (41 rep)
Jul 9, 2025, 01:24 PM • Last activity: Jul 9, 2025, 05:35 PM
0 votes
1 answers
1655 views
Blocking automatic vaccum
I have a table `message`. I saw that queries for this table where long running and caused a memory leak (scheduled job in java app). In pg_stat_activity I saw: ```none wait_event_type wait_event state IO DataFileRead active ``` So I increased available disk space, but it didn't solve this problem. I...
I have a table message. I saw that queries for this table where long running and caused a memory leak (scheduled job in java app). In pg_stat_activity I saw:
wait_event_type	wait_event	     state
IO	            DataFileRead	active
So I increased available disk space, but it didn't solve this problem. I saw that there was long running autovaccum worker for this table. I checked table size and it was about 90% of available RAM. I renamed this table and created new one with same schema. So now I have a new table with few records, but the long running autovaccum worker for this table still occurs. Do you have any ideas what to check, how to tune this table?
tomas930 (1 rep)
Sep 4, 2020, 06:18 AM • Last activity: Jun 27, 2025, 02:01 AM
-1 votes
2 answers
36 views
Auto vacuum for table ASAP
In my app for Postgresql I have a table and my app inserts rows to that table. It could be 2-3 rows, also it could be 100-200k rows. How to do that auto vacuum runs for that table as soon as possible? I played with **autovacuum_analyze_scale_factor**, **autovacuum_analyze_threshold** and other param...
In my app for Postgresql I have a table and my app inserts rows to that table. It could be 2-3 rows, also it could be 100-200k rows. How to do that auto vacuum runs for that table as soon as possible? I played with **autovacuum_analyze_scale_factor**, **autovacuum_analyze_threshold** and other parameters for this table but didn't get good results. Does anybody know how to do that?
sluge (101 rep)
Jan 30, 2024, 07:18 AM • Last activity: May 6, 2025, 05:31 PM
1 votes
1 answers
102 views
How to know, when it is time to vacuum an sqlite database file?
Sqlite, contrary most SQL-compatible DB engine, is working directly on files instead over network sockets. It is also not very good in concurrency, beside that deletion operators are mostly advisory (i.e. do not free the places of the deleted entities). That results that an sqlite database needs reg...
Sqlite, contrary most SQL-compatible DB engine, is working directly on files instead over network sockets. It is also not very good in concurrency, beside that deletion operators are mostly advisory (i.e. do not free the places of the deleted entities). That results that an sqlite database needs regularly be VACUUM-ed, at least those with regular modify or delete operations. Vacuum works by rebuilding the database file, without the free spaces in it. Needless to say, it is absolutely non-concurrent with anything, making it to a costly operation - we have downtime for the vacuum. *However, I think there should exist some indicator which compares the size of the database file to the size of the actual data in it.* Using this indicator, it could be said, do we need a vacuum-ing or not. Does it exist?
peterh (2137 rep)
Apr 11, 2025, 10:16 AM • Last activity: Apr 15, 2025, 11:40 AM
7 votes
1 answers
3643 views
Does UPDATE write a new row version for unchanged, TOASTed values?
I am working with a PostgreSQL table with a large TEXT field, which is theoretically updated on a regular basis. I have thought about storing the data directly in the filesystem, but with TOAST, the data is already being stored off-page and compressed in the database so I figured I would keep things...
I am working with a PostgreSQL table with a large TEXT field, which is theoretically updated on a regular basis. I have thought about storing the data directly in the filesystem, but with TOAST, the data is already being stored off-page and compressed in the database so I figured I would keep things simple and just use the database storage. To give some context, I am indexing RSS feeds. I will have a script run every 24h that pulls the RSS feeds and potentially updates the table. This can lead to a lot of dead tuples, and thus lots of space being used on disk. Of course, autovacuum will take care of this eventually but it has the potential to be a lot of data (many GB) and I want to make sure I know what will happen when I am doing lots of updates on this very large table. One solution I have is to only update the TEXT field (storing the RSS data) if there are certain substantial changes to the feed, e.g. a new post on the website. This means that I could avoid doing the UPDATE unless I *really* have to. However, I still want to update the table (to keep track of when I most recently did an HTTP request). This will create a dead tuple with the old version of the row's data. What will happen to the TEXT data, if it isn't actually changed? Will the UPDATE also duplicate the TEXT data, when it creates a dead tuple? Or will the TEXT data be left untouched, because it wasn't changed and it is stored off-page?
Jason (193 rep)
Mar 16, 2022, 02:18 AM • Last activity: Apr 10, 2025, 05:22 PM
1 votes
1 answers
787 views
Autovacuum is not running even after configuring it on
I am using aurora-postgresql version 9.6.8. and I have one main instance , one writer and one reader replica. I am looking for below information: **How I can check on a particular instance when autovacuum was executed when I am trying to use "pg_stat_user_tables"?** This show lot of dead tuples. But...
I am using aurora-postgresql version 9.6.8. and I have one main instance , one writer and one reader replica. I am looking for below information: **How I can check on a particular instance when autovacuum was executed when I am trying to use "pg_stat_user_tables"?** This show lot of dead tuples. But when we see max last autovacuum executed date its one month back. Seems like autovacuum not executed from last one month on any of the table. In my environment we have huge insert update and delete every day. Thank you in advance for any suggestion!!! Below is my auto vacuum configuration:
name                            setting
autovacuum_analyze_scale_factor 0.05
autovacuum_analyze_threshold    50
autovacuum_freeze_max_age       200000000
autovacuum_max_workers          4
autovacuum_naptime              5
autovacuum_vacuum_cost_delay    5
autovacuum_vacuum_cost_limit    -1
autovacuum_vacuum_scale_factor  0.1
autovacuum_vacuum_threshold     50
maintenance_work_mem            4122624
vacuum_cost_limit               200
vacuum_freeze_min_age           50000000
Vikas P (11 rep)
Jun 20, 2019, 03:21 AM • Last activity: Mar 30, 2025, 09:04 PM
0 votes
0 answers
16 views
Auto-vacuum shows different behaviour in two similar situations. I am unable to understand why?
I have a insert-only table `event` on PostgreSQL-12 where I am having a high volume of inserts per sec (~2000 per sec). I regularly faced an issue when anti-wraparound auto-vacuum was running on this table and ALTER query was getting blocked. I am surprised to see that once I saw that auto-vacuum jo...
I have a insert-only table event on PostgreSQL-12 where I am having a high volume of inserts per sec (~2000 per sec). I regularly faced an issue when anti-wraparound auto-vacuum was running on this table and ALTER query was getting blocked. I am surprised to see that once I saw that auto-vacuum job got cancelled after deadlock timeout even though it was anti-wraparound. **Logs when autovacuum did not get cancelled**
autovacuum not cancelled

sqlstate=00000 application_name=,user=,db=,client= LOG:  automatic vacuum to prevent wraparound of table "my_db.public.event_spl_1740300900": index scans: 0
#011pages: 0 removed, 16591962 remain, 0 skipped due to pins, 16300723 skipped frozen
#011tuples: 0 removed, 1244397113 remain, 0 are dead but not yet removable, oldest xmin: 1410720248
#011buffer usage: 2361602 hits, 6947399 misses, 291262 dirtied
#011avg read rate: 3.879 MB/s, avg write rate: 0.163 MB/s
#011system usage: CPU: user: 83.69 s, system: 135.74 s, elapsed: 13990.91 s
sqlstate=00000 application_name=[unknown],user=bpuser,db=my_db,client=172.16.6.1 LOG:  process 113323 acquired AccessExclusiveLock on relation 181282787 of database 180669275 after 5823314.224 ms
**Logs when autovacuum got cancelled**
autovacuum cancelled (happened later in time)

sqlstate=00000 application_name=,user=,db=,client= LOG:  automatic vacuum to prevent wraparound of table "my_db.public.event_spl_1740300900": index scans: 0
#011pages: 0 removed, 74793286 remain, 0 skipped due to pins, 74587702 skipped frozen
#011tuples: 0 removed, 5609496590 remain, 0 are dead but not yet removable, oldest xmin: 1616127756
#011buffer usage: 436546 hits, 7 misses, 205186 dirtied
#011avg read rate: 0.000 MB/s, avg write rate: 1.179 MB/s
#011system usage: CPU: user: 9.24 s, system: 3.22 s, elapsed: 1359.75 s
sqlstate=57014 application_name=,user=,db=,client= ERROR:  canceling autovacuum task
sqlstate=00000 application_name=[unknown],user=bpuser,db=my_db,client=172.16.6.1 LOG:  process 100214 acquired AccessExclusiveLock on relation 181282787 of database 180669275 after 1000.650 ms
sqlstate=00000 application_name=[unknown],user=bpuser,db=my_db,client=172.16.6.1 STATEMENT:  ALTER TABLE event ALTER pkey SET DEFAULT (1742745300)
sqlstate=00000 application_name=[unknown],user=bpuser,db=my_db,client=172.16.6.1 LOG:  duration: 1126.377 ms  execute : ALTER TABLE event ALTER pkey SET DEFAULT (1742745300)
What could be the difference between these two scenarios?
Yashodhan Agnihotri (11 rep)
Mar 26, 2025, 07:20 AM • Last activity: Mar 26, 2025, 10:20 PM
1 votes
1 answers
80 views
Postgresql last_autovacuum and last_autoanalyze
I have a few tables that ere 1 TB+. The columns last_autovacuum and last_autoanalyze in pg_stat_user_tables have NULLs for these tables. The n_dead_tup to n_live_tup ratio is 0.0001. A few questions, can I rely on the n_dead_tup and n_live_tup numbers? The tables have a large number of inserts and a...
I have a few tables that ere 1 TB+. The columns last_autovacuum and last_autoanalyze in pg_stat_user_tables have NULLs for these tables. The n_dead_tup to n_live_tup ratio is 0.0001. A few questions, can I rely on the n_dead_tup and n_live_tup numbers? The tables have a large number of inserts and a few updates, no deletes. If I manually vacuum and analyze these tables, will the columns get updated? PostgreSQL version is 13.5
Jayadevan (1051 rep)
Dec 6, 2024, 05:32 AM • Last activity: Dec 6, 2024, 07:30 AM
2 votes
2 answers
144 views
Does regular truncate & insert hurt performance?
We have a large (5 TB) PostgreSQL 15 RDS that acts as a data warehouse, data comes in through regular pipelines and then ~20 users run analytic queries on it. Our infrastructure people have access to the Amazon console, so there are configurations & logs that we don't have access to, if relevant. We...
We have a large (5 TB) PostgreSQL 15 RDS that acts as a data warehouse, data comes in through regular pipelines and then ~20 users run analytic queries on it. Our infrastructure people have access to the Amazon console, so there are configurations & logs that we don't have access to, if relevant. We do have an account that has access to the rds_superuser group, so can change ownership of objects, see all queries, ... One of our medium sized datasets (10GB) for reasons gets inserted by the table being truncated and inserted into daily. The auto-vacuum seems to be running regularly on this but I do wonder if: 1. Is this paradigm affecting performance for querying on this table itself? (are the indexes also being regularly updated?) and, 2. if truncate & insert were it to be applied more broadly, would the database as a whole degrade? (autovacuum/autoanalyze would be unable to keep up?) If your answers and comments could point to tests we could be performing now with the access we have, that would be great.
raphael (599 rep)
Aug 28, 2024, 09:44 PM • Last activity: Sep 4, 2024, 12:27 PM
2 votes
3 answers
7395 views
How do I grant PostgreSQL superuser access to vacuum tables?
My logs are constantly filling up with these messages for hundreds of tables: WARNING: skipping "some_table_name" --- only table or database owner can analyze it How do I perform any the following and/or resolve this? 1. Determine in which database(s) these tables reside? Would be nice if the warnin...
My logs are constantly filling up with these messages for hundreds of tables: WARNING: skipping "some_table_name" --- only table or database owner can analyze it How do I perform any the following and/or resolve this? 1. Determine in which database(s) these tables reside? Would be nice if the warning included that information. 2. Grant the PostgreSQL superuser access to vacuum these tables 3. Disable these warnings in the log file Side note: none of the log file rotation, truncation, size/date limits settings are working either but I'll save that for a separate post.
Teflon Ted (123 rep)
Feb 13, 2017, 08:56 PM • Last activity: Jun 5, 2024, 09:19 AM
0 votes
1 answers
443 views
Optimizing XID management in PostgreSQL: How to avoid INSERT locks in tables?
I would like to raise a question regarding the optimal practices for managing transaction age (XID) in a PostgreSQL database. I am currently using the method of performing `VACUUM FULL` operations on the oldest tables on a cyclic basis during periods of reduced activity, i.e. from 5:00 p.m. to 7:00...
I would like to raise a question regarding the optimal practices for managing transaction age (XID) in a PostgreSQL database. I am currently using the method of performing VACUUM FULL operations on the oldest tables on a cyclic basis during periods of reduced activity, i.e. from 5:00 p.m. to 7:00 a.m. The goal is to keep the age of transactions below the value specified by the autovacuum_freeze_max_age parameter (200_000_000) outside of these hours, in order to prevent INSERT operations on tables that are subject to the AUTOVACUUM TO PREVENT WRAPAROUND process from being blocked. Below I show a graph of the change in transaction age over the past 30 days. As you can see, the threshold value of 200_000_000 is practically constantly exceeded. Can considering increasing the value of this parameter (e.g. to 400_000_000) be beneficial, or is this only a short-term solution? I have concerns that increasing the value of this parameter may only help until the age of transactions approaches the new threshold value, provided that the tool is unable to keep up with vacuuming operations during the periods from 5pm to 7am. Please feel free to suggest any additional measures that could help optimize this process. XID_over_30_days enter image description here
Patryk (1 rep)
Apr 24, 2024, 12:01 PM • Last activity: May 6, 2024, 10:03 AM
0 votes
1 answers
46 views
How to Retrieve and Compare All Settings and Overrides for a Specific Table in PostgreSQL (version 12)?
I am working with a PostgreSQL 12 database and currently investigating a table (table_name in schema schema_name) that has accumulated a significant number of dead tuples. To address this, I am examining both the PostgreSQL system-wide settings and any overrides that might be applied specifically to...
I am working with a PostgreSQL 12 database and currently investigating a table (table_name in schema schema_name) that has accumulated a significant number of dead tuples. To address this, I am examining both the PostgreSQL system-wide settings and any overrides that might be applied specifically to this table, with a particular focus on autovacuum settings. What are the queries I can use to find out all the settings that applies to the table, including any overrides, in a glance?
Boon (136 rep)
Apr 30, 2024, 02:50 AM
0 votes
1 answers
78 views
Postgres: how to insert and delete many records and to not run out of space
I have a PostgreSQL installation deployed in Kubernetes (with the CloudNative operator) and allocated a 25GB volume for it. My architecture involves several microservices interacting with various databases. Here's the setup: 1. A custom-made load testing tool, which sends 100-1000 requests per secon...
I have a PostgreSQL installation deployed in Kubernetes (with the CloudNative operator) and allocated a 25GB volume for it. My architecture involves several microservices interacting with various databases. Here's the setup: 1. A custom-made load testing tool, which sends 100-1000 requests per second via REST. 2. Service A, which is database-less, receives requests through REST and forwards them to Service B via AMQP. 3. Service B, which receives data from Service A via AMQP and stores it in the database. 4. A background thread pool in Service B retrieves data portions from the database, processes them, and then sends them to Services C and D via AMQP. 5. Services C and D, which receive data from Service B via AMQP and store it in their respective databases. 6. A custom database cleaning tool, which, once a minute, deletes the oldest records from all databases so that each table has no more than N records (where N ranges from 100k to 1M). Additionally, it performs a vacuum (but not a full vacuum) once every 10 minutes. With this configuration, I encounter a problem in less than an hour - the database size nearly reaches 25GB, and everything comes to a halt. I had assumed that running vacuum would mark the deleted records for reuse, but it appears that only a VACUUM FULL effectively frees up space. Naturally, I would prefer to use VACUUM FULL sparingly because it locks the databases. However, I am already performing a simple VACUUM – why isn't that sufficient? Auto-vacuum is also enabled with default settings. The code in all applications works correctly; there are no forgotten connections or similar issues. With VACUUM FULL, the system operates for hours under a ~500rps load and remains relatively stable. "Relatively" because VACUUM FULL causes significant disruptions, of course. But thanks to AMQP, no data is lost. There are no foreign keys and no complex queries in my system, which is designed for high loads, so I aim to keep it as simple as possible. The role of Service B is merely to perform basic data processing (JSON transformation) and insert or update a record in the "datagrams" table, then insert a record in the "journal" table within the same transaction at the ReadCommitted isolation level. What's wrong with the "simple vacuum" (that takes tens of seconds sometimes as well but at least does not block everything)? In fact with my cleaning utility working each db must be no more 1-2Gb, so if vacuum mark records for reuse, databases should not grow after 2-3Gb (taking into account that indexes are not processed by simple vacuum). But they do grow. Here is the schema of database for service B as an example (D and C have similar, even simpler): CREATE TABLE public.datagrams ( id serial4 NOT NULL, incoming_id text NOT NULL, sender text NOT NULL, body text NOT NULL, errors text NULL, status public.datagram_status NOT NULL, document_type text DEFAULT ''::text NOT NULL, target_document_type text DEFAULT ''::text NOT NULL, created timestamptz NOT NULL, modified timestamptz NULL, processing_instance text NULL, processing_started_at timestamptz NULL, retries int4 DEFAULT 0 NOT NULL, CONSTRAINT datagrams_incoming_id_key UNIQUE (incoming_id), CONSTRAINT datagrams_pk PRIMARY KEY (id) ); CREATE INDEX datagrams_created_idx ON public.datagrams USING btree (created); CREATE INDEX datagrams_modified_idx ON public.datagrams USING btree (modified); CREATE INDEX datagrams_processing_instance_idx ON public.datagrams USING btree (processing_instance); CREATE INDEX datagrams_processing_started_at_idx ON public.datagrams USING btree (processing_started_at); CREATE INDEX datagrams_status_ind ON public.datagrams USING btree (status); CREATE TABLE public.journal ( id serial4 NOT NULL, incoming_id text NOT NULL, status public.datagram_status NOT NULL, errors text NULL, auditor text NULL, stamp timestamptz NOT NULL, CONSTRAINT datagram_errors_pk PRIMARY KEY (id) ); CREATE INDEX journal_stamp_idx ON public.journal USING btree (stamp); CREATE INDEX journal_status_ind ON public.journal USING btree (status);
Tertium (141 rep)
Feb 23, 2024, 07:58 AM • Last activity: Feb 23, 2024, 03:33 PM
0 votes
2 answers
392 views
Sensible value for autovacuum_cost_delay
I'm running a data warehouse on an AWS RDS PostgreSQL instance. Most of the heavy lifting is done during the night-batch, and very often we use a TRUNCATE-rebuild strategy, also for large tables (100M rows). This seems to cause issues with autovacuum, between 2 and 4 the night batch 7 out of 10 of t...
I'm running a data warehouse on an AWS RDS PostgreSQL instance. Most of the heavy lifting is done during the night-batch, and very often we use a TRUNCATE-rebuild strategy, also for large tables (100M rows). This seems to cause issues with autovacuum, between 2 and 4 the night batch 7 out of 10 of the TOP SQL statements are VACUUM ANALYZE statements for the large tables: enter image description here and they are hugging my RDS system enter image description here and dropping the Byte Balance to 0, after which the machine slows down enormously : enter image description here Obviously it would be wiser to postpone the VACUUM ANALYZE to a later timeframe, when the machine is almost idle. After reading some documentation I can think of two strategies to get this done: 1) turn off Autovacuum for these large tables, and schedule a process that runs Vacuum later 2) set the autovacuum_cost_delay to a sensible value. since that would postpone the Vacuum processing in general (or maybe set it to a sensible value for just these tables). However, what is a sensible value in this case? I read that the default is 2 milliseconds. How much larger is sensible 200ms? 10 seconds? 1 minute? 60 minutes? I'm looking for a sensible value to start testing with or other advice that can help me. NB. the machine is 2cpu, 16GB m6g.large and these are the current settings for the autovauccum related parameters: enter image description here **Extra info** @jjanes yes, it barely touches a byte balance of 0, however, This is a careful balance I actually managed to achieve. I regularly encountered the situation that it took very long to recover from a situation that it dropped to 0 actually. Example enter image description here My machine then starts to build up read/write latency and DiskQueueDepth as well Bulk loading at night is concerning many tables (currently ~900), which are all loaded/transformed through jobs between 23h and 6:30h, with the most busy time between 2h and 4h. Many tables are small, only a few are quite large. enter image description here @jjanes & @frank-heikens, which later version does make a difference? here's two screenshots from the situation after before & after migration from 14 to 15: Before: enter image description here After: enter image description here **Update** Implemented the suggestion of @Laurence Albe. Observations: Byte Balance much better: enter image description here Database load much more even: enter image description here
Bart Jonk (357 rep)
Jan 5, 2024, 02:11 PM • Last activity: Jan 19, 2024, 04:10 PM
2 votes
1 answers
3345 views
Disable autovacuum for one (pretty much read-only) database in a cluster
I’ve got a PostgreSQL cluster on my development system in which I’ve created several databases. I also have a dump of the last state of the DB of an old system imported in which I (very) occasionally need to look something up, so this database is pretty much read-only, while the others are live (if...
I’ve got a PostgreSQL cluster on my development system in which I’ve created several databases. I also have a dump of the last state of the DB of an old system imported in which I (very) occasionally need to look something up, so this database is pretty much read-only, while the others are live (if low traffic except for the Akonadi one). I am finding lots of instructions for disabling autovacuum either globally (i.e. for the entire DB cluster) or for individual tables, but how can I permanently disable it for just one database in the cluster?
mirabilos (170 rep)
Jul 29, 2021, 09:57 PM • Last activity: Dec 19, 2023, 08:01 AM
0 votes
1 answers
206 views
What's the difference between autovacuum general setting and autovacuum_enabled table setting in PostgreSQL?
We have a database that is now on v15 PostgreSQL, but was recently migrated from v11, and before that v9. I believe that many of the settings for our database were preserved from prior versions and may not be optimal/default for v15. Specifically, I'm trying to better understand the expected autovac...
We have a database that is now on v15 PostgreSQL, but was recently migrated from v11, and before that v9. I believe that many of the settings for our database were preserved from prior versions and may not be optimal/default for v15. Specifically, I'm trying to better understand the expected autovacuum behavior. Based on other questions, I checked show autovacuum which returns on. This tells me that the database-wide autovacuum daemon is running. And this query tells me the default autovacuum settings:
select *
from pg_settings 
where name like '%autovacuum%';
However, there are several tables where autovacuum does not seem to be running or never has been run. I suspect this is because autovacuum was never specifically enabled for these tables in the prior versions of PostgreSQL that they were created in and transferred from. i.e., the reloptions column returned from the following query is NULL for tables where autovacuum doesn't run and is set to {autovacuum_enabled=true} for tables where autovacuum does run:
select pg_namespace.nspname, relname, reloptions
from pg_class
join pg_namespace on pg_namespace.oid = pg_class.relnamespace
where relname like 'sometablename%' and pg_namespace.nspname = 'someschemaname';
Is this an accurate understanding of the reloptions/autovacuum_enabled behavior? I understand that I can run the following query to enable autovacuum on a specific table: ALTER TABLE schemaname.tablename SET (autovacuum_enabled = true); However, what do I need to consider before enabling autovaccuum on a table? - Are any tables 'too small' (i.e., why bother?) - Can tables be 'too big' (i.e., if autovacuum runs on a very large table can the server run out of space, and/or will DB performance suffer?) - If a table is created and written to but then never updated, does enabling autovacuum on this table benefit me at all? - If a table is written to regularly during the day but idle at night, can I schedule autovacuum to run on this table during specific times of day or days of week? How?
Brian D (111 rep)
Nov 21, 2023, 05:29 PM • Last activity: Nov 22, 2023, 07:30 AM
0 votes
2 answers
428 views
PostgreSQL 12 streaming replication standbys timing out due to autovacuum tasks
We have PostgreSQL 12.9 running on Ubuntu 20.04.3 LTS in a streaming replication setup with 1 primary and 3 standbys where the following options have been configured on all servers: - hot_standby=on - hot_standby_feedback=on - max_standby_archive_delay=30s - max_standby_streaming_delay=30s - wal_rec...
We have PostgreSQL 12.9 running on Ubuntu 20.04.3 LTS in a streaming replication setup with 1 primary and 3 standbys where the following options have been configured on all servers: - hot_standby=on - hot_standby_feedback=on - max_standby_archive_delay=30s - max_standby_streaming_delay=30s - wal_receiver_status_interval=10s And on the primary only, we have configured: - vacuum_defer_cleanup_age=1000 Our largest table is about 1TB in size (half for heap, half for index) with 6.5B rows, and is also the most active one with INSERTS/DELETES occurring frequently, so for that table, we have specified **autovacuum_vacuum_scale_factor=0.001**. Other server-level settings for autovacuum are: - autovacuum_analyze_scale_factor=0.01 - autovacuum_analyze_threshold=40 - autovacuum_freeze_max_age=500000000 - autovacuum_max_workers=20 - autovacuum_multixact_freeze_max_age=400000000 - autovacuum_naptime=1s - autovacuum_vacuum_cost_delay=10ms - utovacuum_vacuum_cost_limit=10000 - autovacuum_vacuum_scale_factor=0.005 - autovacuum_vacuum_threshold=50 - autovacuum_work_mem=-1 - log_autovacuum_min_duration=100ms Normally this works well and autovacuum kicks in without issue. However, now that we've seen an increase in TPS on our standby traffic, we are getting many 57014 errors on them "**canceling statement due to user request**" after about half hour, which is normally how long it takes when actual tuples are removed. This causes spikes in user connections making the clients unstable. Also we see many of the SELECTs are being blocked, **waiting for AccessShareLock** from the autovacuum process. We have traced each of these spikes to the primary which also has an associated 57014 error "**canceling autovacuum task**". When this occurs we can see no autovacuum is being done for quite some time (several hours). Things we've tried: - Rebuilding indexes to remove bloat. (There is no table bloat, only index bloat). - Increasing vacuum_defer_cleanup_age. (Originally the value was 0, and we tried increasing it from 200->400->1000 with no noticeable impact). In the end, we've had to suspend autovacuum on the table in order to stabilize the system. We still have a nightly job that kicks in to manually run VACUUM (ANALYZE) on the database, but we are hoping there's a better solution.
Diane (151 rep)
Feb 17, 2023, 07:48 PM • Last activity: Sep 22, 2023, 07:20 PM
4 votes
1 answers
2424 views
High CPU load after massive delete on PostgreSQL server
I've deleted ~65 million rows from a PostgreSQL table with ~75 million rows. As soon as the deletion query completed, the CPU plummeted to 100% for about five minutes. The table from which rows were deleted has multiple indexes and was in heavy use during the deletion and after it. Unfortunately I d...
I've deleted ~65 million rows from a PostgreSQL table with ~75 million rows. As soon as the deletion query completed, the CPU plummeted to 100% for about five minutes. The table from which rows were deleted has multiple indexes and was in heavy use during the deletion and after it. Unfortunately I don't have a way to reproduce this, since it happened on production environment. Is it likely that the autovacuum kicked in and if so, could it drive a database with 32 CPU cores to 100% CPU usage? If so, is there a way to limit the intake of autovacuum so it doesn't degrade the database performance after massive delete queries? I'm using PostgreSQL version 14.8.
Alechko (229 rep)
Aug 10, 2023, 12:09 PM • Last activity: Aug 10, 2023, 04:39 PM
Showing page 1 of 20 total questions