Thread
-
PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-07-24T06:43:15Z
As per earlier discussion, I'm working on the hot backup issues as part of the PITR support. While I was looking at the buffer manager and the relcache/MyDb issues to figure out the best way to work this, it occurred to me that PITR will introduce a big problem with the way we handle local relations. The basic problem is that local relations (rd_myxactonly == true) are not part of a checkpoint, so there is no way to get a lower bound on the starting LSN needed to recover a local relation. In the past this did not matter, because either the local file would be (effectively) discarded during recovery because it had not yet become visible, or the file would be flushed before the transaction creating it made it visible. Now this is a problem. So I need a decision from the core team on what to do about the local buffer manager. My preference would be to forget about the local buffer manager entirely, or if not that then to allow it only for _true_ temporary data. The only alternative I can devise is to create some way for all other backends to participate in a checkpoint, perhaps using a signal. I'm not sure this can be done safely. Anyway, I'm glad the tuplesort stuff doesn't try to use relation files :-) Can the core team let me know if this is acceptable, and whether I should move ahead with changes to the buffer manager (and some other stuff) needed to avoid special treatment of rd_myxactonly relations? Also to Richard: have you guys at multera dealt with this issue already? Is there some way around this that I'm missing? Regards, John Nield Just as an example of this problem, imagine the following sequence: 1) Transaction TX1 creates a local relation LR1 which will eventually become a globally visible table. Tuples are inserted into the local relation, and logged to the WAL file. Some tuples remain in the local buffer cache and are not yet written out, although they are logged. TX1 is still in progress. 2) Backup starts, and checkpoint is called to get a minimum starting LSN (MINLSN) for the backed-up files. Only the global buffers are flushed. 3) Backup process copies LR1 into the backup directory. (postulate some way of coordinating with the local buffer manager, a problem I have not solved). 4) TX1 commits and flushes its local buffers. A dirty buffer exists whose LSN is before MINLSN. LR1 becomes globally visible. 5) Backup finishes copying all the files, including the local relations, and then flushes the log. The log files between MINLSN and the current LSN are copied to the backup directory, and backup is done. 6) Sometime later, a system administrator restores the backup and plays the logs forward starting at MINLSN. LR1 will be corrupt, because some of the log entries required for its restoration will be before MINLSN. This corruption will not be detected until something goes wrong. BTW: The problem doesn't only happen with backup! It occurs at every checkpoint as well, I just missed it until I started working on the hot backup issue. -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Bruce Momjian <pgman@candle.pha.pa.us> — 2002-08-01T21:14:04Z
J.R needs comments on this. PITR has problems because local relations aren't logged to WAL. Suggestions? --------------------------------------------------------------------------- J. R. Nield wrote: > As per earlier discussion, I'm working on the hot backup issues as part > of the PITR support. While I was looking at the buffer manager and the > relcache/MyDb issues to figure out the best way to work this, it > occurred to me that PITR will introduce a big problem with the way we > handle local relations. > > The basic problem is that local relations (rd_myxactonly == true) are > not part of a checkpoint, so there is no way to get a lower bound on the > starting LSN needed to recover a local relation. In the past this did > not matter, because either the local file would be (effectively) > discarded during recovery because it had not yet become visible, or the > file would be flushed before the transaction creating it made it > visible. Now this is a problem. > > So I need a decision from the core team on what to do about the local > buffer manager. My preference would be to forget about the local buffer > manager entirely, or if not that then to allow it only for _true_ > temporary data. The only alternative I can devise is to create some way > for all other backends to participate in a checkpoint, perhaps using a > signal. I'm not sure this can be done safely. > > Anyway, I'm glad the tuplesort stuff doesn't try to use relation files > :-) > > Can the core team let me know if this is acceptable, and whether I > should move ahead with changes to the buffer manager (and some other > stuff) needed to avoid special treatment of rd_myxactonly relations? > > Also to Richard: have you guys at multera dealt with this issue already? > Is there some way around this that I'm missing? > > > Regards, > > John Nield > > > > > Just as an example of this problem, imagine the following sequence: > > 1) Transaction TX1 creates a local relation LR1 which will eventually > become a globally visible table. Tuples are inserted into the local > relation, and logged to the WAL file. Some tuples remain in the local > buffer cache and are not yet written out, although they are logged. TX1 > is still in progress. > > 2) Backup starts, and checkpoint is called to get a minimum starting LSN > (MINLSN) for the backed-up files. Only the global buffers are flushed. > > 3) Backup process copies LR1 into the backup directory. (postulate some > way of coordinating with the local buffer manager, a problem I have not > solved). > > 4) TX1 commits and flushes its local buffers. A dirty buffer exists > whose LSN is before MINLSN. LR1 becomes globally visible. > > 5) Backup finishes copying all the files, including the local relations, > and then flushes the log. The log files between MINLSN and the current > LSN are copied to the backup directory, and backup is done. > > 6) Sometime later, a system administrator restores the backup and plays > the logs forward starting at MINLSN. LR1 will be corrupt, because some > of the log entries required for its restoration will be before MINLSN. > This corruption will not be detected until something goes wrong. > > BTW: The problem doesn't only happen with backup! It occurs at every > checkpoint as well, I just missed it until I started working on the hot > backup issue. > > -- > J. R. Nield > jrnield@usol.com > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-01T21:37:38Z
On Thu, 2002-08-01 at 17:14, Bruce Momjian wrote: > > J.R needs comments on this. PITR has problems because local relations > aren't logged to WAL. Suggestions? > I'm sorry if it wasn't clear. The issue is not that local relations aren't logged to WAL, they are. The issue is that you can't checkpoint them. That means if you need a lower bound on the LSN to recover from, then you either need to wait for transactions using them all to commit and flush their local buffers, or there needs to be a async way to tell them all to flush. I am working on a way to do this with a signal, using holdoffs around calls into the storage-manager and VFS layers to prevent re-entrant calls. The local buffer manager is simple enough that it should be possible to flush them from within a signal handler at most times, but the VFS and storage manager are not safe to re-enter from a handler. Does this sound like a good idea? -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-02T04:49:18Z
"J. R. Nield" <jrnield@usol.com> writes: > I am working on a way to do this with a signal, using holdoffs around > calls into the storage-manager and VFS layers to prevent re-entrant > calls. The local buffer manager is simple enough that it should be > possible to flush them from within a signal handler at most times, but > the VFS and storage manager are not safe to re-enter from a handler. > Does this sound like a good idea? No. What happened to "simple"? Before I'd accept anything like that, I'd rip out the local buffer manager and just do everything in the shared manager. I've never seen any proof that the local manager buys any noticeable performance gain anyway ... how many people really do anything much with a table during its first transaction of existence? regards, tom lane
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-02T13:48:40Z
Ok. This is what I wanted to hear, but I had assumed someone decided to put it in for a reason, and I wasn't going to submit a patch to pull-out the local buffer manager without clearing it first. The main area where it seems to get heavy use is during index builds, and for 'CREATE TABLE AS SELECT...'. So I will remove the local buffer manager as part of the PITR patch, unless there is further objection. On Fri, 2002-08-02 at 00:49, Tom Lane wrote: > "J. R. Nield" <jrnield@usol.com> writes: > > I am working on a way to do this with a signal, using holdoffs around > > calls into the storage-manager and VFS layers to prevent re-entrant > > calls. The local buffer manager is simple enough that it should be > > possible to flush them from within a signal handler at most times, but > > the VFS and storage manager are not safe to re-enter from a handler. > > > Does this sound like a good idea? > > No. What happened to "simple"? > > Before I'd accept anything like that, I'd rip out the local buffer > manager and just do everything in the shared manager. I've never > seen any proof that the local manager buys any noticeable performance > gain anyway ... how many people really do anything much with a table > during its first transaction of existence? > > regards, tom lane > -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-02T14:01:36Z
"J. R. Nield" <jrnield@usol.com> writes: > Ok. This is what I wanted to hear, but I had assumed someone decided to > put it in for a reason, and I wasn't going to submit a patch to pull-out > the local buffer manager without clearing it first. > The main area where it seems to get heavy use is during index builds, Yeah. I do not think it really saves any I/O: unless you abort your index build, the data is eventually going to end up on disk anyway. What it saves is contention for shared buffers (the overhead of acquiring BufMgrLock, for example). Just out of curiosity, though, what does it matter? On re-reading your message I think you are dealing with a non problem, or at least the wrong problem. Local relations do not need to be checkpointed, because by definition they were created by a transaction that hasn't committed yet. They must be, and are, checkpointed to disk before the transaction commits; but up till that time, if you have a crash then the entire relation should just go away. That mechanism is there already --- perhaps it needs a few tweaks for PITR but I do not see any need for cross-backend flush commands for local relations. regards, tom lane
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-02T16:26:52Z
On Fri, 2002-08-02 at 10:01, Tom Lane wrote: > > Just out of curiosity, though, what does it matter? On re-reading your > message I think you are dealing with a non problem, or at least the > wrong problem. Local relations do not need to be checkpointed, because > by definition they were created by a transaction that hasn't committed > yet. They must be, and are, checkpointed to disk before the transaction > commits; but up till that time, if you have a crash then the entire > relation should just go away. What happens when we have a local file that is created before the backup, and it becomes global during the backup? In order to copy this file, I either need: 1) A copy of all its blocks at the time backup started (or later), plus all log records between then and the end of the backup. OR 2) All the log records from the time the local file was created until the end of the backup. In the case of an idle uncommitted transaction that suddenly commits during backup, case 2 might be very far back in the log file. In fact, the log file might be archived to tape by then. So I must do case 1, and checkpoint the local relations. This brings up the question: why do I need to bother backing up files that were local before the backup started, but became global during the backup. We already know that for the backup to be consistent after we restore it, we must play the logs forward to the completion of the backup to repair our "fuzzy copies" of the database files. Since the transaction that makes the local-file into a global one has committed during our backup, its log entries will be played forward as well. What would happen if a transaction with a local relation commits during backup, and there are log entries inserting the catalog tuples into pg_class. Should I not apply those on restore? How do I know? > > That mechanism is there already --- perhaps it needs a few tweaks for > PITR but I do not see any need for cross-backend flush commands for > local relations. > This problem is subtle, and I'm maybe having difficulty explaining it properly. Do you understand the issue I'm raising? Have I made some kind of blunder, so that this is really not a problem? -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Richard Tucker <richt@multera.com> — 2002-08-02T17:50:19Z
pg_copy does not handle "local relations" as you would suspect. To find the tables and indexes to backup the backend in processing the "ALTER SYSTEM BACKUP" statement reads the pg_class table. Any tables in the process of coming into existence of course are not visible. If somehow they were then the backup would backup up their contents. Any in private memory changes would be captured during crash recovery on the copy of the database. So the question is: is it possible to read the names of the "local relations" from the pg_class table even though there creation has not yet been committed? -regards richt > -----Original Message----- > From: J. R. Nield [mailto:jrnield@usol.com] > Sent: Friday, August 02, 2002 12:27 PM > To: Tom Lane > Cc: Bruce Momjian; Richard Tucker; PostgreSQL Hacker > Subject: Re: [HACKERS] PITR, checkpoint, and local relations > > > On Fri, 2002-08-02 at 10:01, Tom Lane wrote: > > > > Just out of curiosity, though, what does it matter? On re-reading your > > message I think you are dealing with a non problem, or at least the > > wrong problem. Local relations do not need to be checkpointed, because > > by definition they were created by a transaction that hasn't committed > > yet. They must be, and are, checkpointed to disk before the transaction > > commits; but up till that time, if you have a crash then the entire > > relation should just go away. > > What happens when we have a local file that is created before the > backup, and it becomes global during the backup? > > In order to copy this file, I either need: > > 1) A copy of all its blocks at the time backup started (or later), plus > all log records between then and the end of the backup. > > OR > > 2) All the log records from the time the local file was created until > the end of the backup. > > In the case of an idle uncommitted transaction that suddenly commits > during backup, case 2 might be very far back in the log file. In fact, > the log file might be archived to tape by then. > > So I must do case 1, and checkpoint the local relations. > > > This brings up the question: why do I need to bother backing up files > that were local before the backup started, but became global during the > backup. > > We already know that for the backup to be consistent after we restore > it, we must play the logs forward to the completion of the backup to > repair our "fuzzy copies" of the database files. Since the transaction > that makes the local-file into a global one has committed during our > backup, its log entries will be played forward as well. > > What would happen if a transaction with a local relation commits during > backup, and there are log entries inserting the catalog tuples into > pg_class. Should I not apply those on restore? How do I know? > > > > > That mechanism is there already --- perhaps it needs a few tweaks for > > PITR but I do not see any need for cross-backend flush commands for > > local relations. > > > > This problem is subtle, and I'm maybe having difficulty explaining it > properly. Do you understand the issue I'm raising? Have I made some kind > of blunder, so that this is really not a problem? > > -- > J. R. Nield > jrnield@usol.com > > > >
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-02T19:05:10Z
"J. R. Nield" <jrnield@usol.com> writes: > What would happen if a transaction with a local relation commits during > backup, and there are log entries inserting the catalog tuples into > pg_class. Should I not apply those on restore? How do I know? This is certainly a non-problem. You see a WAL log entry, you apply it. Whether the transaction actually commits later is not your concern (at least not at that point). > This problem is subtle, and I'm maybe having difficulty explaining it > properly. Do you understand the issue I'm raising? Have I made some kind > of blunder, so that this is really not a problem? After thinking more, I think you are right, but you didn't explain it well. The problem is not really relevant to PITR at all, but is a hole in the initial design of WAL. Consider transaction starts transaction creates local rel transaction writes in local rel... CHECKPOINT transaction writes in local rel... CHECKPOINT transaction writes in local rel... transaction flushes local rel pages to disk transaction commits system crash We'll try to replay the log from the latest checkpoint. This works only if all the local-rel page flushes actually made it to disk, otherwise the updates of the local rel that happened before the last checkpoint may be lost. (I think there is still an fsync in local-rel commit to ensure the flushes happen, but it's sure messy to do it that way.) We could possibly fix this by logging the local-rel-flush page writes themselves in the WAL log, but that'd probably more than ruin the efficiency advantage of the local bufmgr. So I'm back to the idea that removing it is the way to go. Certainly that would provide nontrivial simplifications in a number of places (no tests on local vs global buffer anymore, no special cases for local rel commit, etc). Might be useful to temporarily dike it out and see what the penalty for building a large index is. regards, tom lane
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-02T19:27:04Z
On Fri, 2002-08-02 at 13:50, Richard Tucker wrote: > pg_copy does not handle "local relations" as you would suspect. To find the > tables and indexes to backup the backend in processing the "ALTER SYSTEM > BACKUP" statement reads the pg_class table. Any tables in the process of > coming into existence of course are not visible. If somehow they were then > the backup would backup up their contents. Any in private memory changes > would be captured during crash recovery on the copy of the database. So the > question is: is it possible to read the names of the "local relations" from > the pg_class table even though there creation has not yet been committed? > -regards > richt > No, not really. At least not a consistent view. The way to do this is using the filesystem to discover the relfilnodes, and there are a couple of ways to deal with the problem of files being pulled out from under you, but you have to be careful about what the buffer manager does when a file gets dropped. The predicate for files we MUST (fuzzy) copy is: File exists at start of backup && File exists at end of backup Any other file, while it may be copied, doesn't need to be in the backup because either it will be created and rebuilt during play-forward recovery, or it will be deleted during play-forward recovery, or both, assuming those operations are logged. They really must be logged to do what we want to do. Also, you can't use the normal relation_open stuff, because local relations will not have a catalog entry, and it looks like there are catcache/sinval issues that I haven't completely covered. So you've got to do 'blind reads' through the buffer manager, which involves a minor extension to the buffer manager to support this if local relations go through the shared buffers, or coordinating with the local buffer manager if they continue to work as they do now, which involves major changes. We also have to checkpoint at the start, and flush the log at the end. -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-02T20:01:40Z
"J. R. Nield" <jrnield@usol.com> writes: > The predicate for files we MUST (fuzzy) copy is: > File exists at start of backup && File exists at end of backup Right, which seems to me to negate all these claims about needing a (horribly messy) way to read uncommitted system catalog entries, do blind reads, etc. What's wrong with just exec'ing tar after having done a checkpoint? (In particular, I *strongly* object to using the buffer manager at all for reading files for backup. That's pretty much guaranteed to blow out buffer cache. Use plain OS-level file reads. An OS directory search will do fine for finding what you need to read, too.) regards, tom lane
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-02T20:45:10Z
On Fri, 2002-08-02 at 16:01, Tom Lane wrote: > "J. R. Nield" <jrnield@usol.com> writes: > > The predicate for files we MUST (fuzzy) copy is: > > File exists at start of backup && File exists at end of backup > > Right, which seems to me to negate all these claims about needing a > (horribly messy) way to read uncommitted system catalog entries, do > blind reads, etc. What's wrong with just exec'ing tar after having > done a checkpoint? > There is no need to read uncommitted system catalog entries. Just take a snapshot of the directory to get the OID's. You don't care whether the get deleted before you get to them, because the log will take care of that. > (In particular, I *strongly* object to using the buffer manager at all > for reading files for backup. That's pretty much guaranteed to blow out > buffer cache. Use plain OS-level file reads. An OS directory search > will do fine for finding what you need to read, too.) How do you get atomic block copies otherwise? > > regards, tom lane > -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Richard Tucker <richt@multera.com> — 2002-08-02T21:20:25Z
> -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us] > Sent: Friday, August 02, 2002 4:02 PM > To: J. R. Nield > Cc: Richard Tucker; Bruce Momjian; PostgreSQL Hacker > Subject: Re: [HACKERS] PITR, checkpoint, and local relations > > > "J. R. Nield" <jrnield@usol.com> writes: > > The predicate for files we MUST (fuzzy) copy is: > > File exists at start of backup && File exists at end of backup > > Right, which seems to me to negate all these claims about needing a > (horribly messy) way to read uncommitted system catalog entries, do > blind reads, etc. What's wrong with just exec'ing tar after having > done a checkpoint? You do need to make sure to backup the pg_xlog directory last and you need to make sure no wal file gets reused while backing up everything else. > > (In particular, I *strongly* object to using the buffer manager at all > for reading files for backup. That's pretty much guaranteed to blow out > buffer cache. Use plain OS-level file reads. An OS directory search > will do fine for finding what you need to read, too.) > > regards, tom lane >
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-02T21:25:28Z
"J. R. Nield" <jrnield@usol.com> writes: >> (In particular, I *strongly* object to using the buffer manager at all >> for reading files for backup. That's pretty much guaranteed to blow out >> buffer cache. Use plain OS-level file reads. An OS directory search >> will do fine for finding what you need to read, too.) > How do you get atomic block copies otherwise? Eh? The kernel does that for you, as long as you're reading the same-size blocks that the backends are writing, no? regards, tom lane
-
Re: PITR, checkpoint, and local relations
Richard Tucker <richt@multera.com> — 2002-08-02T21:30:26Z
> -----Original Message----- > From: pgsql-hackers-owner@postgresql.org > [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Tom Lane > Sent: Friday, August 02, 2002 5:25 PM > To: J. R. Nield > Cc: Richard Tucker; Bruce Momjian; PostgreSQL Hacker > Subject: Re: [HACKERS] PITR, checkpoint, and local relations > > > "J. R. Nield" <jrnield@usol.com> writes: > >> (In particular, I *strongly* object to using the buffer manager at all > >> for reading files for backup. That's pretty much guaranteed > to blow out > >> buffer cache. Use plain OS-level file reads. An OS directory search > >> will do fine for finding what you need to read, too.) > > > How do you get atomic block copies otherwise? > > Eh? The kernel does that for you, as long as you're reading the > same-size blocks that the backends are writing, no? If the OS block size is 4k and the PostgreSQL block size is 8k do we know for sure that the write call does not break this into two 4k writes to the OS buffer cache? > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >
-
Re: PITR, checkpoint, and local relations
Christopher Kings-Lynne <chriskl@familyhealth.com.au> — 2002-08-03T10:13:38Z
> The main area where it seems to get heavy use is during index builds, > and for 'CREATE TABLE AS SELECT...'. > > So I will remove the local buffer manager as part of the PITR patch, > unless there is further objection. Would someone mind filling me in as to what the local bugger manager is and how it is different (and not useful) compared to the shared buffer manager? Chris
-
Re: PITR, checkpoint, and local relations
Bruce Momjian <pgman@candle.pha.pa.us> — 2002-08-04T00:36:13Z
Christopher Kings-Lynne wrote: > > The main area where it seems to get heavy use is during index builds, > > and for 'CREATE TABLE AS SELECT...'. > > > > So I will remove the local buffer manager as part of the PITR patch, > > unless there is further objection. > > Would someone mind filling me in as to what the local bugger manager is and > how it is different (and not useful) compared to the shared buffer manager? Sure. I think I can handle that. When you create a table in a transaction, there isn't any committed state to the table yet, so any table modifications are kept in a local buffer, which is local memory to the backend(?). No one needs to see it because it isn't visible to anyone yet. Same for indexes. Anyway, the WAL activity doesn't handle local buffers the same as shared buffers because there is no crisis if the system crashes. There is debate on whether the local buffers are even valuable considering the headache they cause in other parts of the system. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-04T02:01:12Z
Bruce Momjian <pgman@candle.pha.pa.us> writes: > There is debate on whether the local buffers are even valuable > considering the headache they cause in other parts of the system. More specifically, the issue is that when (if) you commit, the contents of the new table now have to be pushed out to shared storage. This is moderately annoying in itself (among other things, it implies fsync'ing those tables before commit). But the real reason it comes up now is that the proposed PITR scheme can't cope gracefully with tables that are suddenly there but weren't participating in checkpoints before. It looks to me like we should stop using local buffers for ordinary tables that happen to be in their first transaction of existence. But, per Vadim's suggestion, we shouldn't abandon the local buffer manager altogether. What we could and should use it for is TEMP tables, which have no need to be checkpointed or WAL-logged or fsync'd or accessible to other backends *ever*. Also, a temp table can leave blocks in local buffers across transactions, which makes local buffers considerably more useful than they are now. If temp tables didn't use the shared bufmgr nor did updates to them get WAL-logged, they'd be noticeably more efficient than plain tables, which IMHO would be a Good Thing. Such tables would be essentially invisible to WAL and PITR (at least their contents would be --- I assume we'd still log file creation and deletion). But I can't see anything wrong with that. In short, the proposal runs something like this: * Regular tables that happen to be in their first transaction of existence are not treated differently from any other regular table so far as buffer management or WAL or PITR go. (rd_myxactonly either goes away or is used for much less than it is now.) * TEMP tables use the local buffer manager for their entire existence. (This probably means adding an "rd_istemp" flag to relcache entries, but I can't see anything wrong with that.) * Local bufmgr semantics are twiddled to reflect this reality --- in particular, data in local buffers can be held across transactions, there is no end-of-transaction write (much less fsync). A TEMP table that isn't too large might never touch disk at all. * Data operations in TEMP tables do not get WAL-logged, nor do we WAL-log page images of local-buffer pages. These changes seem very attractive to me even without regard for making the world safer for PITR. I'm willing to volunteer to make them happen, if there are no objections. regards, tom lane
-
Re: PITR, checkpoint, and local relations
Bruce Momjian <pgman@candle.pha.pa.us> — 2002-08-04T02:52:35Z
Sounds like a win all around; make PITR easier and temp tables faster. --------------------------------------------------------------------------- Tom Lane wrote: > Bruce Momjian <pgman@candle.pha.pa.us> writes: > > There is debate on whether the local buffers are even valuable > > considering the headache they cause in other parts of the system. > > More specifically, the issue is that when (if) you commit, the contents > of the new table now have to be pushed out to shared storage. This is > moderately annoying in itself (among other things, it implies fsync'ing > those tables before commit). But the real reason it comes up now is > that the proposed PITR scheme can't cope gracefully with tables that > are suddenly there but weren't participating in checkpoints before. > > It looks to me like we should stop using local buffers for ordinary > tables that happen to be in their first transaction of existence. > But, per Vadim's suggestion, we shouldn't abandon the local buffer > manager altogether. What we could and should use it for is TEMP tables, > which have no need to be checkpointed or WAL-logged or fsync'd or > accessible to other backends *ever*. Also, a temp table can leave > blocks in local buffers across transactions, which makes local buffers > considerably more useful than they are now. > > If temp tables didn't use the shared bufmgr nor did updates to them get > WAL-logged, they'd be noticeably more efficient than plain tables, which > IMHO would be a Good Thing. Such tables would be essentially invisible > to WAL and PITR (at least their contents would be --- I assume we'd > still log file creation and deletion). But I can't see anything wrong > with that. > > In short, the proposal runs something like this: > > * Regular tables that happen to be in their first transaction of > existence are not treated differently from any other regular table so > far as buffer management or WAL or PITR go. (rd_myxactonly either goes > away or is used for much less than it is now.) > > * TEMP tables use the local buffer manager for their entire existence. > (This probably means adding an "rd_istemp" flag to relcache entries, but > I can't see anything wrong with that.) > > * Local bufmgr semantics are twiddled to reflect this reality --- in > particular, data in local buffers can be held across transactions, there > is no end-of-transaction write (much less fsync). A TEMP table that > isn't too large might never touch disk at all. > > * Data operations in TEMP tables do not get WAL-logged, nor do we > WAL-log page images of local-buffer pages. > > > These changes seem very attractive to me even without regard for making > the world safer for PITR. I'm willing to volunteer to make them happen, > if there are no objections. > > regards, tom lane > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
-
Re: PITR, checkpoint, and local relations
Greg Copeland <greg@copelandconsulting.net> — 2002-08-05T04:21:38Z
On Sat, 2002-08-03 at 21:01, Tom Lane wrote: > * Local bufmgr semantics are twiddled to reflect this reality --- in > particular, data in local buffers can be held across transactions, there > is no end-of-transaction write (much less fsync). A TEMP table that > isn't too large might never touch disk at all. Curious. Is there currently such a criteria? What exactly constitutes "too large"? Greg
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-05T13:41:04Z
Greg Copeland <greg@copelandconsulting.net> writes: > On Sat, 2002-08-03 at 21:01, Tom Lane wrote: >> * Local bufmgr semantics are twiddled to reflect this reality --- in >> particular, data in local buffers can be held across transactions, there >> is no end-of-transaction write (much less fsync). A TEMP table that >> isn't too large might never touch disk at all. > Curious. Is there currently such a criteria? What exactly constitutes > "too large"? "too large" means "doesn't fit in the local buffer set". At the moment the maximum number of local buffers seems to be frozen at 64. I was thinking of exposing that as a configuration parameter while we're at it. regards, tom lane
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-05T16:57:58Z
This is great Tom. I will try to get what I have to you, Vadim, and other interested parties tonight (Mon), assuming none of my tests fail and reveal major bugs. It will do most of the important stuff except your changes to the local buffer manager. I just have a few more minor tweaks, and I would like to test it a little first. On your advice I have made it use direct OS calls to copy the files, using BLCKSZ aligned read() requests, instead of going through the buffer manager for reads. I can think more about the correctness of this later, since the rest of the code doesn't depend on which method is used. To Richard Tucker: I think duplicating the WAL files the way you plan is not the way I want to do it. I'd rather have a log archiving system be used for this. One thing that does need to be done is an interactive recovery mode, and as soon as I finish getting my current work out for review I'd be glad to have you write it if you want. You'll need to see this in order to interface properly. Regards, John Nield On Sat, 2002-08-03 at 22:52, Bruce Momjian wrote: > > Sounds like a win all around; make PITR easier and temp tables faster. > > > --------------------------------------------------------------------------- > > Tom Lane wrote: > > These changes seem very attractive to me even without regard for making > > the world safer for PITR. I'm willing to volunteer to make them happen, > > if there are no objections. > > > > regards, tom lane > > > > -- > Bruce Momjian | http://candle.pha.pa.us > pgman@candle.pha.pa.us | (610) 853-3000 > + If your life is a hard drive, | 830 Blythe Avenue > + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 > -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-06T02:46:05Z
I said: > In short, the proposal runs something like this: > * Regular tables that happen to be in their first transaction of > existence are not treated differently from any other regular table so > far as buffer management or WAL or PITR go. (rd_myxactonly either goes > away or is used for much less than it is now.) > * TEMP tables use the local buffer manager for their entire existence. > (This probably means adding an "rd_istemp" flag to relcache entries, but > I can't see anything wrong with that.) > * Local bufmgr semantics are twiddled to reflect this reality --- in > particular, data in local buffers can be held across transactions, there > is no end-of-transaction write (much less fsync). A TEMP table that > isn't too large might never touch disk at all. > * Data operations in TEMP tables do not get WAL-logged, nor do we > WAL-log page images of local-buffer pages. I've committed changes to implement these ideas. One thing that proved interesting was that transactions that only made changes in existing TEMP tables failed to commit --- RecordTransactionCommit thought it didn't need to do anything, because no WAL entries had been made! This was fixed by introducing another flag that gets set when we skip making a WAL record because we're working in a TEMP relation. I have not done anything about exporting NLocBuffer as a GUC parameter. The algorithms in localbuf.c are, um, pretty sucky, and would run very slowly if NLocBuffer were large. It'd make sense to install a hash index table similar to the one used for shared buffers, and then we could allow people to set NLocBuffer as large as their system can stand. I figured that was a task for another day, however. regards, tom lane
-
Re: PITR, checkpoint, and local relations
Richard Tucker <richt@multera.com> — 2002-08-07T15:52:01Z
> -----Original Message----- > From: J. R. Nield [mailto:jrnield@usol.com] > Sent: Monday, August 05, 2002 12:58 PM > To: Bruce Momjian > Cc: Tom Lane; Christopher Kings-Lynne; Richard Tucker; PostgreSQL Hacker > Subject: Re: [HACKERS] PITR, checkpoint, and local relations > > > This is great Tom. I will try to get what I have to you, Vadim, and > other interested parties tonight (Mon), assuming none of my tests fail > and reveal major bugs. It will do most of the important stuff except > your changes to the local buffer manager. I just have a few more minor > tweaks, and I would like to test it a little first. > > On your advice I have made it use direct OS calls to copy the files, > using BLCKSZ aligned read() requests, instead of going through the > buffer manager for reads. I can think more about the correctness of this > later, since the rest of the code doesn't depend on which method is > used. > > To Richard Tucker: I think duplicating the WAL files the way you plan is > not the way I want to do it. I'd rather have a log archiving system be > used for this. One thing that does need to be done is an interactive > recovery mode, and as soon as I finish getting my current work out for > review I'd be glad to have you write it if you want. You'll need to see > this in order to interface properly. If you don't duplicate(mirror) the log then in the event you need to restore a database with roll forward recovery won't the restored database be missing on average 1/2 a log segments worth of changes? > > Regards, > > John Nield > > On Sat, 2002-08-03 at 22:52, Bruce Momjian wrote: > > > > Sounds like a win all around; make PITR easier and temp tables faster. > > > > > > > ------------------------------------------------------------------ > --------- > > > > Tom Lane wrote: > > > These changes seem very attractive to me even without regard > for making > > > the world safer for PITR. I'm willing to volunteer to make > them happen, > > > if there are no objections. > > > > > > regards, tom lane > > > > > > > -- > > Bruce Momjian | http://candle.pha.pa.us > > pgman@candle.pha.pa.us | (610) 853-3000 > > + If your life is a hard drive, | 830 Blythe Avenue > > + Christ can be your backup. | Drexel Hill, > Pennsylvania 19026 > > > -- > J. R. Nield > jrnield@usol.com > > >
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-08T03:31:35Z
On Wed, 2002-08-07 at 11:52, Richard Tucker wrote: > > > If you don't duplicate(mirror) the log then in the event you need to restore > a database with roll forward recovery won't the restored database be missing > on average 1/2 a log segments worth of changes? > The xlog code must allow us to force an advance to the next log file, and truncate the archived file when it's copied so as not to waste space. This also prevents the sysadmin from confusing two logfiles with the same name and different data. This complicates both the recovery logic and XLogInsert, and I'm trying to kill the "last" latent bug in that feature now. Hopefully I can even convince myself that the code is correct and covers all the cases. As a side effect, the refactoring of XLogInsert makes it easy to add a special record as the first XLogRecord of each file. This can contain information useful to the system administrator, like what database installation the file came from. Since it's at a fixed offset after the page header, external tools can read it in a simple way. -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-08T03:41:17Z
"J. R. Nield" <jrnield@usol.com> writes: > The xlog code must allow us to force an advance to the next log file, > and truncate the archived file when it's copied so as not to waste > space. Uh, why? Why not just force a checkpoint and remember the exact location of the checkpoint within the current log file? When and if you roll back to a prior checkpoint, you'd want to start the system running forward with a new xlog file, I think (compare what pg_resetxlog does). But it doesn't follow that you MUST force an xlog file boundary simply because you're taking a backup. > This complicates both the recovery logic and XLogInsert, and I'm trying > to kill the "last" latent bug in that feature now. Indeed. How about keeping it simple, instead? regards, tom lane
-
Re: PITR, checkpoint, and local relations
Vadim Mikheev <vmikheev@sectorbase.com> — 2002-08-08T04:58:19Z
> > The xlog code must allow us to force an advance to the next log file, > > and truncate the archived file when it's copied so as not to waste > > space. > > Uh, why? Why not just force a checkpoint and remember the exact > location of the checkpoint within the current log file? Yes, why not just save pg_control' content with new checkpoint position in it? Didn't we agree (or at least I don't remember objections to Tom' suggestion) that backup will not save log files at all and that this will be task of log archiving procedure? Even if we are going to reconsider this approach, I would just save required portion of log at *this moment* and do that space optimization *later*. Vadim
-
Re: PITR, checkpoint, and local relations
J.R. Nield <jrnield@usol.com> — 2002-08-09T01:55:25Z
On Wed, 2002-08-07 at 23:41, Tom Lane wrote: > "J. R. Nield" <jrnield@usol.com> writes: > > The xlog code must allow us to force an advance to the next log file, > > and truncate the archived file when it's copied so as not to waste > > space. > > Uh, why? Why not just force a checkpoint and remember the exact > location of the checkpoint within the current log file? If I do a backup with PITR and save it to tape, I need to be able to restore it even if my machine is destroyed in a fire, and all the logs since the end of a backup are destroyed. If we don't allow the user to force a log advance, how will he do this? I don't want to copy the log file, and then have the original be written to later, because it will become confusing as to which log file to use. Is the complexity really that big of a problem with this? > > When and if you roll back to a prior checkpoint, you'd want to start the > system running forward with a new xlog file, I think (compare what > pg_resetxlog does). But it doesn't follow that you MUST force an xlog > file boundary simply because you're taking a backup. > > > This complicates both the recovery logic and XLogInsert, and I'm trying > > to kill the "last" latent bug in that feature now. > > Indeed. How about keeping it simple, instead? > > regards, tom lane > -- J. R. Nield jrnield@usol.com
-
Re: PITR, checkpoint, and local relations
Tom Lane <tgl@sss.pgh.pa.us> — 2002-08-09T03:59:00Z
"J. R. Nield" <jrnield@usol.com> writes: >> Uh, why? Why not just force a checkpoint and remember the exact >> location of the checkpoint within the current log file? > If I do a backup with PITR and save it to tape, I need to be able to > restore it even if my machine is destroyed in a fire, and all the logs > since the end of a backup are destroyed. And for your next trick, restore it even if the backup tape itself is destroyed. C'mon, be a little reasonable here. The backups and the log archive tapes are *both* critical data in any realistic view of the world. > Is the complexity really that big of a problem with this? Yes, it is. Didn't you just admit to struggling with bugs introduced by exactly this complexity?? I don't care *how* spiffy the backup scheme is, if when push comes to shove my backup doesn't restore because there was a software bug in the backup scheme. In this context there simply is not any virtue greater than "simple and reliable". regards, tom lane
-
Re: PITR, checkpoint, and local relations
Bruce Momjian <pgman@candle.pha.pa.us> — 2002-08-10T01:27:16Z
Tom Lane wrote: > "J. R. Nield" <jrnield@usol.com> writes: > >> Uh, why? Why not just force a checkpoint and remember the exact > >> location of the checkpoint within the current log file? > > > If I do a backup with PITR and save it to tape, I need to be able to > > restore it even if my machine is destroyed in a fire, and all the logs > > since the end of a backup are destroyed. > > And for your next trick, restore it even if the backup tape itself is > destroyed. C'mon, be a little reasonable here. The backups and the > log archive tapes are *both* critical data in any realistic view of > the world. Tom, just because he doesn't agree with you doesn't mean he is unreasonable. I think it is an admirable goal to allow the PITR backup to restore a consistent copy of the database _without_ needing the logs. In fact, I consider something that _needs_ the logs to restore to a consistent state to be broken. If you are doing offsite backup, which people should be doing, requiring the log tape for restore means you have to recycle the log tape _after_ the PITR backup, and to restore to a point in the future, you need two log tapes, one that was done during the backup, and another current. If you can restore the PITR backup without a log tape, you can take just the PITR backup tape off site _and_ you can recyle the log tape _before_ the PITR backup, meaning you only need one tape for a restore to a point in the future. I think there are good reasons to have the PITR backp be restorable on its own, if possible. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073