How to tell how long autovacuum took to vacuum a postgres table? The system table pg_stat_all_tables records when a table was last vacuumed by the autovacuum daemon.
I've noticed a possible correlation between some performance issues and one of the larger tables in my database being vacuumed. However, since I don't know the duration of the vacuuming process, I can't be 100% sure.
How can find I out how long an autovacuum took on any given table?
Autovacuum durations are reported in the logs when log_autovacuum_min_duration is set to 0 or a duration threshold.
It produces this kind of output:

2021-05-17 03:59:40.530 CEST [25526] LOG:  automatic vacuum of table "db.public.tablename": index scans: 1
    pages: 0 removed, 1001527 remain, 0 skipped due to pins, 0 skipped frozen
    tuples: 1346603 removed, 15288094 remain, 224598 are dead but not yet removable, oldest xmin: 736
    buffer usage: 1104110 hits, 2210831 misses, 1716564 dirtied
    avg read rate: 2.329 MB/s, avg write rate: 1.808 MB/s
    system usage: CPU: user: 46.90 s, system: 60.02 s, elapsed: 7417.28 s

As can be seen in this example, it can be very long on large tables, but it does not consume so much resources due to throttling.
When the operation is still in progress, it can be monitored through
the system views pg_stat_progress_vacuum  and  pg_stat_activity (to be joined with the pid column).