it技術:データベース:postgresql:運用
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン次のリビジョン両方とも次のリビジョン | ||
it技術:データベース:postgresql:運用 [2020/01/24 17:08] – [VACUUM実行確認] yajuadmin | it技術:データベース:postgresql:運用 [2020/02/28 18:20] – [インデックスの再構築] yajuadmin | ||
---|---|---|---|
行 513: | 行 513: | ||
SELECT relname, n_live_tup, n_dead_tup, last_vacuum, | SELECT relname, n_live_tup, n_dead_tup, last_vacuum, | ||
FROM pg_stat_all_tables | FROM pg_stat_all_tables | ||
- | WHERE schemaname = 'wh_kousei' | + | WHERE schemaname = 'public' |
ORDER BY relname | ORDER BY relname | ||
</ | </ | ||
行 558: | 行 558: | ||
ageが15億になる前にVACUUMをかける。かけるとまた10億になる。 | ageが15億になる前にVACUUMをかける。かけるとまた10億になる。 | ||
[[http:// | [[http:// | ||
+ | |||
+ | ===== インデックスの再構築 ===== | ||
+ | |||
+ | ==== リインデックス ==== | ||
+ | reindexコマンドを使用して、インデックスの再構築する。\\ | ||
+ | <code bat> | ||
+ | rem PK_REP_RES_QUEをリインデックスする | ||
+ | SET PGPASSWORD=wh_kousei | ||
+ | psql -U wh_kousei -c " | ||
+ | </ | ||
+ | |||
+ | ==== テーブルロックなしのリインデックス ==== | ||
+ | reindexコマンドはテーブルロックがかかってしまうので、運用中のDBに対して使うのは難しい。\\ | ||
+ | ただ、PostgreSQLでは別名で全く同じインデックスの作成を行うことができる | ||
+ | |||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | |||
+ | <code bat> | ||
+ | rem PK_REP_RES_QUEをリインデックスする | ||
+ | SET PGPASSWORD=wh_test | ||
+ | psql -U wh_test -f reindex_rep_res_que.sql | ||
+ | </ | ||
+ | |||
+ | <code sql reindex_rep_res_que.sql> | ||
+ | create unique index concurrently pk_rep_res_que_new on rep_res_que(que_id); | ||
+ | |||
+ | alter table rep_res_que drop constraint pk_rep_res_que; | ||
+ | alter index pk_rep_res_que_new rename to pk_rep_res_que; | ||
+ | alter table rep_res_que add primary key using index pk_rep_res_que; | ||
+ | </ | ||
===== 確認用SQL ===== | ===== 確認用SQL ===== | ||
=== テーブルのディスク使用量を取得する === | === テーブルのディスク使用量を取得する === |
it技術/データベース/postgresql/運用.txt · 最終更新: 2022/06/06 11:17 by yajuadmin