2000-10-13 14:06:40 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2000-10-20 13:01:21 +02:00
|
|
|
* xlogutils.c
|
2000-10-13 14:06:40 +02:00
|
|
|
*
|
2004-07-22 00:31:26 +02:00
|
|
|
* PostgreSQL transaction log manager utility routines
|
|
|
|
*
|
|
|
|
* This file contains support routines that are used by XLOG replay functions.
|
|
|
|
* None of this code is used during normal system operation.
|
|
|
|
*
|
2000-10-13 14:06:40 +02:00
|
|
|
*
|
2007-01-05 23:20:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
2000-10-13 14:06:40 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2007-05-03 01:18:03 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.50 2007/05/02 23:18:03 tgl Exp $
|
XLOG (and related) changes:
* Store two past checkpoint locations, not just one, in pg_control.
On startup, we fall back to the older checkpoint if the newer one
is unreadable. Also, a physical copy of the newest checkpoint record
is kept in pg_control for possible use in disaster recovery (ie,
complete loss of pg_xlog). Also add a version number for pg_control
itself. Remove archdir from pg_control; it ought to be a GUC
parameter, not a special case (not that it's implemented yet anyway).
* Suppress successive checkpoint records when nothing has been entered
in the WAL log since the last one. This is not so much to avoid I/O
as to make it actually useful to keep track of the last two
checkpoints. If the things are right next to each other then there's
not a lot of redundancy gained...
* Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs
on alternate bytes. Polynomial borrowed from ECMA DLT1 standard.
* Fix XLOG record length handling so that it will work at BLCKSZ = 32k.
* Change XID allocation to work more like OID allocation. (This is of
dubious necessity, but I think it's a good idea anyway.)
* Fix a number of minor bugs, such as off-by-one logic for XLOG file
wraparound at the 4 gig mark.
* Add documentation and clean up some coding infelicities; move file
format declarations out to include files where planned contrib
utilities can get at them.
* Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or
every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also
possible to force a checkpoint by sending SIGUSR1 to the postmaster
(undocumented feature...)
* Defend against kill -9 postmaster by storing shmem block's key and ID
in postmaster.pid lockfile, and checking at startup to ensure that no
processes are still connected to old shmem block (if it still exists).
* Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency
stop, for symmetry with postmaster and xlog utilities. Clean up signal
handling in bootstrap.c so that xlog utilities launched by postmaster
will react to signals better.
* Standalone bootstrap now grabs lockfile in target directory, as added
insurance against running it in parallel with live postmaster.
2001-03-13 02:17:06 +01:00
|
|
|
*
|
2000-10-13 14:06:40 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
XLOG (and related) changes:
* Store two past checkpoint locations, not just one, in pg_control.
On startup, we fall back to the older checkpoint if the newer one
is unreadable. Also, a physical copy of the newest checkpoint record
is kept in pg_control for possible use in disaster recovery (ie,
complete loss of pg_xlog). Also add a version number for pg_control
itself. Remove archdir from pg_control; it ought to be a GUC
parameter, not a special case (not that it's implemented yet anyway).
* Suppress successive checkpoint records when nothing has been entered
in the WAL log since the last one. This is not so much to avoid I/O
as to make it actually useful to keep track of the last two
checkpoints. If the things are right next to each other then there's
not a lot of redundancy gained...
* Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs
on alternate bytes. Polynomial borrowed from ECMA DLT1 standard.
* Fix XLOG record length handling so that it will work at BLCKSZ = 32k.
* Change XID allocation to work more like OID allocation. (This is of
dubious necessity, but I think it's a good idea anyway.)
* Fix a number of minor bugs, such as off-by-one logic for XLOG file
wraparound at the 4 gig mark.
* Add documentation and clean up some coding infelicities; move file
format declarations out to include files where planned contrib
utilities can get at them.
* Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or
every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also
possible to force a checkpoint by sending SIGUSR1 to the postmaster
(undocumented feature...)
* Defend against kill -9 postmaster by storing shmem block's key and ID
in postmaster.pid lockfile, and checking at startup to ensure that no
processes are still connected to old shmem block (if it still exists).
* Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency
stop, for symmetry with postmaster and xlog utilities. Clean up signal
handling in bootstrap.c so that xlog utilities launched by postmaster
will react to signals better.
* Standalone bootstrap now grabs lockfile in target directory, as added
insurance against running it in parallel with live postmaster.
2001-03-13 02:17:06 +01:00
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
#include "access/xlogutils.h"
|
2006-03-29 23:17:39 +02:00
|
|
|
#include "storage/bufpage.h"
|
2001-08-25 20:52:43 +02:00
|
|
|
#include "storage/smgr.h"
|
2001-10-05 19:28:13 +02:00
|
|
|
#include "utils/hsearch.h"
|
2000-10-13 14:06:40 +02:00
|
|
|
|
2001-08-25 20:52:43 +02:00
|
|
|
|
2006-04-14 22:27:24 +02:00
|
|
|
/*
|
|
|
|
* During XLOG replay, we may see XLOG records for incremental updates of
|
|
|
|
* pages that no longer exist, because their relation was later dropped or
|
|
|
|
* truncated. (Note: this is only possible when full_page_writes = OFF,
|
|
|
|
* since when it's ON, the first reference we see to a page should always
|
|
|
|
* be a full-page rewrite not an incremental update.) Rather than simply
|
|
|
|
* ignoring such records, we make a note of the referenced page, and then
|
|
|
|
* complain if we don't actually see a drop or truncate covering the page
|
|
|
|
* later in replay.
|
|
|
|
*/
|
|
|
|
typedef struct xl_invalid_page_key
|
|
|
|
{
|
|
|
|
RelFileNode node; /* the relation */
|
|
|
|
BlockNumber blkno; /* the page */
|
|
|
|
} xl_invalid_page_key;
|
|
|
|
|
|
|
|
typedef struct xl_invalid_page
|
|
|
|
{
|
|
|
|
xl_invalid_page_key key; /* hash key ... must be first */
|
|
|
|
bool present; /* page existed but contained zeroes */
|
|
|
|
} xl_invalid_page;
|
|
|
|
|
|
|
|
static HTAB *invalid_page_tab = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* Log a reference to an invalid page */
|
|
|
|
static void
|
|
|
|
log_invalid_page(RelFileNode node, BlockNumber blkno, bool present)
|
|
|
|
{
|
|
|
|
xl_invalid_page_key key;
|
|
|
|
xl_invalid_page *hentry;
|
|
|
|
bool found;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log references to invalid pages at DEBUG1 level. This allows some
|
|
|
|
* tracing of the cause (note the elog context mechanism will tell us
|
|
|
|
* something about the XLOG record that generated the reference).
|
|
|
|
*/
|
|
|
|
if (present)
|
|
|
|
elog(DEBUG1, "page %u of relation %u/%u/%u is uninitialized",
|
|
|
|
blkno, node.spcNode, node.dbNode, node.relNode);
|
|
|
|
else
|
|
|
|
elog(DEBUG1, "page %u of relation %u/%u/%u does not exist",
|
|
|
|
blkno, node.spcNode, node.dbNode, node.relNode);
|
|
|
|
|
|
|
|
if (invalid_page_tab == NULL)
|
|
|
|
{
|
|
|
|
/* create hash table when first needed */
|
|
|
|
HASHCTL ctl;
|
|
|
|
|
|
|
|
memset(&ctl, 0, sizeof(ctl));
|
|
|
|
ctl.keysize = sizeof(xl_invalid_page_key);
|
|
|
|
ctl.entrysize = sizeof(xl_invalid_page);
|
|
|
|
ctl.hash = tag_hash;
|
|
|
|
|
|
|
|
invalid_page_tab = hash_create("XLOG invalid-page table",
|
|
|
|
100,
|
|
|
|
&ctl,
|
|
|
|
HASH_ELEM | HASH_FUNCTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we currently assume xl_invalid_page_key contains no padding */
|
|
|
|
key.node = node;
|
|
|
|
key.blkno = blkno;
|
|
|
|
hentry = (xl_invalid_page *)
|
|
|
|
hash_search(invalid_page_tab, (void *) &key, HASH_ENTER, &found);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
/* hash_search already filled in the key */
|
|
|
|
hentry->present = present;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* repeat reference ... leave "present" as it was */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Forget any invalid pages >= minblkno, because they've been dropped */
|
|
|
|
static void
|
|
|
|
forget_invalid_pages(RelFileNode node, BlockNumber minblkno)
|
|
|
|
{
|
|
|
|
HASH_SEQ_STATUS status;
|
|
|
|
xl_invalid_page *hentry;
|
|
|
|
|
|
|
|
if (invalid_page_tab == NULL)
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
hash_seq_init(&status, invalid_page_tab);
|
|
|
|
|
|
|
|
while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
|
|
|
|
{
|
|
|
|
if (RelFileNodeEquals(hentry->key.node, node) &&
|
|
|
|
hentry->key.blkno >= minblkno)
|
|
|
|
{
|
|
|
|
elog(DEBUG2, "page %u of relation %u/%u/%u has been dropped",
|
|
|
|
hentry->key.blkno, hentry->key.node.spcNode,
|
|
|
|
hentry->key.node.dbNode, hentry->key.node.relNode);
|
|
|
|
|
|
|
|
if (hash_search(invalid_page_tab,
|
|
|
|
(void *) &hentry->key,
|
|
|
|
HASH_REMOVE, NULL) == NULL)
|
|
|
|
elog(ERROR, "hash table corrupted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Forget any invalid pages in a whole database */
|
|
|
|
static void
|
|
|
|
forget_invalid_pages_db(Oid dbid)
|
|
|
|
{
|
|
|
|
HASH_SEQ_STATUS status;
|
|
|
|
xl_invalid_page *hentry;
|
|
|
|
|
|
|
|
if (invalid_page_tab == NULL)
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
hash_seq_init(&status, invalid_page_tab);
|
|
|
|
|
|
|
|
while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
|
|
|
|
{
|
|
|
|
if (hentry->key.node.dbNode == dbid)
|
|
|
|
{
|
|
|
|
elog(DEBUG2, "page %u of relation %u/%u/%u has been dropped",
|
|
|
|
hentry->key.blkno, hentry->key.node.spcNode,
|
|
|
|
hentry->key.node.dbNode, hentry->key.node.relNode);
|
|
|
|
|
|
|
|
if (hash_search(invalid_page_tab,
|
|
|
|
(void *) &hentry->key,
|
|
|
|
HASH_REMOVE, NULL) == NULL)
|
|
|
|
elog(ERROR, "hash table corrupted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Complain about any remaining invalid-page entries */
|
|
|
|
void
|
|
|
|
XLogCheckInvalidPages(void)
|
|
|
|
{
|
|
|
|
HASH_SEQ_STATUS status;
|
|
|
|
xl_invalid_page *hentry;
|
|
|
|
bool foundone = false;
|
|
|
|
|
|
|
|
if (invalid_page_tab == NULL)
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
hash_seq_init(&status, invalid_page_tab);
|
|
|
|
|
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* Our strategy is to emit WARNING messages for all remaining entries and
|
|
|
|
* only PANIC after we've dumped all the available info.
|
2006-04-14 22:27:24 +02:00
|
|
|
*/
|
|
|
|
while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
|
|
|
|
{
|
|
|
|
if (hentry->present)
|
|
|
|
elog(WARNING, "page %u of relation %u/%u/%u was uninitialized",
|
|
|
|
hentry->key.blkno, hentry->key.node.spcNode,
|
|
|
|
hentry->key.node.dbNode, hentry->key.node.relNode);
|
|
|
|
else
|
|
|
|
elog(WARNING, "page %u of relation %u/%u/%u did not exist",
|
|
|
|
hentry->key.blkno, hentry->key.node.spcNode,
|
|
|
|
hentry->key.node.dbNode, hentry->key.node.relNode);
|
|
|
|
foundone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundone)
|
|
|
|
elog(PANIC, "WAL contains references to invalid pages");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
/*
|
2006-03-29 23:17:39 +02:00
|
|
|
* XLogReadBuffer
|
|
|
|
* Read a page during XLOG replay
|
2000-10-20 13:01:21 +02:00
|
|
|
*
|
2006-03-29 23:17:39 +02:00
|
|
|
* This is functionally comparable to ReadBuffer followed by
|
|
|
|
* LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE): you get back a pinned
|
2006-04-01 01:32:07 +02:00
|
|
|
* and locked buffer. (Getting the lock is not really necessary, since we
|
|
|
|
* expect that this is only used during single-process XLOG replay, but
|
|
|
|
* some subroutines such as MarkBufferDirty will complain if we don't.)
|
2000-10-20 13:01:21 +02:00
|
|
|
*
|
2006-03-29 23:17:39 +02:00
|
|
|
* If "init" is true then the caller intends to rewrite the page fully
|
|
|
|
* using the info in the XLOG record. In this case we will extend the
|
|
|
|
* relation if needed to make the page exist, and we will not complain about
|
2007-05-03 01:18:03 +02:00
|
|
|
* the page being "new" (all zeroes); in fact, we usually will supply a
|
|
|
|
* zeroed buffer without reading the page at all, so as to avoid unnecessary
|
|
|
|
* failure if the page is present on disk but has corrupt headers.
|
2006-03-29 23:17:39 +02:00
|
|
|
*
|
|
|
|
* If "init" is false then the caller needs the page to be valid already.
|
2006-04-14 22:27:24 +02:00
|
|
|
* If the page doesn't exist or contains zeroes, we return InvalidBuffer.
|
|
|
|
* In this case the caller should silently skip the update on this page.
|
|
|
|
* (In this situation, we expect that the page was later dropped or truncated.
|
|
|
|
* If we don't see evidence of that later in the WAL sequence, we'll complain
|
|
|
|
* at the end of WAL replay.)
|
2000-10-20 13:01:21 +02:00
|
|
|
*/
|
|
|
|
Buffer
|
2006-03-29 23:17:39 +02:00
|
|
|
XLogReadBuffer(Relation reln, BlockNumber blkno, bool init)
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
BlockNumber lastblock = RelationGetNumberOfBlocks(reln);
|
2000-10-20 13:01:21 +02:00
|
|
|
Buffer buffer;
|
|
|
|
|
2006-03-29 23:17:39 +02:00
|
|
|
Assert(blkno != P_NEW);
|
|
|
|
|
|
|
|
if (blkno < lastblock)
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
2006-03-29 23:17:39 +02:00
|
|
|
/* page exists in file */
|
2007-05-03 01:18:03 +02:00
|
|
|
if (init)
|
|
|
|
buffer = ReadOrZeroBuffer(reln, blkno);
|
|
|
|
else
|
|
|
|
buffer = ReadBuffer(reln, blkno);
|
2006-03-29 23:17:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* hm, page doesn't exist in file */
|
|
|
|
if (!init)
|
2006-04-14 22:27:24 +02:00
|
|
|
{
|
|
|
|
log_invalid_page(reln->rd_node, blkno, false);
|
|
|
|
return InvalidBuffer;
|
|
|
|
}
|
2006-03-29 23:17:39 +02:00
|
|
|
/* OK to extend the file */
|
|
|
|
/* we do this in recovery only - no rel-extension lock needed */
|
|
|
|
Assert(InRecovery);
|
2000-10-20 13:01:21 +02:00
|
|
|
buffer = InvalidBuffer;
|
2006-03-29 23:17:39 +02:00
|
|
|
while (blkno >= lastblock)
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
2006-03-29 23:17:39 +02:00
|
|
|
if (buffer != InvalidBuffer)
|
2006-04-01 01:32:07 +02:00
|
|
|
ReleaseBuffer(buffer);
|
2006-03-29 23:17:39 +02:00
|
|
|
buffer = ReadBuffer(reln, P_NEW);
|
|
|
|
lastblock++;
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
2006-03-29 23:17:39 +02:00
|
|
|
Assert(BufferGetBlockNumber(buffer) == blkno);
|
|
|
|
}
|
|
|
|
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
{
|
|
|
|
/* check that page has been initialized */
|
2006-10-04 02:30:14 +02:00
|
|
|
Page page = (Page) BufferGetPage(buffer);
|
2006-03-29 23:17:39 +02:00
|
|
|
|
|
|
|
if (PageIsNew((PageHeader) page))
|
2006-04-14 22:27:24 +02:00
|
|
|
{
|
|
|
|
UnlockReleaseBuffer(buffer);
|
|
|
|
log_invalid_page(reln->rd_node, blkno, true);
|
|
|
|
return InvalidBuffer;
|
|
|
|
}
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2006-01-11 09:43:13 +01:00
|
|
|
return buffer;
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2004-07-22 00:31:26 +02:00
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
/*
|
2004-07-22 00:31:26 +02:00
|
|
|
* Lightweight "Relation" cache --- this substitutes for the normal relcache
|
|
|
|
* during XLOG replay.
|
2000-10-20 13:01:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct XLogRelDesc
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelationData reldata;
|
|
|
|
struct XLogRelDesc *lessRecently;
|
|
|
|
struct XLogRelDesc *moreRecently;
|
2000-10-20 13:01:21 +02:00
|
|
|
} XLogRelDesc;
|
|
|
|
|
|
|
|
typedef struct XLogRelCacheEntry
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelFileNode rnode;
|
|
|
|
XLogRelDesc *rdesc;
|
2000-10-20 13:01:21 +02:00
|
|
|
} XLogRelCacheEntry;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static HTAB *_xlrelcache;
|
|
|
|
static XLogRelDesc *_xlrelarr = NULL;
|
|
|
|
static Form_pg_class _xlpgcarr = NULL;
|
|
|
|
static int _xlast = 0;
|
|
|
|
static int _xlcnt = 0;
|
|
|
|
|
|
|
|
#define _XLOG_RELCACHESIZE 512
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
_xl_init_rel_cache(void)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
HASHCTL ctl;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-11-01 00:56:36 +01:00
|
|
|
_xlcnt = _XLOG_RELCACHESIZE;
|
2000-10-20 13:01:21 +02:00
|
|
|
_xlast = 0;
|
2001-03-22 05:01:46 +01:00
|
|
|
_xlrelarr = (XLogRelDesc *) malloc(sizeof(XLogRelDesc) * _xlcnt);
|
2000-10-20 13:01:21 +02:00
|
|
|
memset(_xlrelarr, 0, sizeof(XLogRelDesc) * _xlcnt);
|
|
|
|
_xlpgcarr = (Form_pg_class) malloc(sizeof(FormData_pg_class) * _xlcnt);
|
2000-10-24 11:56:23 +02:00
|
|
|
memset(_xlpgcarr, 0, sizeof(FormData_pg_class) * _xlcnt);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-10-21 17:43:36 +02:00
|
|
|
_xlrelarr[0].moreRecently = &(_xlrelarr[0]);
|
|
|
|
_xlrelarr[0].lessRecently = &(_xlrelarr[0]);
|
|
|
|
|
2001-10-01 07:36:17 +02:00
|
|
|
memset(&ctl, 0, sizeof(ctl));
|
2000-10-20 13:01:21 +02:00
|
|
|
ctl.keysize = sizeof(RelFileNode);
|
2001-10-01 07:36:17 +02:00
|
|
|
ctl.entrysize = sizeof(XLogRelCacheEntry);
|
2000-10-20 13:01:21 +02:00
|
|
|
ctl.hash = tag_hash;
|
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
_xlrelcache = hash_create("XLOG relcache", _XLOG_RELCACHESIZE,
|
|
|
|
&ctl, HASH_ELEM | HASH_FUNCTION);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
static void
|
2001-10-05 19:28:13 +02:00
|
|
|
_xl_remove_hash_entry(XLogRelDesc *rdesc)
|
2000-10-28 18:21:00 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Form_pg_class tpgc = rdesc->reldata.rd_rel;
|
2001-10-05 19:28:13 +02:00
|
|
|
XLogRelCacheEntry *hentry;
|
2000-10-28 18:21:00 +02:00
|
|
|
|
|
|
|
rdesc->lessRecently->moreRecently = rdesc->moreRecently;
|
|
|
|
rdesc->moreRecently->lessRecently = rdesc->lessRecently;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
hentry = (XLogRelCacheEntry *) hash_search(_xlrelcache,
|
2005-10-15 04:49:52 +02:00
|
|
|
(void *) &(rdesc->reldata.rd_node), HASH_REMOVE, NULL);
|
2000-10-28 18:21:00 +02:00
|
|
|
if (hentry == NULL)
|
Commit to match discussed elog() changes. Only update is that LOG is
now just below FATAL in server_min_messages. Added more text to
highlight ordering difference between it and client_min_messages.
---------------------------------------------------------------------------
REALLYFATAL => PANIC
STOP => PANIC
New INFO level the prints to client by default
New LOG level the prints to server log by default
Cause VACUUM information to print only to the client
NOTICE => INFO where purely information messages are sent
DEBUG => LOG for purely server status messages
DEBUG removed, kept as backward compatible
DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1 added
DebugLvl removed in favor of new DEBUG[1-5] symbols
New server_min_messages GUC parameter with values:
DEBUG[5-1], INFO, NOTICE, ERROR, LOG, FATAL, PANIC
New client_min_messages GUC parameter with values:
DEBUG[5-1], LOG, INFO, NOTICE, ERROR, FATAL, PANIC
Server startup now logged with LOG instead of DEBUG
Remove debug_level GUC parameter
elog() numbers now start at 10
Add test to print error message if older elog() values are passed to elog()
Bootstrap mode now has a -d that requires an argument, like postmaster
2002-03-02 22:39:36 +01:00
|
|
|
elog(PANIC, "_xl_remove_hash_entry: file was not found in cache");
|
2000-10-28 18:21:00 +02:00
|
|
|
|
2005-01-10 21:02:24 +01:00
|
|
|
RelationCloseSmgr(&(rdesc->reldata));
|
2000-10-28 18:21:00 +02:00
|
|
|
|
|
|
|
memset(rdesc, 0, sizeof(XLogRelDesc));
|
2006-07-04 00:45:41 +02:00
|
|
|
memset(tpgc, 0, sizeof(FormData_pg_class));
|
2000-10-28 18:21:00 +02:00
|
|
|
rdesc->reldata.rd_rel = tpgc;
|
|
|
|
}
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
static XLogRelDesc *
|
2000-10-20 13:01:21 +02:00
|
|
|
_xl_new_reldesc(void)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
XLogRelDesc *res;
|
2000-11-01 00:56:36 +01:00
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
_xlast++;
|
|
|
|
if (_xlast < _xlcnt)
|
|
|
|
{
|
|
|
|
_xlrelarr[_xlast].reldata.rd_rel = &(_xlpgcarr[_xlast]);
|
2006-01-11 09:43:13 +01:00
|
|
|
return &(_xlrelarr[_xlast]);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2000-11-01 00:56:36 +01:00
|
|
|
/* reuse */
|
|
|
|
res = _xlrelarr[0].moreRecently;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
_xl_remove_hash_entry(res);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-11-01 00:56:36 +01:00
|
|
|
_xlast--;
|
2006-01-11 09:43:13 +01:00
|
|
|
return res;
|
2000-10-28 18:21:00 +02:00
|
|
|
}
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
void
|
|
|
|
XLogInitRelationCache(void)
|
|
|
|
{
|
|
|
|
_xl_init_rel_cache();
|
2006-04-14 22:27:24 +02:00
|
|
|
invalid_page_tab = NULL;
|
2000-10-28 18:21:00 +02:00
|
|
|
}
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
void
|
|
|
|
XLogCloseRelationCache(void)
|
|
|
|
{
|
2001-10-05 19:28:13 +02:00
|
|
|
HASH_SEQ_STATUS status;
|
|
|
|
XLogRelCacheEntry *hentry;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
if (!_xlrelarr)
|
|
|
|
return;
|
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
hash_seq_init(&status, _xlrelcache);
|
|
|
|
|
|
|
|
while ((hentry = (XLogRelCacheEntry *) hash_seq_search(&status)) != NULL)
|
|
|
|
_xl_remove_hash_entry(hentry->rdesc);
|
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
hash_destroy(_xlrelcache);
|
|
|
|
|
|
|
|
free(_xlrelarr);
|
|
|
|
free(_xlpgcarr);
|
|
|
|
|
|
|
|
_xlrelarr = NULL;
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
2004-02-11 23:55:26 +01:00
|
|
|
/*
|
|
|
|
* Open a relation during XLOG replay
|
2006-03-29 23:17:39 +02:00
|
|
|
*
|
|
|
|
* Note: this once had an API that allowed NULL return on failure, but it
|
|
|
|
* no longer does; any failure results in elog().
|
2004-02-11 23:55:26 +01:00
|
|
|
*/
|
2000-10-20 13:01:21 +02:00
|
|
|
Relation
|
2005-06-06 19:01:25 +02:00
|
|
|
XLogOpenRelation(RelFileNode rnode)
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
XLogRelDesc *res;
|
|
|
|
XLogRelCacheEntry *hentry;
|
|
|
|
bool found;
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
hentry = (XLogRelCacheEntry *)
|
2001-10-05 19:28:13 +02:00
|
|
|
hash_search(_xlrelcache, (void *) &rnode, HASH_FIND, NULL);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
2001-10-05 19:28:13 +02:00
|
|
|
if (hentry)
|
2000-10-20 13:01:21 +02:00
|
|
|
{
|
|
|
|
res = hentry->rdesc;
|
|
|
|
|
|
|
|
res->lessRecently->moreRecently = res->moreRecently;
|
|
|
|
res->moreRecently->lessRecently = res->lessRecently;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = _xl_new_reldesc();
|
|
|
|
|
2002-03-31 08:26:32 +02:00
|
|
|
sprintf(RelationGetRelationName(&(res->reldata)), "%u", rnode.relNode);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
res->reldata.rd_node = rnode;
|
|
|
|
|
2004-02-10 02:55:27 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* We set up the lockRelId in case anything tries to lock the dummy
|
|
|
|
* relation. Note that this is fairly bogus since relNode may be
|
|
|
|
* different from the relation's OID. It shouldn't really matter
|
|
|
|
* though, since we are presumably running by ourselves and can't have
|
|
|
|
* any lock conflicts ...
|
2004-02-10 02:55:27 +01:00
|
|
|
*/
|
2004-06-18 08:14:31 +02:00
|
|
|
res->reldata.rd_lockInfo.lockRelId.dbId = rnode.dbNode;
|
2004-02-10 02:55:27 +01:00
|
|
|
res->reldata.rd_lockInfo.lockRelId.relId = rnode.relNode;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
hentry = (XLogRelCacheEntry *)
|
2001-10-01 07:36:17 +02:00
|
|
|
hash_search(_xlrelcache, (void *) &rnode, HASH_ENTER, &found);
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
if (found)
|
2006-03-29 23:17:39 +02:00
|
|
|
elog(PANIC, "xlog relation already present on insert into cache");
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
hentry->rdesc = res;
|
|
|
|
|
2001-06-29 23:08:25 +02:00
|
|
|
res->reldata.rd_targblock = InvalidBlockNumber;
|
2005-01-10 21:02:24 +01:00
|
|
|
res->reldata.rd_smgr = NULL;
|
|
|
|
RelationOpenSmgr(&(res->reldata));
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-02-10 02:55:27 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Create the target file if it doesn't already exist. This lets us
|
|
|
|
* cope if the replay sequence contains writes to a relation that is
|
|
|
|
* later deleted. (The original coding of this routine would instead
|
|
|
|
* return NULL, causing the writes to be suppressed. But that seems
|
|
|
|
* like it risks losing valuable data if the filesystem loses an inode
|
|
|
|
* during a crash. Better to write the data until we are actually
|
|
|
|
* told to delete the file.)
|
2004-02-10 02:55:27 +01:00
|
|
|
*/
|
|
|
|
smgrcreate(res->reldata.rd_smgr, res->reldata.rd_istemp, true);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
res->moreRecently = &(_xlrelarr[0]);
|
|
|
|
res->lessRecently = _xlrelarr[0].lessRecently;
|
|
|
|
_xlrelarr[0].lessRecently = res;
|
|
|
|
res->lessRecently->moreRecently = res;
|
|
|
|
|
2006-01-11 09:43:13 +01:00
|
|
|
return &(res->reldata);
|
2000-10-20 13:01:21 +02:00
|
|
|
}
|
2004-02-11 23:55:26 +01:00
|
|
|
|
|
|
|
/*
|
2006-03-29 23:17:39 +02:00
|
|
|
* Drop a relation during XLOG replay
|
2004-02-11 23:55:26 +01:00
|
|
|
*
|
|
|
|
* This is called when the relation is about to be deleted; we need to ensure
|
|
|
|
* that there is no dangling smgr reference in the xlog relation cache.
|
|
|
|
*
|
|
|
|
* Currently, we don't bother to physically remove the relation from the
|
|
|
|
* cache, we just let it age out normally.
|
2006-04-14 22:27:24 +02:00
|
|
|
*
|
|
|
|
* This also takes care of removing any open "invalid-page" records for
|
|
|
|
* the relation.
|
2004-02-11 23:55:26 +01:00
|
|
|
*/
|
|
|
|
void
|
2006-03-29 23:17:39 +02:00
|
|
|
XLogDropRelation(RelFileNode rnode)
|
2004-02-11 23:55:26 +01:00
|
|
|
{
|
|
|
|
XLogRelCacheEntry *hentry;
|
|
|
|
|
|
|
|
hentry = (XLogRelCacheEntry *)
|
|
|
|
hash_search(_xlrelcache, (void *) &rnode, HASH_FIND, NULL);
|
|
|
|
|
2006-04-14 22:27:24 +02:00
|
|
|
if (hentry)
|
|
|
|
{
|
|
|
|
XLogRelDesc *rdesc = hentry->rdesc;
|
2004-02-11 23:55:26 +01:00
|
|
|
|
2006-04-14 22:27:24 +02:00
|
|
|
RelationCloseSmgr(&(rdesc->reldata));
|
|
|
|
}
|
2004-02-11 23:55:26 +01:00
|
|
|
|
2006-04-14 22:27:24 +02:00
|
|
|
forget_invalid_pages(rnode, 0);
|
2004-02-11 23:55:26 +01:00
|
|
|
}
|
2006-03-29 23:17:39 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop a whole database during XLOG replay
|
|
|
|
*
|
|
|
|
* As above, but for DROP DATABASE instead of dropping a single rel
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
XLogDropDatabase(Oid dbid)
|
|
|
|
{
|
|
|
|
HASH_SEQ_STATUS status;
|
|
|
|
XLogRelCacheEntry *hentry;
|
|
|
|
|
|
|
|
hash_seq_init(&status, _xlrelcache);
|
|
|
|
|
|
|
|
while ((hentry = (XLogRelCacheEntry *) hash_seq_search(&status)) != NULL)
|
|
|
|
{
|
|
|
|
XLogRelDesc *rdesc = hentry->rdesc;
|
|
|
|
|
|
|
|
if (hentry->rnode.dbNode == dbid)
|
|
|
|
RelationCloseSmgr(&(rdesc->reldata));
|
|
|
|
}
|
2006-04-14 22:27:24 +02:00
|
|
|
|
|
|
|
forget_invalid_pages_db(dbid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Truncate a relation during XLOG replay
|
|
|
|
*
|
|
|
|
* We don't need to do anything to the fake relcache, but we do need to
|
|
|
|
* clean up any open "invalid-page" records for the dropped pages.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
XLogTruncateRelation(RelFileNode rnode, BlockNumber nblocks)
|
|
|
|
{
|
|
|
|
forget_invalid_pages(rnode, nblocks);
|
2006-03-29 23:17:39 +02:00
|
|
|
}
|