patternsqlModerate
TOAST Table Growth Out of Control - FULLVAC Does Nothing
Viewed 0 times
fullvaccontrolnothinggrowthdoestoastouttable
Problem
Recently, I've had a PostgreSQL 8.2.11 server upgraded to 8.4 in order to take advantage of autovacuum features and be in line with 30ish other PGSQL servers. This was done by a separate IT group who administrates the hardware, so we don't have much choice on any other upgrades (won't see 9+ for a while). The server exists in a very closed environment (isolated network, limited root privileges) and runs on RHEL5.5 (i686). After the upgrade, the database has constantly been growing to the tune of 5-6 GB a day. Normally, the database, as a whole, is ~20GB; currently, it is ~89GB. We have a couple other servers which run equivalent databases and actually synchronize the records to each other via a 3rd party application (one I do not have access to the inner workings). The other databases are ~20GB as they should be.
Running the following SQL, it's fairly obvious there's an issue with a particular table, and, more specifically, its TOAST table.
Which produces:
relation | size
------------------------------------+---------
pg_toast.pg_toast_16874 | 89 GB
fews00.warmstates | 1095 MB
...
(20 rows)
This TOAST table is for a table called "timeseries" which saves large records of blobbed data. A
I've performed a
INFO: vacuuming "pg_toast.pg_toast_16874"
INFO: "pg_toast_16874": found 22483 removable, 10475318 nonremovable row versions
Running the following SQL, it's fairly obvious there's an issue with a particular table, and, more specifically, its TOAST table.
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_relation_size(C.oid)) AS "size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_relation_size(C.oid) DESC
LIMIT 20;Which produces:
relation | size
------------------------------------+---------
pg_toast.pg_toast_16874 | 89 GB
fews00.warmstates | 1095 MB
...
(20 rows)
This TOAST table is for a table called "timeseries" which saves large records of blobbed data. A
SUM(LENGTH(blob)/1024./1024.) of all the records in timeseries yields ~16GB for that column. There should be no reason this table's TOAST table should be as large as it is.I've performed a
VACUUM FULL VERBOSE ANALYZE timeseries, and the vacuum runs to completion with no errors.INFO: vacuuming "pg_toast.pg_toast_16874"
INFO: "pg_toast_16874": found 22483 removable, 10475318 nonremovable row versions
Solution
This:
suggests that the underlying issue is that something can still "see" those rows so they can't be removed.
The candidates for that are:
-
Lost prepared transactions. Check
-
Long-running sessions with an open, idle transaction. In PostgreSQL 8.4 and above this should only be an issue for
Most likely you have a client that's failing to commit or rollback transactions during long idle periods.
If this doesn't turn out to be it, the next thing I'd check would be to do a sum of the
INFO: "pg_toast_16874": found 22483 removable, 10475318 nonremovable row versions in 10448587 pages 22483 removable, 10475318 nonremovable row versions in 10448587 pagessuggests that the underlying issue is that something can still "see" those rows so they can't be removed.
The candidates for that are:
-
Lost prepared transactions. Check
pg_catalog.pg_prepared_xacts; it should be empty. Also run SHOW max_prepared_transactions; it should report zero.-
Long-running sessions with an open, idle transaction. In PostgreSQL 8.4 and above this should only be an issue for
SERIALIZABLE transactions. Check pg_catalog.pg_stat_activity for in transaction sessions.Most likely you have a client that's failing to commit or rollback transactions during long idle periods.
If this doesn't turn out to be it, the next thing I'd check would be to do a sum of the
octet_size of each column of the table of interest. Compare that to the pg_relation_size of the table and its TOAST side-table. If there's a big difference then the space consumed is likely by no longer visible rows and you probably do have table bloat issues. If they're quite similar, you can start narrowing down where the space use is by summing up the octet sizes per column, getting the top 'n' values, etc.Code Snippets
INFO: "pg_toast_16874": found 22483 removable, 10475318 nonremovable row versions in 10448587 pages 22483 removable, 10475318 nonremovable row versions in 10448587 pagesContext
StackExchange Database Administrators Q#45662, answer score: 12
Revisions (0)
No revisions yet.