Commit a56a016c authored by Tom Lane's avatar Tom Lane

Repair some REINDEX problems per recent discussions. The relcache is

now able to cope with assigning new relfilenode values to nailed-in-cache
indexes, so they can be reindexed using the fully crash-safe method.  This
leaves only shared system indexes as special cases.  Remove the 'index
deactivation' code, since it provides no useful protection in the shared-
index case.  Require reindexing of shared indexes to be done in standalone
mode, but remove other restrictions on REINDEX.  -P (IgnoreSystemIndexes)
now prevents using indexes for lookups, but does not disable index updates.
It is therefore safe to allow from PGOPTIONS.  Upshot: reindexing system catalogs
can be done without a standalone backend for all cases except
shared catalogs.
parent 5f78c6a8
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/postgres-ref.sgml,v 1.36 2003/09/18 20:30:15 tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/postgres-ref.sgml,v 1.37 2003/09/24 18:54:01 tgl Exp $
PostgreSQL documentation
-->
......@@ -177,9 +177,9 @@ PostgreSQL documentation
<term><option>-P</option></term>
<listitem>
<para>
Ignore system indexes while scanning/updating system tables. The
<command>REINDEX</command> command for system tables/indexes
requires this option to be used.
Ignore system indexes when reading system tables (but still update
the indexes when modifying the tables). This is useful when
recovering from damaged system indexes.
</para>
</listitem>
</varlistentry>
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reindex.sgml,v 1.20 2003/09/11 21:42:20 momjian Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reindex.sgml,v 1.21 2003/09/24 18:54:01 tgl Exp $
PostgreSQL documentation
-->
......@@ -56,43 +56,6 @@ REINDEX { DATABASE | TABLE | INDEX } <replaceable class="PARAMETER">name</replac
</listitem>
</itemizedlist>
</para>
<para>
If you suspect corruption of an index on a user table, you can
simply rebuild that index, or all indexes on the table, using
<command>REINDEX INDEX</command> or <command>REINDEX
TABLE</command>. Another approach to dealing with a corrupted
user-table index is just to drop and recreate it. This may in fact
be preferable if you would like to maintain some semblance of
normal operation on the table meanwhile. <command>REINDEX</>
acquires exclusive lock on the table, while <command>CREATE
INDEX</> only locks out writes not reads of the table.
</para>
<para>
Things are more difficult if you need to recover from corruption of
an index on a system table. In this case it's important for the
system to not have used any of the suspect indexes itself.
(Indeed, in this sort of scenario you may find that server
processes are crashing immediately at start-up, due to reliance on
the corrupted indexes.) To recover safely, the server must be shut
down and a stand-alone <productname>PostgreSQL</productname> server
must be started instead with the command-line options
<option>-O</option> and <option>-P</option>. (These options allow
system table modifications and prevent use of system indexes,
respectively.) Then, <command>REINDEX DATABASE</>,
<command>REINDEX TABLE</>, or <command>REINDEX INDEX</> can be
issued, depending on how much you want to reconstruct. If in
doubt, use <command>REINDEX DATABASE FORCE</> to force
reconstruction of all system indexes in the database. Then quit
the standalone server session and restart the real server.
</para>
<para>
See the <xref linkend="app-postgres"> reference page for more
information about how to interact with the stand-alone server
interface.
</para>
</refsect1>
<refsect1>
......@@ -104,8 +67,8 @@ REINDEX { DATABASE | TABLE | INDEX } <replaceable class="PARAMETER">name</replac
<listitem>
<para>
Recreate all system indexes of a specified database. Indexes on
user tables are not included. This form of <command>REINDEX</>
can only be used in stand-alone mode (see above).
user tables are not processed. Also, indexes on shared system
catalogs are skipped except in stand-alone mode (see below).
</para>
</listitem>
</varlistentry>
......@@ -114,7 +77,8 @@ REINDEX { DATABASE | TABLE | INDEX } <replaceable class="PARAMETER">name</replac
<term><literal>TABLE</literal></term>
<listitem>
<para>
Recreate all indexes of a specified table.
Recreate all indexes of a specified table. If the table has a
secondary <quote>TOAST</> table, that is reindexed as well.
</para>
</listitem>
</varlistentry>
......@@ -142,16 +106,93 @@ REINDEX { DATABASE | TABLE | INDEX } <replaceable class="PARAMETER">name</replac
<term><literal>FORCE</literal></term>
<listitem>
<para>
Force rebuild of system indexes. Without this key word,
<command>REINDEX</> skips system indexes that are not marked
invalid. <literal>FORCE</> is irrelevant for <command>REINDEX
INDEX</> or when reindexing user indexes.
This is an obsolete option; it is ignored if specified.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
If you suspect corruption of an index on a user table, you can
simply rebuild that index, or all indexes on the table, using
<command>REINDEX INDEX</command> or <command>REINDEX
TABLE</command>. Another approach to dealing with a corrupted
user-table index is just to drop and recreate it. This may in fact
be preferable if you would like to maintain some semblance of
normal operation on the table meanwhile. <command>REINDEX</>
acquires exclusive lock on the table, while <command>CREATE
INDEX</> only locks out writes not reads of the table.
</para>
<para>
Things are more difficult if you need to recover from corruption of
an index on a system table. In this case it's important for the
system to not have used any of the suspect indexes itself.
(Indeed, in this sort of scenario you may find that server
processes are crashing immediately at start-up, due to reliance on
the corrupted indexes.) To recover safely, the server must be started
with the <option>-P</option> option, which prevents it from using
indexes for system catalog lookups.
</para>
<para>
One way to do this is to shut down the postmaster and start a stand-alone
<productname>PostgreSQL</productname> server
with the <option>-P</option> option included on its command line.
Then, <command>REINDEX DATABASE</>,
<command>REINDEX TABLE</>, or <command>REINDEX INDEX</> can be
issued, depending on how much you want to reconstruct. If in
doubt, use <command>REINDEX DATABASE</> to select
reconstruction of all system indexes in the database. Then quit
the standalone server session and restart the regular server.
See the <xref linkend="app-postgres"> reference page for more
information about how to interact with the stand-alone server
interface.
</para>
<para>
Alternatively, a regular server session can be started with
<option>-P</option> included in its command line options.
The method for doing this varies across clients, but in all
<application>libpq</>-based clients, it is possible to set
the <envar>PGOPTIONS</envar> environment variable to <literal>-P</>
before starting the client. Note that while this method does not
require locking out other clients, it may still be wise to prevent
other users from connecting to the damaged database until repairs
have been completed.
</para>
<para>
If corruption is suspected in the indexes of any of the shared
system catalogs (<structname>pg_database</structname>,
<structname>pg_group</structname>, or
<structname>pg_shadow</structname>), then a standalone server
must be used to repair it. <command>REINDEX</> will not process
shared catalogs in multiuser mode.
</para>
<para>
For all indexes except the shared system catalogs, <command>REINDEX</>
is crash-safe and transaction-safe. <command>REINDEX</> is not
crash-safe for shared indexes, which is why this case is disallowed
during normal operation. If a failure occurs while reindexing one
of these catalogs in standalone mode, it is important that the failure
be rectified and the <command>REINDEX</> operation redone
before attempting to restart the regular server.
</para>
<para>
Prior to <productname>PostgreSQL</productname> 7.4, <command>REINDEX
TABLE</> did not automatically process TOAST tables, and so those had
to be reindexed by separate commands. This is still possible, but
redundant.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
......@@ -172,11 +213,15 @@ REINDEX INDEX my_index;
</para>
<para>
Rebuild all system indexes (this will only work in a stand-alone
server session):
Rebuild all system indexes in a particular database, without trusting them
to be valid already:
<programlisting>
REINDEX DATABASE my_database FORCE;
$ <userinput>export PGOPTIONS="-P"</userinput>
$ <userinput>psql broken_db</userinput>
...
broken_db=> REINDEX DATABASE broken_db;
broken_db=> \q
</programlisting>
</para>
</refsect1>
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.40 2003/08/04 02:39:57 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.41 2003/09/24 18:54:01 tgl Exp $
*
* NOTES
* many of the old access method routines have been turned into
......@@ -184,21 +184,32 @@ systable_beginscan(Relation heapRelation,
int nkeys, ScanKey key)
{
SysScanDesc sysscan;
Relation irel;
if (indexOK && !IsIgnoringSystemIndexes())
{
/* We assume it's a system index, so index_openr is OK */
irel = index_openr(indexRelname);
if (ReindexIsProcessingIndex(RelationGetRelid(irel)))
{
/* oops, can't use index that's being rebuilt */
index_close(irel);
irel = NULL;
}
}
else
irel = NULL;
sysscan = (SysScanDesc) palloc(sizeof(SysScanDescData));
sysscan->heap_rel = heapRelation;
sysscan->irel = irel;
if (indexOK &&
heapRelation->rd_rel->relhasindex &&
!IsIgnoringSystemIndexes())
if (irel)
{
Relation irel;
int i;
/* We assume it's a system index, so index_openr is OK */
sysscan->irel = irel = index_openr(indexRelname);
/*
* Change attribute numbers to be index column numbers.
*
......@@ -210,13 +221,13 @@ systable_beginscan(Relation heapRelation,
Assert(key[i].sk_attno == irel->rd_index->indkey[i]);
key[i].sk_attno = i + 1;
}
sysscan->iscan = index_beginscan(heapRelation, irel, snapshot,
nkeys, key);
sysscan->scan = NULL;
}
else
{
sysscan->irel = NULL;
sysscan->scan = heap_beginscan(heapRelation, snapshot, nkeys, key);
sysscan->iscan = NULL;
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.152 2003/08/08 21:41:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.153 2003/09/24 18:54:01 tgl Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
......@@ -834,8 +834,6 @@ StartTransaction(void)
*/
s->state = TRANS_START;
SetReindexProcessing(false);
/*
* generate a new transaction id
*/
......@@ -1085,6 +1083,7 @@ AbortTransaction(void)
AtEOXact_Namespace(false);
AtEOXact_CatCache(false);
AtEOXact_Files();
SetReindexProcessing(InvalidOid, InvalidOid);
pgstat_count_xact_rollback();
/*
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.16 2003/08/04 02:39:58 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.17 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -77,32 +77,29 @@ LargeObjectDrop(Oid loid)
{
bool found = false;
Relation pg_largeobject;
Relation pg_lo_idx;
ScanKeyData skey[1];
IndexScanDesc sd;
SysScanDesc sd;
HeapTuple tuple;
ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0,
(AttrNumber) 1,
ScanKeyEntryInitialize(&skey[0], 0x0,
(AttrNumber) Anum_pg_largeobject_loid,
(RegProcedure) F_OIDEQ,
ObjectIdGetDatum(loid));
pg_largeobject = heap_openr(LargeObjectRelationName, RowShareLock);
pg_lo_idx = index_openr(LargeObjectLOidPNIndex);
pg_largeobject = heap_openr(LargeObjectRelationName, RowExclusiveLock);
sd = index_beginscan(pg_largeobject, pg_lo_idx, SnapshotNow, 1, skey);
sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndex, true,
SnapshotNow, 1, skey);
while ((tuple = index_getnext(sd, ForwardScanDirection)) != NULL)
while ((tuple = systable_getnext(sd)) != NULL)
{
simple_heap_delete(pg_largeobject, &tuple->t_self);
found = true;
}
index_endscan(sd);
systable_endscan(sd);
index_close(pg_lo_idx);
heap_close(pg_largeobject, RowShareLock);
heap_close(pg_largeobject, RowExclusiveLock);
if (!found)
ereport(ERROR,
......@@ -115,32 +112,29 @@ LargeObjectExists(Oid loid)
{
bool retval = false;
Relation pg_largeobject;
Relation pg_lo_idx;
ScanKeyData skey[1];
IndexScanDesc sd;
SysScanDesc sd;
HeapTuple tuple;
/*
* See if we can find any tuples belonging to the specified LO
*/
ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0,
(AttrNumber) 1,
ScanKeyEntryInitialize(&skey[0], 0x0,
(AttrNumber) Anum_pg_largeobject_loid,
(RegProcedure) F_OIDEQ,
ObjectIdGetDatum(loid));
pg_largeobject = heap_openr(LargeObjectRelationName, RowShareLock);
pg_lo_idx = index_openr(LargeObjectLOidPNIndex);
pg_largeobject = heap_openr(LargeObjectRelationName, AccessShareLock);
sd = index_beginscan(pg_largeobject, pg_lo_idx, SnapshotNow, 1, skey);
sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndex, true,
SnapshotNow, 1, skey);
if ((tuple = index_getnext(sd, ForwardScanDirection)) != NULL)
if ((tuple = systable_getnext(sd)) != NULL)
retval = true;
index_endscan(sd);
systable_endscan(sd);
index_close(pg_lo_idx);
heap_close(pg_largeobject, RowShareLock);
heap_close(pg_largeobject, AccessShareLock);
return retval;
}
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.34 2003/09/10 19:59:23 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.35 2003/09/24 18:54:01 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
......@@ -1095,24 +1095,25 @@ DropCast(DropCastStmt *stmt)
void
DropCastById(Oid castOid)
{
Relation relation,
index;
Relation relation;
ScanKeyData scankey;
IndexScanDesc scan;
SysScanDesc scan;
HeapTuple tuple;
relation = heap_openr(CastRelationName, RowExclusiveLock);
index = index_openr(CastOidIndex);
ScanKeyEntryInitialize(&scankey, 0x0,
1, F_OIDEQ, ObjectIdGetDatum(castOid));
scan = index_beginscan(relation, index, SnapshotNow, 1, &scankey);
tuple = index_getnext(scan, ForwardScanDirection);
ObjectIdAttributeNumber,
F_OIDEQ,
ObjectIdGetDatum(castOid));
scan = systable_beginscan(relation, CastOidIndex, true,
SnapshotNow, 1, &scankey);
tuple = systable_getnext(scan);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "could not find tuple for cast %u", castOid);
simple_heap_delete(relation, &tuple->t_self);
index_endscan(scan);
index_close(index);
systable_endscan(scan);
heap_close(relation, RowExclusiveLock);
}
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.108 2003/09/23 01:51:09 inoue Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.109 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -112,14 +112,6 @@ DefineIndex(RangeVar *heapRelation,
relationId = RelationGetRelid(rel);
namespaceId = RelationGetNamespace(rel);
if (!IsBootstrapProcessingMode() &&
IsSystemRelation(rel) &&
!IndexesAreActive(rel))
ereport(ERROR,
(errcode(ERRCODE_INDEXES_DEACTIVATED),
errmsg("existing indexes are inactive"),
errhint("REINDEX the table first.")));
heap_close(rel, NoLock);
/*
......@@ -599,10 +591,6 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
{
Oid indOid;
HeapTuple tuple;
bool overwrite;
/* Choose in-place-or-not mode */
overwrite = IsIgnoringSystemIndexes();
indOid = RangeVarGetRelid(indexRelation, false);
tuple = SearchSysCache(RELOID,
......@@ -617,37 +605,14 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
errmsg("relation \"%s\" is not an index",
indexRelation->relname)));
if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
!IsToastClass((Form_pg_class) GETSTRUCT(tuple)))
{
if (!allowSystemTableMods)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied: \"%s\" is a system index",
indexRelation->relname),
errhint("Do REINDEX in standalone postgres with -O -P options.")));
if (!IsIgnoringSystemIndexes())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied: \"%s\" is a system index",
indexRelation->relname),
errhint("Do REINDEX in standalone postgres with -P -O options.")));
}
/* Check permissions */
if (!pg_class_ownercheck(indOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
indexRelation->relname);
ReleaseSysCache(tuple);
/*
* In-place REINDEX within a transaction block is dangerous, because
* if the transaction is later rolled back we have no way to undo
* truncation of the index's physical file. Disallow it.
*/
if (overwrite)
PreventTransactionChain((void *) indexRelation, "REINDEX");
if (!reindex_index(indOid, force, overwrite))
ereport(WARNING,
(errmsg("index \"%s\" wasn't reindexed",
indexRelation->relname)));
reindex_index(indOid);
}
/*
......@@ -655,54 +620,62 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
* Recreate indexes of a table.
*/
void
ReindexTable(RangeVar *relation, bool force)
ReindexTable(RangeVar *relation, bool force /* currently unused */ )
{
Oid heapOid;
char relkind;
HeapTuple tuple;
heapOid = RangeVarGetRelid(relation, false);
relkind = get_rel_relkind(heapOid);
tuple = SearchSysCache(RELOID,
ObjectIdGetDatum(heapOid),
0, 0, 0);
if (!HeapTupleIsValid(tuple)) /* shouldn't happen */
elog(ERROR, "cache lookup failed for relation %u", heapOid);
if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE)
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_RELATION &&
((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_TOASTVALUE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a table",
relation->relname)));
/*
* In-place REINDEX within a transaction block is dangerous, because
* if the transaction is later rolled back we have no way to undo
* truncation of the index's physical file. Disallow it.
*
* XXX we assume that in-place reindex will only be done if
* IsIgnoringSystemIndexes() is true.
*/
if (IsIgnoringSystemIndexes())
PreventTransactionChain((void *) relation, "REINDEX");
/* Check permissions */
if (!pg_class_ownercheck(heapOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
relation->relname);
/* Can't reindex shared tables except in standalone mode */
if (((Form_pg_class) GETSTRUCT(tuple))->relisshared && IsUnderPostmaster)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("shared table \"%s\" can only be reindexed in standalone mode",
relation->relname)));
ReleaseSysCache(tuple);
if (!reindex_relation(heapOid, force))
if (!reindex_relation(heapOid))
ereport(WARNING,
(errmsg("table \"%s\" wasn't reindexed",
(errmsg("table \"%s\" has no indexes",
relation->relname)));
}
/*
* ReindexDatabase
* Recreate indexes of a database.
*
* To reduce the probability of deadlocks, each table is reindexed in a
* separate transaction, so we can release the lock on it right away.
*/
void
ReindexDatabase(const char *dbname, bool force, bool all)
ReindexDatabase(const char *dbname, bool force /* currently unused */,
bool all)
{
Relation relationRelation;
HeapScanDesc scan;
HeapTuple tuple;
MemoryContext private_context;
MemoryContext old;
int relcnt,
relalc,
i,
oncealc = 200;
Oid *relids = (Oid *) NULL;
List *relids = NIL;
AssertArg(dbname);
......@@ -715,21 +688,12 @@ ReindexDatabase(const char *dbname, bool force, bool all)
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
dbname);
if (!allowSystemTableMods)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("REINDEX DATABASE must be done in standalone postgres with -O -P options")));
if (!IsIgnoringSystemIndexes())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("REINDEX DATABASE must be done in standalone postgres with -P -O options")));
/*
* We cannot run inside a user transaction block; if we were inside a
* transaction, then our commit- and start-transaction-command calls
* would not have the intended effect!
*/
PreventTransactionChain((void *) dbname, "REINDEX");
PreventTransactionChain((void *) dbname, "REINDEX DATABASE");
/*
* Create a memory context that will survive forced transaction
......@@ -743,55 +707,68 @@ ReindexDatabase(const char *dbname, bool force, bool all)
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
/*
* We always want to reindex pg_class first. This ensures that if
* there is any corruption in pg_class' indexes, they will be fixed
* before we process any other tables. This is critical because
* reindexing itself will try to update pg_class.
*/
old = MemoryContextSwitchTo(private_context);
relids = lappendo(relids, RelOid_pg_class);
MemoryContextSwitchTo(old);
/*
* Scan pg_class to build a list of the relations we need to reindex.
*
* We only consider plain relations here (toast rels will be processed
* indirectly by reindex_relation).
*/
relationRelation = heap_openr(RelationRelationName, AccessShareLock);
scan = heap_beginscan(relationRelation, SnapshotNow, 0, NULL);
relcnt = relalc = 0;
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
char relkind;
Form_pg_class classtuple = (Form_pg_class) GETSTRUCT(tuple);
if (!all)
{
if (!(IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
!IsToastClass((Form_pg_class) GETSTRUCT(tuple))))
if (classtuple->relkind != RELKIND_RELATION)
continue;
}
relkind = ((Form_pg_class) GETSTRUCT(tuple))->relkind;
if (relkind == RELKIND_RELATION || relkind == RELKIND_TOASTVALUE)
{
old = MemoryContextSwitchTo(private_context);
if (relcnt == 0)
if (!all) /* only system tables? */
{
relalc = oncealc;
relids = palloc(sizeof(Oid) * relalc);
if (!IsSystemClass(classtuple))
continue;
}
else if (relcnt >= relalc)
if (IsUnderPostmaster) /* silently ignore shared tables */
{
relalc *= 2;
relids = repalloc(relids, sizeof(Oid) * relalc);
if (classtuple->relisshared)
continue;
}
if (HeapTupleGetOid(tuple) == RelOid_pg_class)
continue; /* got it already */
old = MemoryContextSwitchTo(private_context);
relids = lappendo(relids, HeapTupleGetOid(tuple));
MemoryContextSwitchTo(old);
relids[relcnt] = HeapTupleGetOid(tuple);
relcnt++;
}
}
heap_endscan(scan);
heap_close(relationRelation, AccessShareLock);
/* Now reindex each rel in a separate transaction */
CommitTransactionCommand();
for (i = 0; i < relcnt; i++)
while (relids)
{
Oid relid = lfirsto(relids);
StartTransactionCommand();
SetQuerySnapshot(); /* might be needed for functions in
* indexes */
if (reindex_relation(relids[i], force))
if (reindex_relation(relid))
ereport(NOTICE,
(errmsg("relation %u was reindexed", relids[i])));
(errmsg("table \"%s\" was reindexed",
get_rel_name(relid))));
CommitTransactionCommand();
relids = lnext(relids);
}
StartTransactionCommand();
......
......@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.259 2003/08/04 02:39:58 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.260 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -904,11 +904,6 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
int nindexes,
i;
VRelStats *vacrelstats;
bool reindex = false;
if (IsIgnoringSystemIndexes() &&
IsSystemRelation(onerel))
reindex = true;
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,
&OldestXmin, &FreezeLimit);
......@@ -927,27 +922,9 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
/* Now open all indexes of the relation */
vac_open_indexes(onerel, &nindexes, &Irel);
if (!Irel)
reindex = false;
else if (!RelationGetForm(onerel)->relhasindex)
reindex = true;
if (nindexes > 0)
vacrelstats->hasindex = true;
#ifdef NOT_USED
/*
* reindex in VACUUM is dangerous under WAL. ifdef out until it
* becomes safe.
*/
if (reindex)
{
vac_close_indexes(nindexes, Irel);
Irel = (Relation *) NULL;
activate_indexes_of_a_table(onerel, false);
}
#endif /* NOT_USED */
/* Clean/scan index relation(s) */
if (Irel != (Relation *) NULL)
{
......@@ -994,11 +971,6 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
}
}
#ifdef NOT_USED
if (reindex)
activate_indexes_of_a_table(onerel, true);
#endif /* NOT_USED */
/* update shared free space map with final free space info */
vac_update_fsm(onerel, &fraged_pages, vacrelstats->rel_pages);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.103 2003/08/08 21:41:40 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.104 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -647,12 +647,9 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo)
resultRelInfo->ri_NumIndices = 0;
/* checks for disabled indexes */
/* fast path if no indexes */
if (!RelationGetForm(resultRelation)->relhasindex)
return;
if (IsIgnoringSystemIndexes() &&
IsSystemRelation(resultRelation))
return;
/*
* Get cached list of index OIDs
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.83 2003/08/22 20:26:43 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.84 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -964,12 +964,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate)
currentRelation = heap_open(reloid, AccessShareLock);
if (!RelationGetForm(currentRelation)->relhasindex)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("indexes of relation %u were deactivated",
reloid)));
indexstate->ss.ss_currentRelation = currentRelation;
indexstate->ss.ss_currentScanDesc = NULL; /* no heap scan here */
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.59 2003/08/04 02:40:03 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.60 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -73,6 +73,12 @@ SendSharedInvalidMessage(SharedInvalidationMessage *msg)
/*
* ReceiveSharedInvalidMessages
* Process shared-cache-invalidation messages waiting for this backend
*
* NOTE: it is entirely possible for this routine to be invoked recursively
* as a consequence of processing inside the invalFunction or resetFunction.
* Hence, we must be holding no SI resources when we call them. The only
* bad side-effect is that SIDelExpiredDataEntries might be called extra
* times on the way out of a nested call.
*/
void
ReceiveSharedInvalidMessages(
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.363 2003/09/14 00:03:32 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.364 2003/09/24 18:54:01 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
......@@ -2252,8 +2252,11 @@ PostgresMain(int argc, char *argv[], const char *username)
/*
* ignore system indexes
*
* As of PG 7.4 this is safe to allow from the client,
* since it only disables reading the system indexes,
* not writing them. Worst case consequence is slowness.
*/
if (secure) /* XXX safe to allow from client??? */
IgnoreSystemIndexes(true);
break;
......@@ -2658,7 +2661,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.363 $ $Date: 2003/09/14 00:03:32 $\n");
puts("$Revision: 1.364 $ $Date: 2003/09/24 18:54:01 $\n");
}
/*
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.206 2003/09/09 23:22:21 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.207 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -992,11 +992,9 @@ ProcessUtility(Node *parsetree,
switch (stmt->kind)
{
case OBJECT_INDEX:
CheckRelationOwnership(stmt->relation, false);
ReindexIndex(stmt->relation, stmt->force);
break;
case OBJECT_TABLE:
CheckRelationOwnership(stmt->relation, false);
ReindexTable(stmt->relation, stmt->force);
break;
case OBJECT_DATABASE:
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.90 2003/08/04 02:40:06 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.91 2003/09/24 18:54:01 tgl Exp $
*
* NOTES
* These routines allow the parser/planner/executor to perform
......@@ -436,19 +436,11 @@ static const struct cachedesc cacheinfo[] = {
}}
};
static CatCache *SysCache[
lengthof(cacheinfo)];
static CatCache *SysCache[lengthof(cacheinfo)];
static int SysCacheSize = lengthof(cacheinfo);
static bool CacheInitialized = false;
bool
IsCacheInitialized(void)
{
return CacheInitialized;
}
/*
* InitCatalogCache - initialize the caches
*
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.113 2003/08/04 04:03:10 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.114 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -51,6 +51,11 @@ static char socketLockFile[MAXPGPATH];
/* ----------------------------------------------------------------
* ignoring system indexes support stuff
*
* NOTE: "ignoring system indexes" means we do not use the system indexes
* for lookups (either in hardwired catalog accesses or in planner-generated
* plans). We do, however, still update the indexes when a catalog
* modification is made.
* ----------------------------------------------------------------
*/
......@@ -61,7 +66,7 @@ static bool isIgnoringSystemIndexes = false;
* True if ignoring system indexes.
*/
bool
IsIgnoringSystemIndexes()
IsIgnoringSystemIndexes(void)
{
return isIgnoringSystemIndexes;
}
......@@ -69,7 +74,6 @@ IsIgnoringSystemIndexes()
/*
* IgnoreSystemIndexes
* Set true or false whether PostgreSQL ignores system indexes.
*
*/
void
IgnoreSystemIndexes(bool mode)
......@@ -77,6 +81,53 @@ IgnoreSystemIndexes(bool mode)
isIgnoringSystemIndexes = mode;
}
/* ----------------------------------------------------------------
* system index reindexing support
*
* When we are busy reindexing a system index, this code provides support
* for preventing catalog lookups from using that index.
* ----------------------------------------------------------------
*/
static Oid currentlyReindexedHeap = InvalidOid;
static Oid currentlyReindexedIndex = InvalidOid;
/*
* ReindexIsProcessingHeap
* True if heap specified by OID is currently being reindexed.
*/
bool
ReindexIsProcessingHeap(Oid heapOid)
{
return heapOid == currentlyReindexedHeap;
}
/*
* ReindexIsProcessingIndex
* True if index specified by OID is currently being reindexed.
*/
bool
ReindexIsProcessingIndex(Oid indexOid)
{
return indexOid == currentlyReindexedIndex;
}
/*
* SetReindexProcessing
* Set flag that specified heap/index are being reindexed.
* Pass InvalidOid to indicate that reindexing is not active.
*/
void
SetReindexProcessing(Oid heapOid, Oid indexOid)
{
/* Args should be both, or neither, InvalidOid */
Assert((heapOid == InvalidOid) == (indexOid == InvalidOid));
/* Reindexing is not re-entrant. */
Assert(indexOid == InvalidOid || currentlyReindexedIndex == InvalidOid);
currentlyReindexedHeap = heapOid;
currentlyReindexedIndex = indexOid;
}
/* ----------------------------------------------------------------
* database path / name support stuff
* ----------------------------------------------------------------
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: index.h,v 1.52 2003/08/04 02:40:10 momjian Exp $
* $Id: index.h,v 1.53 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -51,15 +51,12 @@ extern void FormIndexDatum(IndexInfo *indexInfo,
char *nullv);
extern void UpdateStats(Oid relid, double reltuples);
extern bool IndexesAreActive(Relation heaprel);
extern void setRelhasindex(Oid relid, bool hasindex,
bool isprimary, Oid reltoastidxid);
extern void setNewRelfilenode(Relation relation);
extern bool SetReindexProcessing(bool processing);
extern bool IsReindexProcessing(void);
extern void index_build(Relation heapRelation, Relation indexRelation,
IndexInfo *indexInfo);
......@@ -69,9 +66,7 @@ extern double IndexBuildHeapScan(Relation heapRelation,
IndexBuildCallback callback,
void *callback_state);
extern bool activate_indexes_of_a_table(Relation heaprel, bool activate);
extern bool reindex_index(Oid indexId, bool force, bool inplace);
extern bool reindex_relation(Oid relid, bool force);
extern void reindex_index(Oid indexId);
extern bool reindex_relation(Oid relid);
#endif /* INDEX_H */
......@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: miscadmin.h,v 1.133 2003/08/26 15:38:25 tgl Exp $
* $Id: miscadmin.h,v 1.134 2003/09/24 18:54:01 tgl Exp $
*
* NOTES
* some of the information in this file should be moved to
......@@ -296,18 +296,17 @@ extern void InitPostgres(const char *dbname, const char *username);
extern void BaseInit(void);
/* in utils/init/miscinit.c */
extern void IgnoreSystemIndexes(bool mode);
extern bool IsIgnoringSystemIndexes(void);
extern void SetReindexProcessing(Oid heapOid, Oid indexOid);
extern bool ReindexIsProcessingHeap(Oid heapOid);
extern bool ReindexIsProcessingIndex(Oid indexOid);
extern void CreateDataDirLockFile(const char *datadir, bool amPostmaster);
extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
extern void TouchSocketLockFile(void);
extern void RecordSharedMemoryInLockFile(unsigned long id1,
unsigned long id2);
extern void ValidatePgVersion(const char *path);
extern void process_preload_libraries(char *preload_libraries_string);
/* these externs do not belong here... */
extern void IgnoreSystemIndexes(bool mode);
extern bool IsIgnoringSystemIndexes(void);
extern bool IsCacheInitialized(void);
#endif /* MISCADMIN_H */
......@@ -11,7 +11,7 @@
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* $Id: errcodes.h,v 1.5 2003/08/26 21:15:27 tgl Exp $
* $Id: errcodes.h,v 1.6 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -281,7 +281,6 @@
/* Class 55 - Object Not In Prerequisite State (class borrowed from DB2) */
#define ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE MAKE_SQLSTATE('5','5', '0','0','0')
#define ERRCODE_OBJECT_IN_USE MAKE_SQLSTATE('5','5', '0','0','6')
#define ERRCODE_INDEXES_DEACTIVATED MAKE_SQLSTATE('5','5', 'P','0','1')
#define ERRCODE_CANT_CHANGE_RUNTIME_PARAM MAKE_SQLSTATE('5','5', 'P','0','2')
/* Class 57 - Operator Intervention (class borrowed from DB2) */
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: rel.h,v 1.67 2003/08/04 02:40:15 momjian Exp $
* $Id: rel.h,v 1.68 2003/09/24 18:54:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -119,8 +119,10 @@ typedef struct RelationData
* it is possible for new-ness to be "forgotten" (eg, after CLUSTER).
*/
bool rd_istemp; /* rel uses the local buffer mgr */
bool rd_isnailed; /* rel is nailed in cache */
bool rd_indexfound; /* true if rd_indexlist is valid */
char rd_isnailed; /* rel is nailed in cache: 0 = no, 1 = yes,
* 2 = yes but possibly invalid */
char rd_indexvalid; /* state of rd_indexlist: 0 = not valid,
* 1 = valid, 2 = temporarily forced */
Form_pg_class rd_rel; /* RELATION tuple */
TupleDesc rd_att; /* tuple descriptor */
Oid rd_id; /* relation's object id */
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: relcache.h,v 1.36 2003/08/04 02:40:15 momjian Exp $
* $Id: relcache.h,v 1.37 2003/09/24 18:54:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -35,6 +35,8 @@ extern List *RelationGetIndexList(Relation relation);
extern List *RelationGetIndexExpressions(Relation relation);
extern List *RelationGetIndexPredicate(Relation relation);
extern void RelationSetIndexList(Relation relation, List *indexIds);
extern void RelationInitIndexAccessInfo(Relation relation);
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment