KFC_MALL REINDEX测试

36 阅读13分钟

#查看索引膨胀
SELECT schemaname "模式名",
       relname "表名",
       indexrelname "索引名",
       pg_size_pretty(total_size) "索引相关总大小",
       pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
 CASE
     WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误

     ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
 END AS "索引膨胀度"
FROM
  (SELECT schemaname,
          relname,
          indexrelname,
          pg_total_relation_size(indexrelid) AS total_size,
          pg_relation_size(indexrelid) AS index_data_size
   FROM pg_stat_user_indexes
   WHERE schemaname NOT IN ('pg_catalog',
                            'information_schema') and schemaname||'.'||relname='public.c_order_item_coupon_codes' )  idx_size order by "索引膨胀度" desc;


#查看索引膨胀
SELECT schemaname "模式名",
       relname "表名",
       indexrelname "索引名",
       pg_size_pretty(total_size) "索引相关总大小",
       pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
 CASE
     WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误

     ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
 END AS "索引膨胀度"
FROM
  (SELECT schemaname,
          relname,
          indexrelname,
          pg_total_relation_size(indexrelid) AS total_size,
          pg_relation_size(indexrelid) AS index_data_size
   FROM pg_stat_user_indexes
   WHERE schemaname NOT IN ('pg_catalog',
                            'information_schema') and schemaname||'.'||relname='public.c_order_payment_preference' )  idx_size order by "索引膨胀度" desc;

#查看索引膨胀
SELECT schemaname "模式名",
       relname "表名",
       indexrelname "索引名",
       pg_size_pretty(total_size) "索引相关总大小",
       pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
 CASE
     WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误

     ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
 END AS "索引膨胀度"
FROM
  (SELECT schemaname,
          relname,
          indexrelname,
          pg_total_relation_size(indexrelid) AS total_size,
          pg_relation_size(indexrelid) AS index_data_size
   FROM pg_stat_user_indexes
   WHERE schemaname NOT IN ('pg_catalog',
                            'information_schema') and schemaname||'.'||relname='public.c_pay_result' )  idx_size order by "索引膨胀度" desc;

一、 (44G)pk_c_order_item_coupon_codes

表                   
public.c_order_item_coupon_codes
index  
pk_c_order_item_coupon_codes   

 mall=# \d public.c_order_item_coupon_codes
                       Table "public.c_order_item_coupon_codes"
          Column          |           Type           | Collation | Nullable | Default 
--------------------------+--------------------------+-----------+----------+---------
 order_id                 | text                     |           | not null | 
 product_id               | text                     |           | not null | 
 sub_product_id           | text                     |           | not null | 
 sub_product_coupon_codes | text                     |           |          | 
 last_updated_stamp       | timestamp with time zone |           |          | 
 last_updated_tx_stamp    | timestamp with time zone |           |          | 
 created_stamp            | timestamp with time zone |           |          | 
 created_tx_stamp         | timestamp with time zone |           |          | 
 card                     | text                     |           |          | 
 user_code                | text                     |           |          | 
 amounts                  | numeric(18,2)            |           |          | 
 identification           | text                     |           |          | 
Indexes:
    "pk_c_order_item_coupon_codes" PRIMARY KEY, btree (order_id, product_id, sub_product_id)
    "c_itm_cpn_cds_tp_new" btree (last_updated_tx_stamp)
    "c_order_item_coupon_codes_card_idx" btree (card)
    "corderitemcouponcodes_orderid_new" btree (order_id)
    "corderitemcouponcodes_producti_new" btree (product_id)
    "corderitemcouponcodes_subprodu_new" btree (sub_product_id)
    "idx_c_order_item_coupon_codes_created_tx_stamp" btree (created_tx_stamp)
    "sub_product_coupon_codes_idx" btree (sub_product_coupon_codes)

mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-#
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_order_item_coupon_codes' )  idx_size order by "索引膨胀度" desc;
 模式名 |           表名            |                     索引名                     | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+---------------------------+------------------------------------------------+----------------+--------------+--------------------------------
 public | c_order_item_coupon_codes | sub_product_coupon_codes_idx                   | 16 GB          | 16 GB        |         0.01332188847689715266
 public | c_order_item_coupon_codes | corderitemcouponcodes_subprodu_new             | 13 GB          | 13 GB        |         0.00658084996809193387
 public | c_order_item_coupon_codes | corderitemcouponcodes_producti_new             | 13 GB          | 13 GB        |         0.00579542161692263112
 public | c_order_item_coupon_codes | pk_c_order_item_coupon_codes                   | 44 GB          | 44 GB        |         0.00477273784374993492
 public | c_order_item_coupon_codes | c_order_item_coupon_codes_card_idx             | 9713 MB        | 9713 MB      |         0.00474568745706761559
 public | c_order_item_coupon_codes | c_itm_cpn_cds_tp_new                           | 7585 MB        | 7585 MB      |         0.00298703933930809869
 public | c_order_item_coupon_codes | corderitemcouponcodes_orderid_new              | 22 GB          | 22 GB        |         0.00040763444973085935
 public | c_order_item_coupon_codes | idx_c_order_item_coupon_codes_created_tx_stamp | 4465 MB        | 4465 MB      | 0.0000000000000000000000000000
(8 rows)

mall=# \timing 
Timing is on.
mall=# reindex index pk_c_order_item_coupon_codes;
REINDEX
Time: 396399.269 ms (06:36.399)

mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-# 
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_order_item_coupon_codes' )  idx_size order by "索引膨胀度" desc;
 模式名 |           表名            |                     索引名                     | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+---------------------------+------------------------------------------------+----------------+--------------+--------------------------------
 public | c_order_item_coupon_codes | sub_product_coupon_codes_idx                   | 16 GB          | 16 GB        |         0.01332188847689715266
 public | c_order_item_coupon_codes | corderitemcouponcodes_subprodu_new             | 13 GB          | 13 GB        |         0.00658084996809193387
 public | c_order_item_coupon_codes | corderitemcouponcodes_producti_new             | 13 GB          | 13 GB        |         0.00579542161692263112
 public | c_order_item_coupon_codes | c_order_item_coupon_codes_card_idx             | 9713 MB        | 9713 MB      |         0.00474568745706761559
 public | c_order_item_coupon_codes | c_itm_cpn_cds_tp_new                           | 7585 MB        | 7585 MB      |         0.00298703933930809869
 public | c_order_item_coupon_codes | corderitemcouponcodes_orderid_new              | 22 GB          | 22 GB        |         0.00040763444973085935
 public | c_order_item_coupon_codes | pk_c_order_item_coupon_codes                   | 4611 MB        | 4611 MB      | 0.0000000000000000000000000000
 public | c_order_item_coupon_codes | idx_c_order_item_coupon_codes_created_tx_stamp | 4465 MB        | 4465 MB      | 0.0000000000000000000000000000
(8 rows)

Time: 10.652 ms

二、(6.6G)cpaymentmethodtype_new

表                       
mall.public.c_order_payment_preference
index
cpaymentmethodtype_new

 mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-# 
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_order_payment_preference' )  idx_size order by "索引膨胀度" desc;
 模式名 |            表名            |                     索引名                      | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+----------------------------+-------------------------------------------------+----------------+--------------+--------------------------------
 public | c_order_payment_preference | c_orr_pmt_prc_txsp_new                          | 6523 MB        | 6521 MB      |         0.02491958044052546769
 public | c_order_payment_preference | cpayment_new                                    | 5276 MB        | 5275 MB      |         0.02458534446881586021
 public | c_order_payment_preference | c_order_payment_pre_const_new                   | 10 GB          | 10 GB        |         0.02437480099402341591
 public | c_order_payment_preference | pk_c_order_payment_preference                   | 14 GB          | 14 GB        |         0.02067313888053610550
 public | c_order_payment_preference | cpaymentmethodtype_new                          | 6686 MB        | 6684 MB      |         0.01776502020771048627
 public | c_order_payment_preference | userlogin_new                                   | 6721 MB        | 6720 MB      |         0.01767178838498456044
 public | c_order_payment_preference | returnheader_new                                | 6722 MB        | 6721 MB      |         0.01766948758486003906
 public | c_order_payment_preference | idx_c_order_payment_preference_created_tx_stamp | 4016 MB        | 4016 MB      | 0.0000000000000000000000000000
(8 rows)

Time: 8.612 ms
mall=# reindex index cpaymentmethodtype_new;


REINDEX
Time: 337782.533 ms (05:37.783)

mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-# 
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_order_payment_preference' )  idx_size order by "索引膨胀度" desc;
 模式名 |            表名            |                     索引名                      | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+----------------------------+-------------------------------------------------+----------------+--------------+--------------------------------
 public | c_order_payment_preference | c_orr_pmt_prc_txsp_new                          | 6523 MB        | 6521 MB      |         0.02491958044052546769
 public | c_order_payment_preference | cpayment_new                                    | 5276 MB        | 5275 MB      |         0.02458534446881586021
 public | c_order_payment_preference | c_order_payment_pre_const_new                   | 10 GB          | 10 GB        |         0.02437480099402341591
 public | c_order_payment_preference | pk_c_order_payment_preference                   | 14 GB          | 14 GB        |         0.02067313888053610550
 public | c_order_payment_preference | userlogin_new                                   | 6721 MB        | 6720 MB      |         0.01767178838498456044
 public | c_order_payment_preference | returnheader_new                                | 6722 MB        | 6721 MB      |         0.01766948758486003906
 public | c_order_payment_preference | cpaymentmethodtype_new                          | 1096 MB        | 1096 MB      | 0.0000000000000000000000000000
 public | c_order_payment_preference | idx_c_order_payment_preference_created_tx_stamp | 4016 MB        | 4016 MB      | 0.0000000000000000000000000000
(8 rows)

Time: 9.182 ms

三、index_c_pay_result_orderid_new

表
public.c_pay_result
index
index_c_pay_result_orderid_new                                


mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-# 
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_pay_result' )  idx_size order by "索引膨胀度" desc;
 模式名 |     表名     |              索引名               | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+--------------+-----------------------------------+----------------+--------------+--------------------------------
 public | c_pay_result | c_p_rslt_txstmp_new               | 3627 MB        | 3627 MB      |         0.02434311294558129415
 public | c_pay_result | pk_c_pay_result                   | 11 GB          | 11 GB        |         0.02340193843802206275
 public | c_pay_result | index_c_pay_result_orderid_new    | 13 GB          | 13 GB        |         0.01704639946781972393
 public | c_pay_result | idx_c_pay_result_created_tx_stamp | 3219 MB        | 3219 MB      | 0.0000000000000000000000000000
(4 rows)

Time: 7.718 ms
mall=# reindex index  index_c_pay_result_orderid_new;
REINDEX
Time: 286696.292 ms (04:46.696)
mall=# SELECT schemaname "模式名",
       relname "表名",
       indexrelname "索引名",
       pg_size_pretty(total_size) "索引相关总大小",
       pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
 CASE
     WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
     ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
 END AS "索引膨胀度"
FROM
  (SELECT schemaname,
          relname,
          indexrelname,
          pg_total_relation_size(indexrelid) AS total_size,
          pg_relation_size(indexrelid) AS index_data_size
   FROM pg_stat_user_indexes
   WHERE schemaname NOT IN ('pg_catalog',
                            'information_schema') and schemaname||'.'||relname='public.c_pay_result' )  idx_size order by "索引膨胀度" desc;
 模式名 |     表名     |              索引名               | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+--------------+-----------------------------------+----------------+--------------+--------------------------------
 public | c_pay_result | c_p_rslt_txstmp_new               | 3627 MB        | 3627 MB      |         0.02434311294558129415
 public | c_pay_result | pk_c_pay_result                   | 11 GB          | 11 GB        |         0.02340193843802206275
 public | c_pay_result | idx_c_pay_result_created_tx_stamp | 3219 MB        | 3219 MB      | 0.0000000000000000000000000000
 public | c_pay_result | index_c_pay_result_orderid_new    | 1962 MB        | 1962 MB      | 0.0000000000000000000000000000
(4 rows)

Time: 8.483 ms

四、查看表年龄


mall=# select current_database(),rolname,nspname,relkind,relname,age(relfrozenxid),2^31-age(relfrozenxid) age_remain from pg_authid t1 join pg_class t2 on t1.oid=t2.relowner join pg_namespace t3 on t2.relnamespace=t3.oid where t2.relkind in ($$t$$,$$r$$) order by age(relfrozenxid) desc limit 5;
 current_database | rolname | nspname  | relkind |          relname           |    age     | age_remain 
------------------+---------+----------+---------+----------------------------+------------+------------
 mall             | mallapp | public   | r       | c_order_item_coupon_codes  | 1363472954 |  784010694
 mall             | mallapp | public   | r       | c_pay_result               | 1239064250 |  908419398
 mall             | mallapp | public   | r       | c_order_payment_preference | 1229976850 |  917506798
 mall             | mallapp | pg_toast | t       | pg_toast_233406            |  197751518 | 1949732130
 mall             | mallapp | public   | r       | analysis_category          |  197751518 | 1949732130
(5 rows)

mall=# vacuum ANALYZE  public.c_order_item_coupon_codes;
ERROR:  right sibling 232001 of block 415690 is not next child 416589 of block 456657 in index "corderitemcouponcodes_orderid_new"
Time: 79530.182 ms (01:19.530)

2.corderitemcouponcodes_orderid_new


执行vacuum analyse public.c_order_item_coupon_codes ,报错如下

数据库日志:
2024-10-30 22:51:15.096 CST,,,206371,,672240db.32623,3,,2024-10-30 22:21:15 CST,,0,LOG,00000,"checkpoint starting: time",,,,,,,,"LogCheckpointStart, xlog.c:8725",""
2024-10-30 22:51:50.209 CST,,,211376,,67224731.339b0,2,,2024-10-30 22:48:17 CST,3/21,0,ERROR,XX000,"right sibling 232001 of block 415690 is not next child 416589 of block 456657 in index ""corderitemcouponcodes_orderid_new""",,,,,"automatic vacuum of table ""mall.public.c_order_item_coupon_codes""",,,"_bt_mark_page_halfdead, nbtpage.c:1598",""
2024-10-30 22:54:04.751 CST,,,212091,,67224821.33c7b,1,,2024-10-30 22:52:17 CST,3/25,0,LOG,00000,"no left sibling (concurrent deletion?) of block 206402 in ""c_itm_cpn_cds_tp_new""",,,,,,,,"_bt_unlink_halfdead_page, nbtpage.c:1833",""
2024-10-30 22:54:59.635 CST,,,212091,,67224821.33c7b,2,,2024-10-30 22:52:17 CST,3/25,0,ERROR,XX000,"right sibling 232001 of block 415690 is not next child 416589 of block 456657 in index ""corderitemcouponcodes_orderid_new""",,,,,"automatic vacuum of table ""mall.public.c_order_item_coupon_codes""",,,"_bt_mark_page_halfdead, nbtpage.c:1598",""
2024-10-30 22:57:04.601 CST,,,212557,,672248d5.33e4d,1,,2024-10-30 22:55:17 CST,3/29,0,LOG,00000,"no left sibling (concurrent deletion?) of block 206402 in ""c_itm_cpn_cds_tp_new""",,,,,,,,"_bt_unlink_halfdead_page, nbtpage.c:1833",""
2024-10-30 22:58:00.220 CST,,,212557,,672248d5.33e4d,2,,2024-10-30 22:55:17 CST,3/29,0,ERROR,XX000,"right sibling 232001 of block 415690 is not next child 416589 of block 456657 in index ""corderitemcouponcodes_orderid_new""",,,,,"automatic vacuum of table ""mall.public.c_order_item_coupon_codes""",,,"_bt_mark_page_halfdead, nbtpage.c:1598",""


mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-# 
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_order_item_coupon_codes' )  idx_size order by "索引膨胀度" desc;
 模式名 |           表名            |                     索引名                     | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+---------------------------+------------------------------------------------+----------------+--------------+--------------------------------
 public | c_order_item_coupon_codes | c_itm_cpn_cds_tp_new                           | 7586 MB        | 7585 MB      |         0.01411118584431756966
 public | c_order_item_coupon_codes | sub_product_coupon_codes_idx                   | 16 GB          | 16 GB        |         0.01332188847689715266
 public | c_order_item_coupon_codes | corderitemcouponcodes_subprodu_new             | 13 GB          | 13 GB        |         0.00658084996809193387
 public | c_order_item_coupon_codes | corderitemcouponcodes_producti_new             | 13 GB          | 13 GB        |         0.00579542161692263112
 public | c_order_item_coupon_codes | c_order_item_coupon_codes_card_idx             | 9713 MB        | 9713 MB      |         0.00474568745706761559
 public | c_order_item_coupon_codes | corderitemcouponcodes_orderid_new              | 22 GB          | 22 GB        |         0.00356680143514501935
 public | c_order_item_coupon_codes | pk_c_order_item_coupon_codes                   | 4611 MB        | 4611 MB      | 0.0000000000000000000000000000
 public | c_order_item_coupon_codes | idx_c_order_item_coupon_codes_created_tx_stamp | 4465 MB        | 4465 MB      | 0.0000000000000000000000000000
(8 rows)

Time: 9.652 ms
mall=# reindex index corderitemcouponcodes_orderid_new;
REINDEX
Time: 150927.261 ms (02:30.927)
mall=# SELECT schemaname "模式名",
mall-#        relname "表名",
mall-#        indexrelname "索引名",
mall-#        pg_size_pretty(total_size) "索引相关总大小",
mall-#        pg_size_pretty(index_data_size) "索引本身大小", -- 计算空闲空间百分比作为膨胀度的一个近似指标
mall-#  CASE
mall-#      WHEN index_data_size = 0 THEN NULL -- 避免除以零的错误
mall-# 
mall-#      ELSE (total_size::bigint - index_data_size::bigint) * 100.0 / index_data_size::bigint
mall-#  END AS "索引膨胀度"
mall-# FROM
mall-#   (SELECT schemaname,
mall(#           relname,
mall(#           indexrelname,
mall(#           pg_total_relation_size(indexrelid) AS total_size,
mall(#           pg_relation_size(indexrelid) AS index_data_size
mall(#    FROM pg_stat_user_indexes
mall(#    WHERE schemaname NOT IN ('pg_catalog',
mall(#                             'information_schema') and schemaname||'.'||relname='public.c_order_item_coupon_codes' )  idx_size order by "索引膨胀度" desc;
 模式名 |           表名            |                     索引名                     | 索引相关总大小 | 索引本身大小 |           索引膨胀度           
--------+---------------------------+------------------------------------------------+----------------+--------------+--------------------------------
 public | c_order_item_coupon_codes | c_itm_cpn_cds_tp_new                           | 7586 MB        | 7585 MB      |         0.01411118584431756966
 public | c_order_item_coupon_codes | sub_product_coupon_codes_idx                   | 16 GB          | 16 GB        |         0.01332188847689715266
 public | c_order_item_coupon_codes | corderitemcouponcodes_subprodu_new             | 13 GB          | 13 GB        |         0.00658084996809193387
 public | c_order_item_coupon_codes | corderitemcouponcodes_producti_new             | 13 GB          | 13 GB        |         0.00579542161692263112
 public | c_order_item_coupon_codes | c_order_item_coupon_codes_card_idx             | 9713 MB        | 9713 MB      |         0.00474568745706761559
 public | c_order_item_coupon_codes | pk_c_order_item_coupon_codes                   | 4611 MB        | 4611 MB      | 0.0000000000000000000000000000
 public | c_order_item_coupon_codes | corderitemcouponcodes_orderid_new              | 2417 MB        | 2417 MB      | 0.0000000000000000000000000000
 public | c_order_item_coupon_codes | idx_c_order_item_coupon_codes_created_tx_stamp | 4465 MB        | 4465 MB      | 0.0000000000000000000000000000
(8 rows)

Time: 9.186 ms

3.c_itm_cpn_cds_tp_new

重建完索引corderitemcouponcodes_orderid_new,
执行vacuum analyse public.c_order_item_coupon_codes ,数据库报错如下


2024-10-30 23:10:01.206 CST,,,214848,,67224ba5.34740,1,,2024-10-30 23:07:17 CST,3/45,0,LOG,00000,"no left sibling (concurrent deletion?) of block 206402 in ""c_itm_cpn_cds_tp_new""",,,,,,,,"_bt_unlink_halfdead_page, nbtpage.c:1833",""