File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -1685,14 +1685,28 @@ ReindexIndex(RangeVar *indexRelation)
16851685{
16861686 Oid indOid ;
16871687 Oid heapOid = InvalidOid ;
1688+ Relation irel ;
1689+ char persistence ;
16881690
1689- /* lock level used here should match index lock reindex_index() */
1691+ /*
1692+ * Find and lock index, and check permissions on table; use callback to
1693+ * obtain lock on table first, to avoid deadlock hazard. The lock level
1694+ * used here must match the index lock obtained in reindex_index().
1695+ */
16901696 indOid = RangeVarGetRelidExtended (indexRelation , AccessExclusiveLock ,
16911697 false, false,
16921698 RangeVarCallbackForReindexIndex ,
16931699 (void * ) & heapOid );
16941700
1695- reindex_index (indOid , false, indexRelation -> relpersistence );
1701+ /*
1702+ * Obtain the current persistence of the existing index. We already hold
1703+ * lock on the index.
1704+ */
1705+ irel = index_open (indOid , NoLock );
1706+ persistence = irel -> rd_rel -> relpersistence ;
1707+ index_close (irel , NoLock );
1708+
1709+ reindex_index (indOid , false, persistence );
16961710
16971711 return indOid ;
16981712}
Original file line number Diff line number Diff line change @@ -208,6 +208,28 @@ CREATE TABLE IF NOT EXISTS test_tsvector(
208208);
209209NOTICE: relation "test_tsvector" already exists, skipping
210210CREATE UNLOGGED TABLE unlogged1 (a int primary key); -- OK
211+ CREATE TEMPORARY TABLE unlogged2 (a int primary key); -- OK
212+ SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~ '^unlogged\d' ORDER BY relname;
213+ relname | relkind | relpersistence
214+ ----------------+---------+----------------
215+ unlogged1 | r | u
216+ unlogged1_pkey | i | u
217+ unlogged2 | r | t
218+ unlogged2_pkey | i | t
219+ (4 rows)
220+
221+ REINDEX INDEX unlogged1_pkey;
222+ REINDEX INDEX unlogged2_pkey;
223+ SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~ '^unlogged\d' ORDER BY relname;
224+ relname | relkind | relpersistence
225+ ----------------+---------+----------------
226+ unlogged1 | r | u
227+ unlogged1_pkey | i | u
228+ unlogged2 | r | t
229+ unlogged2_pkey | i | t
230+ (4 rows)
231+
232+ DROP TABLE unlogged2;
211233INSERT INTO unlogged1 VALUES (42);
212234CREATE UNLOGGED TABLE public.unlogged2 (a int primary key); -- also OK
213235CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key); -- not OK
Original file line number Diff line number Diff line change @@ -246,6 +246,12 @@ CREATE TABLE IF NOT EXISTS test_tsvector(
246246);
247247
248248CREATE UNLOGGED TABLE unlogged1 (a int primary key ); -- OK
249+ CREATE TEMPORARY TABLE unlogged2 (a int primary key ); -- OK
250+ SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~ ' ^unlogged\d ' ORDER BY relname;
251+ REINDEX INDEX unlogged1_pkey;
252+ REINDEX INDEX unlogged2_pkey;
253+ SELECT relname, relkind, relpersistence FROM pg_class WHERE relname ~ ' ^unlogged\d ' ORDER BY relname;
254+ DROP TABLE unlogged2;
249255INSERT INTO unlogged1 VALUES (42 );
250256CREATE UNLOGGED TABLE public .unlogged2 (a int primary key ); -- also OK
251257CREATE UNLOGGED TABLE pg_temp .unlogged3 (a int primary key ); -- not OK
You can’t perform that action at this time.
0 commit comments