gitlab-exporter 7.1.2 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gitlab_exporter/database/bloat_btree.sql +84 -67
- data/lib/gitlab_exporter/database/bloat_table.sql +13 -12
- data/lib/gitlab_exporter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86ad2e8d49582c70ba5faa5e7a8744a0e812f5682447cc1e1f000e050a3b9451
|
|
4
|
+
data.tar.gz: 2a0f878e42abef28992284e0e372db960831025b7ff3cf71c676369210d05fea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28d6f61e6df16ac17ba9e25ddea5d6a39c65940796898a2a6bad66c352ad47a1341593e3bb8dd7edaefd5281a787612beda9ff6f3f3700c6c458ad345fef055d
|
|
7
|
+
data.tar.gz: f7b2ff3ddd97529571e0517f4b8f9c7d42fe512f5d786a9c60dfae6337cafc56f5ae8eecaf98e3d85d0cb987e66363102bfec40a6ff4411524359cdf888f9d3e
|
data/Gemfile.lock
CHANGED
|
@@ -12,73 +12,90 @@ SELECT current_database(), nspname AS schemaname, tblname, idxname AS object_nam
|
|
|
12
12
|
END AS bloat_size,
|
|
13
13
|
100 * (relpages-est_pages_ff)::float / relpages AS bloat_ratio,
|
|
14
14
|
is_na
|
|
15
|
-
-- , 100-(
|
|
15
|
+
-- , 100-(pst).avg_leaf_density AS pst_avg_bloat, est_pages, index_tuple_hdr_bm, maxalign, pagehdr, nulldatawidth, nulldatahdrwidth, reltuples, relpages -- (DEBUG INFO)
|
|
16
16
|
FROM (
|
|
17
17
|
SELECT coalesce(1 +
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
ceil(reltuples/floor((bs-pageopqdata-pagehdr)/(4+nulldatahdrwidth)::float)), 0 -- ItemIdData size + computed avg size of a tuple (nulldatahdrwidth)
|
|
19
|
+
) AS est_pages,
|
|
20
|
+
coalesce(1 +
|
|
21
|
+
ceil(reltuples/floor((bs-pageopqdata-pagehdr)*fillfactor/(100*(4+nulldatahdrwidth)::float))), 0
|
|
22
|
+
) AS est_pages_ff,
|
|
23
|
+
bs, nspname, tblname, idxname, relpages, fillfactor, is_na
|
|
24
|
+
-- , pgstatindex(idxoid) AS pst, index_tuple_hdr_bm, maxalign, pagehdr, nulldatawidth, nulldatahdrwidth, reltuples -- (DEBUG INFO)
|
|
25
25
|
FROM (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
) AS
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
26
|
+
SELECT maxalign, bs, nspname, tblname, idxname, reltuples, relpages, idxoid, fillfactor,
|
|
27
|
+
( index_tuple_hdr_bm +
|
|
28
|
+
maxalign - CASE -- Add padding to the index tuple header to align on MAXALIGN
|
|
29
|
+
WHEN index_tuple_hdr_bm%maxalign = 0 THEN maxalign
|
|
30
|
+
ELSE index_tuple_hdr_bm%maxalign
|
|
31
|
+
END
|
|
32
|
+
+ nulldatawidth + maxalign - CASE -- Add padding to the data to align on MAXALIGN
|
|
33
|
+
WHEN nulldatawidth = 0 THEN 0
|
|
34
|
+
WHEN nulldatawidth::integer%maxalign = 0 THEN maxalign
|
|
35
|
+
ELSE nulldatawidth::integer%maxalign
|
|
36
|
+
END
|
|
37
|
+
)::numeric AS nulldatahdrwidth, pagehdr, pageopqdata, is_na
|
|
38
|
+
-- , index_tuple_hdr_bm, nulldatawidth -- (DEBUG INFO)
|
|
39
|
+
FROM (
|
|
40
|
+
SELECT n.nspname, i.tblname, i.idxname, i.reltuples, i.relpages,
|
|
41
|
+
i.idxoid, i.fillfactor, current_setting('block_size')::numeric AS bs,
|
|
42
|
+
CASE -- MAXALIGN: 4 on 32bits, 8 on 64bits (and mingw32 ?)
|
|
43
|
+
WHEN version() ~ 'mingw32' OR version() ~ '64-bit|x86_64|ppc64|ia64|amd64' THEN 8
|
|
44
|
+
ELSE 4
|
|
45
|
+
END AS maxalign,
|
|
46
|
+
/* per page header, fixed size: 20 for 7.X, 24 for others */
|
|
47
|
+
24 AS pagehdr,
|
|
48
|
+
/* per page btree opaque data */
|
|
49
|
+
16 AS pageopqdata,
|
|
50
|
+
/* per tuple header: add IndexAttributeBitMapData if some cols are null-able */
|
|
51
|
+
CASE WHEN max(coalesce(s.null_frac,0)) = 0
|
|
52
|
+
THEN 2 -- IndexTupleData size
|
|
53
|
+
ELSE 2 + (( 32 + 8 - 1 ) / 8) -- IndexTupleData size + IndexAttributeBitMapData size ( max num filed per index + 8 - 1 /8)
|
|
54
|
+
END AS index_tuple_hdr_bm,
|
|
55
|
+
/* data len: we remove null values save space using it fractionnal part from stats */
|
|
56
|
+
sum( (1-coalesce(s.null_frac, 0)) * coalesce(s.avg_width, 1024)) AS nulldatawidth,
|
|
57
|
+
max( CASE WHEN i.atttypid = 'pg_catalog.name'::regtype THEN 1 ELSE 0 END ) > 0 AS is_na
|
|
58
|
+
FROM (
|
|
59
|
+
SELECT ct.relname AS tblname, ct.relnamespace, ic.idxname, ic.attpos, ic.indkey, ic.indkey[ic.attpos], ic.reltuples, ic.relpages, ic.tbloid, ic.idxoid, ic.fillfactor,
|
|
60
|
+
coalesce(a1.attnum, a2.attnum) AS attnum, coalesce(a1.attname, a2.attname) AS attname, coalesce(a1.atttypid, a2.atttypid) AS atttypid,
|
|
61
|
+
CASE WHEN a1.attnum IS NULL
|
|
62
|
+
THEN ic.idxname
|
|
63
|
+
ELSE ct.relname
|
|
64
|
+
END AS attrelname
|
|
65
|
+
FROM (
|
|
66
|
+
SELECT idxname, reltuples, relpages, tbloid, idxoid, fillfactor, indkey,
|
|
67
|
+
pg_catalog.generate_series(1,indnatts) AS attpos
|
|
68
|
+
FROM (
|
|
69
|
+
SELECT ci.relname AS idxname, ci.reltuples, ci.relpages, i.indrelid AS tbloid,
|
|
70
|
+
i.indexrelid AS idxoid,
|
|
71
|
+
coalesce(substring(
|
|
72
|
+
array_to_string(ci.reloptions, ' ')
|
|
73
|
+
from 'fillfactor=([0-9]+)')::smallint, 90) AS fillfactor,
|
|
74
|
+
i.indnatts,
|
|
75
|
+
pg_catalog.string_to_array(pg_catalog.textin(
|
|
76
|
+
pg_catalog.int2vectorout(i.indkey)),' ')::int[] AS indkey
|
|
77
|
+
FROM pg_catalog.pg_index i
|
|
78
|
+
JOIN pg_catalog.pg_class ci ON ci.oid = i.indexrelid
|
|
79
|
+
WHERE ci.relam=(SELECT oid FROM pg_am WHERE amname = 'btree')
|
|
80
|
+
AND ci.relpages > 0
|
|
81
|
+
) AS idx_data
|
|
82
|
+
) AS ic
|
|
83
|
+
JOIN pg_catalog.pg_class ct ON ct.oid = ic.tbloid
|
|
84
|
+
LEFT JOIN pg_catalog.pg_attribute a1 ON
|
|
85
|
+
ic.indkey[ic.attpos] <> 0
|
|
86
|
+
AND a1.attrelid = ic.tbloid
|
|
87
|
+
AND a1.attnum = ic.indkey[ic.attpos]
|
|
88
|
+
LEFT JOIN pg_catalog.pg_attribute a2 ON
|
|
89
|
+
ic.indkey[ic.attpos] = 0
|
|
90
|
+
AND a2.attrelid = ic.idxoid
|
|
91
|
+
AND a2.attnum = ic.attpos
|
|
92
|
+
) i
|
|
93
|
+
JOIN pg_catalog.pg_namespace n ON n.oid = i.relnamespace
|
|
94
|
+
JOIN pg_catalog.pg_stats s ON s.schemaname = n.nspname
|
|
95
|
+
AND s.tablename = i.attrelname
|
|
96
|
+
AND s.attname = i.attname
|
|
97
|
+
GROUP BY 1,2,3,4,5,6,7,8,9,10,11
|
|
98
|
+
) AS rows_data_stats
|
|
99
|
+
) AS rows_hdr_pdg_stats
|
|
100
|
+
) AS relation_stats
|
|
101
|
+
ORDER BY nspname, tblname, idxname;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
-- Originally from: https://github.com/ioguix/pgsql-bloat-estimation/blob/master/table/table_bloat.sql
|
|
2
|
-
/* WARNING: executed with a non-superuser role, the query inspect only tables you are granted to read.
|
|
2
|
+
/* WARNING: executed with a non-superuser role, the query inspect only tables and materialized view (9.3+) you are granted to read.
|
|
3
3
|
* This query is compatible with PostgreSQL 9.0 and more
|
|
4
4
|
*/
|
|
5
5
|
SELECT current_database(), schemaname, tblname AS object_name, bs*tblpages AS real_size,
|
|
@@ -16,12 +16,12 @@ SELECT current_database(), schemaname, tblname AS object_name, bs*tblpages AS re
|
|
|
16
16
|
THEN 100 * (tblpages - est_tblpages_ff)/tblpages::float
|
|
17
17
|
ELSE 0
|
|
18
18
|
END AS bloat_ratio, is_na
|
|
19
|
-
-- , (pst).free_percent + (pst).dead_tuple_percent AS real_frag
|
|
19
|
+
-- , tpl_hdr_size, tpl_data_size, (pst).free_percent + (pst).dead_tuple_percent AS real_frag -- (DEBUG INFO)
|
|
20
20
|
FROM (
|
|
21
21
|
SELECT ceil( reltuples / ( (bs-page_hdr)/tpl_size ) ) + ceil( toasttuples / 4 ) AS est_tblpages,
|
|
22
22
|
ceil( reltuples / ( (bs-page_hdr)*fillfactor/(tpl_size*100) ) ) + ceil( toasttuples / 4 ) AS est_tblpages_ff,
|
|
23
23
|
tblpages, fillfactor, bs, tblid, schemaname, tblname, heappages, toastpages, is_na
|
|
24
|
-
-- ,
|
|
24
|
+
-- , tpl_hdr_size, tpl_data_size, pgstattuple(tblid) AS pst -- (DEBUG INFO)
|
|
25
25
|
FROM (
|
|
26
26
|
SELECT
|
|
27
27
|
( 4 + tpl_hdr_size + tpl_data_size + (2*ma)
|
|
@@ -29,6 +29,7 @@ FROM (
|
|
|
29
29
|
- CASE WHEN ceil(tpl_data_size)::int%ma = 0 THEN ma ELSE ceil(tpl_data_size)::int%ma END
|
|
30
30
|
) AS tpl_size, bs - page_hdr AS size_per_block, (heappages + toastpages) AS tblpages, heappages,
|
|
31
31
|
toastpages, reltuples, toasttuples, bs, page_hdr, tblid, schemaname, tblname, fillfactor, is_na
|
|
32
|
+
-- , tpl_hdr_size, tpl_data_size
|
|
32
33
|
FROM (
|
|
33
34
|
SELECT
|
|
34
35
|
tbl.oid AS tblid, ns.nspname AS schemaname, tbl.relname AS tblname, tbl.reltuples,
|
|
@@ -40,24 +41,24 @@ FROM (
|
|
|
40
41
|
current_setting('block_size')::numeric AS bs,
|
|
41
42
|
CASE WHEN version()~'mingw32' OR version()~'64-bit|x86_64|ppc64|ia64|amd64' THEN 8 ELSE 4 END AS ma,
|
|
42
43
|
24 AS page_hdr,
|
|
43
|
-
23 + CASE WHEN MAX(coalesce(null_frac,0)) > 0 THEN ( 7 + count(
|
|
44
|
-
|
|
45
|
-
sum( (1-coalesce(s.null_frac, 0)) * coalesce(s.avg_width,
|
|
44
|
+
23 + CASE WHEN MAX(coalesce(s.null_frac,0)) > 0 THEN ( 7 + count(s.attname) ) / 8 ELSE 0::int END
|
|
45
|
+
+ CASE WHEN bool_or(att.attname = 'oid' and att.attnum < 0) THEN 4 ELSE 0 END AS tpl_hdr_size,
|
|
46
|
+
sum( (1-coalesce(s.null_frac, 0)) * coalesce(s.avg_width, 0) ) AS tpl_data_size,
|
|
46
47
|
bool_or(att.atttypid = 'pg_catalog.name'::regtype)
|
|
47
|
-
OR
|
|
48
|
+
OR sum(CASE WHEN att.attnum > 0 THEN 1 ELSE 0 END) <> count(s.attname) AS is_na
|
|
48
49
|
FROM pg_attribute AS att
|
|
49
50
|
JOIN pg_class AS tbl ON att.attrelid = tbl.oid
|
|
50
51
|
JOIN pg_namespace AS ns ON ns.oid = tbl.relnamespace
|
|
51
52
|
LEFT JOIN pg_stats AS s ON s.schemaname=ns.nspname
|
|
52
53
|
AND s.tablename = tbl.relname AND s.inherited=false AND s.attname=att.attname
|
|
53
54
|
LEFT JOIN pg_class AS toast ON tbl.reltoastrelid = toast.oid
|
|
54
|
-
WHERE
|
|
55
|
-
AND tbl.relkind
|
|
56
|
-
GROUP BY 1,2,3,4,5,6,7,8,9,10
|
|
55
|
+
WHERE NOT att.attisdropped
|
|
56
|
+
AND tbl.relkind in ('r','m')
|
|
57
|
+
GROUP BY 1,2,3,4,5,6,7,8,9,10
|
|
57
58
|
ORDER BY 2,3
|
|
58
59
|
) AS s
|
|
59
60
|
) AS s2
|
|
60
61
|
) AS s3
|
|
61
|
-
WHERE NOT is_na
|
|
62
|
+
-- WHERE NOT is_na
|
|
62
63
|
-- AND tblpages*((pst).free_percent + (pst).dead_tuple_percent)::float4/100 >= 1
|
|
63
|
-
|
|
64
|
+
ORDER BY schemaname, tblname;
|