|
21 | 21 | * heap_multi_insert - insert multiple tuples into a relation
|
22 | 22 | * heap_delete - delete a tuple from a relation
|
23 | 23 | * heap_update - replace a tuple in a relation with another tuple
|
| 24 | + * heap_sync - sync heap, for when no WAL has been written |
24 | 25 | *
|
25 | 26 | * NOTES
|
26 | 27 | * This file contains the heap_ routines which implement
|
@@ -1938,7 +1939,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
|
1938 | 1939 | MarkBufferDirty(buffer);
|
1939 | 1940 |
|
1940 | 1941 | /* XLOG stuff */
|
1941 |
| - if (RelationNeedsWAL(relation)) |
| 1942 | + if (!(options & HEAP_INSERT_SKIP_WAL) && RelationNeedsWAL(relation)) |
1942 | 1943 | {
|
1943 | 1944 | xl_heap_insert xlrec;
|
1944 | 1945 | xl_heap_header xlhdr;
|
@@ -2121,7 +2122,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
|
2121 | 2122 | /* currently not needed (thus unsupported) for heap_multi_insert() */
|
2122 | 2123 | AssertArg(!(options & HEAP_INSERT_NO_LOGICAL));
|
2123 | 2124 |
|
2124 |
| - needwal = RelationNeedsWAL(relation); |
| 2125 | + needwal = !(options & HEAP_INSERT_SKIP_WAL) && RelationNeedsWAL(relation); |
2125 | 2126 | saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
|
2126 | 2127 | HEAP_DEFAULT_FILLFACTOR);
|
2127 | 2128 |
|
@@ -8919,6 +8920,46 @@ heap2_redo(XLogReaderState *record)
|
8919 | 8920 | }
|
8920 | 8921 | }
|
8921 | 8922 |
|
| 8923 | +/* |
| 8924 | + * heap_sync - sync a heap, for use when no WAL has been written |
| 8925 | + * |
| 8926 | + * This forces the heap contents (including TOAST heap if any) down to disk. |
| 8927 | + * If we skipped using WAL, and WAL is otherwise needed, we must force the |
| 8928 | + * relation down to disk before it's safe to commit the transaction. This |
| 8929 | + * requires writing out any dirty buffers and then doing a forced fsync. |
| 8930 | + * |
| 8931 | + * Indexes are not touched. (Currently, index operations associated with |
| 8932 | + * the commands that use this are WAL-logged and so do not need fsync. |
| 8933 | + * That behavior might change someday, but in any case it's likely that |
| 8934 | + * any fsync decisions required would be per-index and hence not appropriate |
| 8935 | + * to be done here.) |
| 8936 | + */ |
| 8937 | +void |
| 8938 | +heap_sync(Relation rel) |
| 8939 | +{ |
| 8940 | + /* non-WAL-logged tables never need fsync */ |
| 8941 | + if (!RelationNeedsWAL(rel)) |
| 8942 | + return; |
| 8943 | + |
| 8944 | + /* main heap */ |
| 8945 | + FlushRelationBuffers(rel); |
| 8946 | + /* FlushRelationBuffers will have opened rd_smgr */ |
| 8947 | + smgrimmedsync(rel->rd_smgr, MAIN_FORKNUM); |
| 8948 | + |
| 8949 | + /* FSM is not critical, don't bother syncing it */ |
| 8950 | + |
| 8951 | + /* toast heap, if any */ |
| 8952 | + if (OidIsValid(rel->rd_rel->reltoastrelid)) |
| 8953 | + { |
| 8954 | + Relation toastrel; |
| 8955 | + |
| 8956 | + toastrel = table_open(rel->rd_rel->reltoastrelid, AccessShareLock); |
| 8957 | + FlushRelationBuffers(toastrel); |
| 8958 | + smgrimmedsync(toastrel->rd_smgr, MAIN_FORKNUM); |
| 8959 | + table_close(toastrel, AccessShareLock); |
| 8960 | + } |
| 8961 | +} |
| 8962 | + |
8922 | 8963 | /*
|
8923 | 8964 | * Mask a heap page before performing consistency checks on it.
|
8924 | 8965 | */
|
|
0 commit comments