Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking fillfactor setting for tables and indexes

There is maybe some function to check the fillfactor for indexes and tables? I've tried already \d+ but have basic definition only, without fillfactor value:

        Index "public.tab1_pkey"
 Column |  Type  | Definition | Storage 
--------+--------+------------+---------
 id     | bigint | id         | plain
primary key, btree, for table "public.tab1"

For tables haven't found anything. If table was created with fillfactor other than default:

CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    UNIQUE(name) WITH (fillfactor=70)
)
WITH (fillfactor=70);

Then \d+ distributorsshows non-standard fillfactor.

                            Table "public.distributors"                                                                                                                                        
 Column |         Type          | Modifiers | Storage  | Stats target | Description                                                                                                            
--------+-----------------------+-----------+----------+--------------+-------------                                                                                                           
 did    | integer               |           | plain    |              |                                                                                                                        
 name   | character varying(40) |           | extended |              |                                                                                                                        
Indexes:                                                                                                                                                                                       
    "distributors_name_key" UNIQUE CONSTRAINT, btree (name) WITH (fillfactor=70)                                                                                                               
Has OIDs: no
Options: fillfactor=70

But maybe there is a way to get this value without parsing output?

like image 825
Borys Avatar asked Apr 23 '14 11:04

Borys


1 Answers

You need to query the pg_class system table:

select t.relname as table_name, 
       t.reloptions
from pg_class t
  join pg_namespace n on n.oid = t.relnamespace
where t.relname in ('tab11_pkey', 'tab1')
  and n.nspname = 'public'

reloptions is an array, with each element containing one option=value definition. But it will be null for relations that have the default options.

like image 194
a_horse_with_no_name Avatar answered Sep 28 '22 06:09

a_horse_with_no_name