5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLでINDEXをテーブルロックしないで作りなおす

Last updated at Posted at 2019-05-16

PostgreSQLのREINDEXでは実行中にテーブルロックが発生します。これを回避するには、CREATE INDEXCONCURRENTLYを指定します。また、この操作はShareLockを取得するので同じテーブルに対して同時に実行するとDeadLockとなるので注意が必要。

一時インデックスを作成

CREATE INDEX CONCURRENTLY idx_new ON tbl (i);

古いインデックスを捨てる

DROP INDEX idx_old
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?