|
| 1 | +-- Just the basic VACUUM operation |
| 2 | +VACUUM; |
| 3 | + |
| 4 | + |
| 5 | +-- Equivalent to SHRINK |
| 6 | +VACUUM (FULL); |
| 7 | + |
| 8 | + |
| 9 | +-- Targeting a table |
| 10 | +VACUUM radio.antenna; |
| 11 | + |
| 12 | +-- Targeting more than one table |
| 13 | +VACUUM radio.antenna, radio.bands, radio.digitalmodes |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +-- Adding, then removing, dummy data to see this in action |
| 18 | +INSERT INTO radio.countries |
| 19 | +(country_name) |
| 20 | +SELECT generate_series(1,15000,1); |
| 21 | + |
| 22 | +DELETE FROM radio.countries |
| 23 | +WHERE country_id BETWEEN 3 AND 12000; |
| 24 | + |
| 25 | +VACUUM (VERBOSE) radio.countries; |
| 26 | + |
| 27 | +--cleanup and reset from above |
| 28 | +DELETE FROM radio.countries |
| 29 | +WHERE country_id > 2; |
| 30 | + |
| 31 | +ALTER TABLE radio.countries ALTER COLUMN country_id RESTART WITH 3; |
| 32 | + |
| 33 | + |
| 34 | +SELECT * FROM radio.countries c; |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +--ANALYZE |
| 39 | +VACUUM (ANALYZE); |
| 40 | + |
| 41 | + |
| 42 | +--Just ANALYZE |
| 43 | +ANALYZE; |
| 44 | + |
| 45 | +--ANALYZE and then look at STATISTICS |
| 46 | +VACUUM (ANALYZE) radio.countries; |
| 47 | + |
| 48 | +--ensure we have a clean set of statistics, then review them |
| 49 | +VACUUM (ANALYZE) radio.countries; |
| 50 | + |
| 51 | +SELECT |
| 52 | + ps.histogram_bounds |
| 53 | +FROM |
| 54 | + pg_stats AS ps |
| 55 | +WHERE |
| 56 | + ps.tablename = 'countries'; |
| 57 | + |
| 58 | + |
| 59 | +--modify the data and then look at STATISTICS |
| 60 | +INSERT INTO radio.countries |
| 61 | +(country_name) |
| 62 | +SELECT generate_series(1,15000,1); |
| 63 | + |
| 64 | +SELECT |
| 65 | + ps.histogram_bounds |
| 66 | +FROM |
| 67 | + pg_stats AS ps |
| 68 | +WHERE |
| 69 | + ps.tablename = 'countries'; |
| 70 | + |
| 71 | +VACUUM (ANALYZE) radio.countries; |
| 72 | + |
| 73 | +SELECT |
| 74 | + ps.histogram_bounds |
| 75 | +FROM |
| 76 | + pg_stats AS ps |
| 77 | +WHERE |
| 78 | + ps.tablename = 'countries'; |
| 79 | + |
| 80 | +--VERBOSE and ANALYZE |
| 81 | + |
0 commit comments