1 /*-------------------------------------------------------------------------
4 * Catalog-to-filenode mapping
6 * For most tables, the physical file underlying the table is specified by
7 * pg_class.relfilenode. However, that obviously won't work for pg_class
8 * itself, nor for the other "nailed" catalogs for which we have to be able
9 * to set up working Relation entries without access to pg_class. It also
10 * does not work for shared catalogs, since there is no practical way to
11 * update other databases' pg_class entries when relocating a shared catalog.
12 * Therefore, for these special catalogs (henceforth referred to as "mapped
13 * catalogs") we rely on a separately maintained file that shows the mapping
14 * from catalog OIDs to filenode numbers. Each database has a map file for
15 * its local mapped catalogs, and there is a separate map file for shared
16 * catalogs. Mapped catalogs have zero in their pg_class.relfilenode entries.
18 * Relocation of a normal table is committed (ie, the new physical file becomes
19 * authoritative) when the pg_class row update commits. For mapped catalogs,
20 * the act of updating the map file is effectively commit of the relocation.
21 * We postpone the file update till just before commit of the transaction
22 * doing the rewrite, but there is necessarily a window between. Therefore
23 * mapped catalogs can only be relocated by operations such as VACUUM FULL
24 * and CLUSTER, which make no transactionally-significant changes: it must be
25 * safe for the new file to replace the old, even if the transaction itself
26 * aborts. An important factor here is that the indexes and toast table of
27 * a mapped catalog must also be mapped, so that the rewrites/relocations of
28 * all these files commit in a single map file update rather than being tied
29 * to transaction commit.
31 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
32 * Portions Copyright (c) 1994, Regents of the University of California
36 * src/backend/utils/cache/relmapper.c
38 *-------------------------------------------------------------------------
46 #include "access/xact.h"
47 #include "catalog/catalog.h"
48 #include "catalog/pg_tablespace.h"
49 #include "catalog/storage.h"
50 #include "miscadmin.h"
51 #include "storage/fd.h"
52 #include "storage/lwlock.h"
53 #include "utils/inval.h"
54 #include "utils/relmapper.h"
58 * The map file is critical data: we have no automatic method for recovering
59 * from loss or corruption of it. We use a CRC so that we can detect
60 * corruption. To minimize the risk of failed updates, the map file should
61 * be kept to no more than one standard-size disk sector (ie 512 bytes),
62 * and we use overwrite-in-place rather than playing renaming games.
63 * The struct layout below is designed to occupy exactly 512 bytes, which
64 * might make filesystem updates a bit more efficient.
66 * Entries in the mappings[] array are in no particular order. We could
67 * speed searching by insisting on OID order, but it really shouldn't be
68 * worth the trouble given the intended size of the mapping sets.
70 #define RELMAPPER_FILENAME "pg_filenode.map"
72 #define RELMAPPER_FILEMAGIC 0x592717 /* version ID value */
74 #define MAX_MAPPINGS 62 /* 62 * 8 + 16 = 512 */
76 typedef struct RelMapping
78 Oid mapoid; /* OID of a catalog */
79 Oid mapfilenode; /* its filenode number */
82 typedef struct RelMapFile
84 int32 magic; /* always RELMAPPER_FILEMAGIC */
85 int32 num_mappings; /* number of valid RelMapping entries */
86 RelMapping mappings[MAX_MAPPINGS];
87 int32 crc; /* CRC of all above */
88 int32 pad; /* to make the struct size be 512 exactly */
92 * The currently known contents of the shared map file and our database's
93 * local map file are stored here. These can be reloaded from disk
94 * immediately whenever we receive an update sinval message.
96 static RelMapFile shared_map;
97 static RelMapFile local_map;
100 * We use the same RelMapFile data structure to track uncommitted local
101 * changes in the mappings (but note the magic and crc fields are not made
102 * valid in these variables). Currently, map updates are not allowed within
103 * subtransactions, so one set of transaction-level changes is sufficient.
105 * The active_xxx variables contain updates that are valid in our transaction
106 * and should be honored by RelationMapOidToFilenode. The pending_xxx
107 * variables contain updates we have been told about that aren't active yet;
108 * they will become active at the next CommandCounterIncrement. This setup
109 * lets map updates act similarly to updates of pg_class rows, ie, they
110 * become visible only at the next CommandCounterIncrement boundary.
112 static RelMapFile active_shared_updates;
113 static RelMapFile active_local_updates;
114 static RelMapFile pending_shared_updates;
115 static RelMapFile pending_local_updates;
118 /* non-export function prototypes */
119 static void apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode,
121 static void merge_map_updates(RelMapFile *map, const RelMapFile *updates,
123 static void load_relmap_file(bool shared);
124 static void write_relmap_file(bool shared, RelMapFile *newmap,
125 bool write_wal, bool send_sinval, bool preserve_files,
126 Oid dbid, Oid tsid, const char *dbpath);
127 static void perform_relmap_update(bool shared, const RelMapFile *updates);
131 * RelationMapOidToFilenode
133 * The raison d' etre ... given a relation OID, look up its filenode.
135 * Although shared and local relation OIDs should never overlap, the caller
136 * always knows which we need --- so pass that information to avoid useless
139 * Returns InvalidOid if the OID is not known (which should never happen,
140 * but the caller is in a better position to report a meaningful error).
143 RelationMapOidToFilenode(Oid relationId, bool shared)
145 const RelMapFile *map;
148 /* If there are active updates, believe those over the main maps */
151 map = &active_shared_updates;
152 for (i = 0; i < map->num_mappings; i++)
154 if (relationId == map->mappings[i].mapoid)
155 return map->mappings[i].mapfilenode;
158 for (i = 0; i < map->num_mappings; i++)
160 if (relationId == map->mappings[i].mapoid)
161 return map->mappings[i].mapfilenode;
166 map = &active_local_updates;
167 for (i = 0; i < map->num_mappings; i++)
169 if (relationId == map->mappings[i].mapoid)
170 return map->mappings[i].mapfilenode;
173 for (i = 0; i < map->num_mappings; i++)
175 if (relationId == map->mappings[i].mapoid)
176 return map->mappings[i].mapfilenode;
184 * RelationMapFilenodeToOid
186 * Do the reverse of the normal direction of mapping done in
187 * RelationMapOidToFilenode.
189 * This is not supposed to be used during normal running but rather for
190 * information purposes when looking at the filesystem or xlog.
192 * Returns InvalidOid if the OID is not known; this can easily happen if the
193 * relfilenode doesn't pertain to a mapped relation.
196 RelationMapFilenodeToOid(Oid filenode, bool shared)
198 const RelMapFile *map;
201 /* If there are active updates, believe those over the main maps */
204 map = &active_shared_updates;
205 for (i = 0; i < map->num_mappings; i++)
207 if (filenode == map->mappings[i].mapfilenode)
208 return map->mappings[i].mapoid;
211 for (i = 0; i < map->num_mappings; i++)
213 if (filenode == map->mappings[i].mapfilenode)
214 return map->mappings[i].mapoid;
219 map = &active_local_updates;
220 for (i = 0; i < map->num_mappings; i++)
222 if (filenode == map->mappings[i].mapfilenode)
223 return map->mappings[i].mapoid;
226 for (i = 0; i < map->num_mappings; i++)
228 if (filenode == map->mappings[i].mapfilenode)
229 return map->mappings[i].mapoid;
237 * RelationMapUpdateMap
239 * Install a new relfilenode mapping for the specified relation.
241 * If immediate is true (or we're bootstrapping), the mapping is activated
242 * immediately. Otherwise it is made pending until CommandCounterIncrement.
245 RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared,
250 if (IsBootstrapProcessingMode())
253 * In bootstrap mode, the mapping gets installed in permanent map.
263 * We don't currently support map changes within subtransactions. This
264 * could be done with more bookkeeping infrastructure, but it doesn't
265 * presently seem worth it.
267 if (GetCurrentTransactionNestLevel() > 1)
268 elog(ERROR, "cannot change relation mapping within subtransaction");
272 /* Make it active, but only locally */
274 map = &active_shared_updates;
276 map = &active_local_updates;
280 /* Make it pending */
282 map = &pending_shared_updates;
284 map = &pending_local_updates;
287 apply_map_update(map, relationId, fileNode, true);
293 * Insert a new mapping into the given map variable, replacing any existing
294 * mapping for the same relation.
296 * In some cases the caller knows there must be an existing mapping; pass
297 * add_okay = false to draw an error if not.
300 apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, bool add_okay)
304 /* Replace any existing mapping */
305 for (i = 0; i < map->num_mappings; i++)
307 if (relationId == map->mappings[i].mapoid)
309 map->mappings[i].mapfilenode = fileNode;
314 /* Nope, need to add a new mapping */
316 elog(ERROR, "attempt to apply a mapping to unmapped relation %u",
318 if (map->num_mappings >= MAX_MAPPINGS)
319 elog(ERROR, "ran out of space in relation map");
320 map->mappings[map->num_mappings].mapoid = relationId;
321 map->mappings[map->num_mappings].mapfilenode = fileNode;
328 * Merge all the updates in the given pending-update map into the target map.
329 * This is just a bulk form of apply_map_update.
332 merge_map_updates(RelMapFile *map, const RelMapFile *updates, bool add_okay)
336 for (i = 0; i < updates->num_mappings; i++)
338 apply_map_update(map,
339 updates->mappings[i].mapoid,
340 updates->mappings[i].mapfilenode,
346 * RelationMapRemoveMapping
348 * Remove a relation's entry in the map. This is only allowed for "active"
349 * (but not committed) local mappings. We need it so we can back out the
350 * entry for the transient target file when doing VACUUM FULL/CLUSTER on
354 RelationMapRemoveMapping(Oid relationId)
356 RelMapFile *map = &active_local_updates;
359 for (i = 0; i < map->num_mappings; i++)
361 if (relationId == map->mappings[i].mapoid)
363 /* Found it, collapse it out */
364 map->mappings[i] = map->mappings[map->num_mappings - 1];
369 elog(ERROR, "could not find temporary mapping for relation %u",
374 * RelationMapInvalidate
376 * This routine is invoked for SI cache flush messages. We must re-read
377 * the indicated map file. However, we might receive a SI message in a
378 * process that hasn't yet, and might never, load the mapping files;
379 * for example the autovacuum launcher, which *must not* try to read
380 * a local map since it is attached to no particular database.
381 * So, re-read only if the map is valid now.
384 RelationMapInvalidate(bool shared)
388 if (shared_map.magic == RELMAPPER_FILEMAGIC)
389 load_relmap_file(true);
393 if (local_map.magic == RELMAPPER_FILEMAGIC)
394 load_relmap_file(false);
399 * RelationMapInvalidateAll
401 * Reload all map files. This is used to recover from SI message buffer
402 * overflow: we can't be sure if we missed an inval message.
403 * Again, reload only currently-valid maps.
406 RelationMapInvalidateAll(void)
408 if (shared_map.magic == RELMAPPER_FILEMAGIC)
409 load_relmap_file(true);
410 if (local_map.magic == RELMAPPER_FILEMAGIC)
411 load_relmap_file(false);
417 * Activate any "pending" relation map updates at CommandCounterIncrement time.
420 AtCCI_RelationMap(void)
422 if (pending_shared_updates.num_mappings != 0)
424 merge_map_updates(&active_shared_updates,
425 &pending_shared_updates,
427 pending_shared_updates.num_mappings = 0;
429 if (pending_local_updates.num_mappings != 0)
431 merge_map_updates(&active_local_updates,
432 &pending_local_updates,
434 pending_local_updates.num_mappings = 0;
439 * AtEOXact_RelationMap
441 * Handle relation mapping at main-transaction commit or abort.
443 * During commit, this must be called as late as possible before the actual
444 * transaction commit, so as to minimize the window where the transaction
445 * could still roll back after committing map changes. Although nothing
446 * critically bad happens in such a case, we still would prefer that it
447 * not happen, since we'd possibly be losing useful updates to the relations'
450 * During abort, we just have to throw away any pending map changes.
451 * Normal post-abort cleanup will take care of fixing relcache entries.
454 AtEOXact_RelationMap(bool isCommit)
459 * We should not get here with any "pending" updates. (We could
460 * logically choose to treat such as committed, but in the current
461 * code this should never happen.)
463 Assert(pending_shared_updates.num_mappings == 0);
464 Assert(pending_local_updates.num_mappings == 0);
467 * Write any active updates to the actual map files, then reset them.
469 if (active_shared_updates.num_mappings != 0)
471 perform_relmap_update(true, &active_shared_updates);
472 active_shared_updates.num_mappings = 0;
474 if (active_local_updates.num_mappings != 0)
476 perform_relmap_update(false, &active_local_updates);
477 active_local_updates.num_mappings = 0;
482 /* Abort --- drop all local and pending updates */
483 active_shared_updates.num_mappings = 0;
484 active_local_updates.num_mappings = 0;
485 pending_shared_updates.num_mappings = 0;
486 pending_local_updates.num_mappings = 0;
491 * AtPrepare_RelationMap
493 * Handle relation mapping at PREPARE.
495 * Currently, we don't support preparing any transaction that changes the map.
498 AtPrepare_RelationMap(void)
500 if (active_shared_updates.num_mappings != 0 ||
501 active_local_updates.num_mappings != 0 ||
502 pending_shared_updates.num_mappings != 0 ||
503 pending_local_updates.num_mappings != 0)
505 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
506 errmsg("cannot PREPARE a transaction that modified relation mapping")));
510 * CheckPointRelationMap
512 * This is called during a checkpoint. It must ensure that any relation map
513 * updates that were WAL-logged before the start of the checkpoint are
514 * securely flushed to disk and will not need to be replayed later. This
515 * seems unlikely to be a performance-critical issue, so we use a simple
516 * method: we just take and release the RelationMappingLock. This ensures
517 * that any already-logged map update is complete, because write_relmap_file
518 * will fsync the map file before the lock is released.
521 CheckPointRelationMap(void)
523 LWLockAcquire(RelationMappingLock, LW_SHARED);
524 LWLockRelease(RelationMappingLock);
528 * RelationMapFinishBootstrap
530 * Write out the initial relation mapping files at the completion of
531 * bootstrap. All the mapped files should have been made known to us
532 * via RelationMapUpdateMap calls.
535 RelationMapFinishBootstrap(void)
537 Assert(IsBootstrapProcessingMode());
539 /* Shouldn't be anything "pending" ... */
540 Assert(active_shared_updates.num_mappings == 0);
541 Assert(active_local_updates.num_mappings == 0);
542 Assert(pending_shared_updates.num_mappings == 0);
543 Assert(pending_local_updates.num_mappings == 0);
545 /* Write the files; no WAL or sinval needed */
546 write_relmap_file(true, &shared_map, false, false, false,
547 InvalidOid, GLOBALTABLESPACE_OID, NULL);
548 write_relmap_file(false, &local_map, false, false, false,
549 MyDatabaseId, MyDatabaseTableSpace, DatabasePath);
553 * RelationMapInitialize
555 * This initializes the mapper module at process startup. We can't access the
556 * database yet, so just make sure the maps are empty.
559 RelationMapInitialize(void)
561 /* The static variables should initialize to zeroes, but let's be sure */
562 shared_map.magic = 0; /* mark it not loaded */
564 shared_map.num_mappings = 0;
565 local_map.num_mappings = 0;
566 active_shared_updates.num_mappings = 0;
567 active_local_updates.num_mappings = 0;
568 pending_shared_updates.num_mappings = 0;
569 pending_local_updates.num_mappings = 0;
573 * RelationMapInitializePhase2
575 * This is called to prepare for access to pg_database during startup.
576 * We should be able to read the shared map file now.
579 RelationMapInitializePhase2(void)
582 * In bootstrap mode, the map file isn't there yet, so do nothing.
584 if (IsBootstrapProcessingMode())
588 * Load the shared map file, die on error.
590 load_relmap_file(true);
594 * RelationMapInitializePhase3
596 * This is called as soon as we have determined MyDatabaseId and set up
597 * DatabasePath. At this point we should be able to read the local map file.
600 RelationMapInitializePhase3(void)
603 * In bootstrap mode, the map file isn't there yet, so do nothing.
605 if (IsBootstrapProcessingMode())
609 * Load the local map file, die on error.
611 load_relmap_file(false);
615 * load_relmap_file -- load data from the shared or local map file
617 * Because the map file is essential for access to core system catalogs,
618 * failure to read it is a fatal error.
620 * Note that the local case requires DatabasePath to be set up.
623 load_relmap_file(bool shared)
626 char mapfilename[MAXPGPATH];
632 snprintf(mapfilename, sizeof(mapfilename), "global/%s",
638 snprintf(mapfilename, sizeof(mapfilename), "%s/%s",
639 DatabasePath, RELMAPPER_FILENAME);
644 fd = OpenTransientFile(mapfilename,
645 O_RDONLY | PG_BINARY, S_IRUSR | S_IWUSR);
648 (errcode_for_file_access(),
649 errmsg("could not open relation mapping file \"%s\": %m",
653 * Note: we could take RelationMappingLock in shared mode here, but it
654 * seems unnecessary since our read() should be atomic against any
655 * concurrent updater's write(). If the file is updated shortly after we
656 * look, the sinval signaling mechanism will make us re-read it before we
657 * are able to access any relation that's affected by the change.
659 if (read(fd, map, sizeof(RelMapFile)) != sizeof(RelMapFile))
661 (errcode_for_file_access(),
662 errmsg("could not read relation mapping file \"%s\": %m",
665 CloseTransientFile(fd);
667 /* check for correct magic number, etc */
668 if (map->magic != RELMAPPER_FILEMAGIC ||
669 map->num_mappings < 0 ||
670 map->num_mappings > MAX_MAPPINGS)
672 (errmsg("relation mapping file \"%s\" contains invalid data",
677 COMP_CRC32(crc, (char *) map, offsetof(RelMapFile, crc));
680 if (!EQ_CRC32(crc, map->crc))
682 (errmsg("relation mapping file \"%s\" contains incorrect checksum",
687 * Write out a new shared or local map file with the given contents.
689 * The magic number and CRC are automatically updated in *newmap. On
690 * success, we copy the data to the appropriate permanent static variable.
692 * If write_wal is TRUE then an appropriate WAL message is emitted.
693 * (It will be false for bootstrap and WAL replay cases.)
695 * If send_sinval is TRUE then a SI invalidation message is sent.
696 * (This should be true except in bootstrap case.)
698 * If preserve_files is TRUE then the storage manager is warned not to
699 * delete the files listed in the map.
701 * Because this may be called during WAL replay when MyDatabaseId,
702 * DatabasePath, etc aren't valid, we require the caller to pass in suitable
703 * values. The caller is also responsible for being sure no concurrent
704 * map update could be happening.
707 write_relmap_file(bool shared, RelMapFile *newmap,
708 bool write_wal, bool send_sinval, bool preserve_files,
709 Oid dbid, Oid tsid, const char *dbpath)
713 char mapfilename[MAXPGPATH];
716 * Fill in the overhead fields and update CRC.
718 newmap->magic = RELMAPPER_FILEMAGIC;
719 if (newmap->num_mappings < 0 || newmap->num_mappings > MAX_MAPPINGS)
720 elog(ERROR, "attempt to write bogus relation mapping");
722 INIT_CRC32(newmap->crc);
723 COMP_CRC32(newmap->crc, (char *) newmap, offsetof(RelMapFile, crc));
724 FIN_CRC32(newmap->crc);
727 * Open the target file. We prefer to do this before entering the
728 * critical section, so that an open() failure need not force PANIC.
732 snprintf(mapfilename, sizeof(mapfilename), "global/%s",
734 realmap = &shared_map;
738 snprintf(mapfilename, sizeof(mapfilename), "%s/%s",
739 dbpath, RELMAPPER_FILENAME);
740 realmap = &local_map;
743 fd = OpenTransientFile(mapfilename,
744 O_WRONLY | O_CREAT | PG_BINARY,
748 (errcode_for_file_access(),
749 errmsg("could not open relation mapping file \"%s\": %m",
754 xl_relmap_update xlrec;
755 XLogRecData rdata[2];
758 /* now errors are fatal ... */
759 START_CRIT_SECTION();
763 xlrec.nbytes = sizeof(RelMapFile);
765 rdata[0].data = (char *) (&xlrec);
766 rdata[0].len = MinSizeOfRelmapUpdate;
767 rdata[0].buffer = InvalidBuffer;
768 rdata[0].next = &(rdata[1]);
769 rdata[1].data = (char *) newmap;
770 rdata[1].len = sizeof(RelMapFile);
771 rdata[1].buffer = InvalidBuffer;
772 rdata[1].next = NULL;
774 lsn = XLogInsert(RM_RELMAP_ID, XLOG_RELMAP_UPDATE, rdata);
776 /* As always, WAL must hit the disk before the data update does */
781 if (write(fd, newmap, sizeof(RelMapFile)) != sizeof(RelMapFile))
783 /* if write didn't set errno, assume problem is no disk space */
787 (errcode_for_file_access(),
788 errmsg("could not write to relation mapping file \"%s\": %m",
793 * We choose to fsync the data to disk before considering the task done.
794 * It would be possible to relax this if it turns out to be a performance
795 * issue, but it would complicate checkpointing --- see notes for
796 * CheckPointRelationMap.
798 if (pg_fsync(fd) != 0)
800 (errcode_for_file_access(),
801 errmsg("could not fsync relation mapping file \"%s\": %m",
804 if (CloseTransientFile(fd))
806 (errcode_for_file_access(),
807 errmsg("could not close relation mapping file \"%s\": %m",
811 * Now that the file is safely on disk, send sinval message to let other
812 * backends know to re-read it. We must do this inside the critical
813 * section: if for some reason we fail to send the message, we have to
814 * force a database-wide PANIC. Otherwise other backends might continue
815 * execution with stale mapping information, which would be catastrophic
816 * as soon as others began to use the now-committed data.
819 CacheInvalidateRelmap(dbid);
822 * Make sure that the files listed in the map are not deleted if the outer
823 * transaction aborts. This had better be within the critical section
824 * too: it's not likely to fail, but if it did, we'd arrive at transaction
825 * abort with the files still vulnerable. PANICing will leave things in a
826 * good state on-disk.
828 * Note: we're cheating a little bit here by assuming that mapped files
829 * are either in pg_global or the database's default tablespace.
835 for (i = 0; i < newmap->num_mappings; i++)
839 rnode.spcNode = tsid;
841 rnode.relNode = newmap->mappings[i].mapfilenode;
842 RelationPreserveStorage(rnode, false);
846 /* Success, update permanent copy */
847 memcpy(realmap, newmap, sizeof(RelMapFile));
849 /* Critical section done */
855 * Merge the specified updates into the appropriate "real" map,
856 * and write out the changes. This function must be used for committing
857 * updates during normal multiuser operation.
860 perform_relmap_update(bool shared, const RelMapFile *updates)
865 * Anyone updating a relation's mapping info should take exclusive lock on
866 * that rel and hold it until commit. This ensures that there will not be
867 * concurrent updates on the same mapping value; but there could easily be
868 * concurrent updates on different values in the same file. We cover that
869 * by acquiring the RelationMappingLock, re-reading the target file to
870 * ensure it's up to date, applying the updates, and writing the data
871 * before releasing RelationMappingLock.
873 * There is only one RelationMappingLock. In principle we could try to
874 * have one per mapping file, but it seems unlikely to be worth the
877 LWLockAcquire(RelationMappingLock, LW_EXCLUSIVE);
879 /* Be certain we see any other updates just made */
880 load_relmap_file(shared);
882 /* Prepare updated data in a local variable */
884 memcpy(&newmap, &shared_map, sizeof(RelMapFile));
886 memcpy(&newmap, &local_map, sizeof(RelMapFile));
889 * Apply the updates to newmap. No new mappings should appear, unless
890 * somebody is adding indexes to system catalogs.
892 merge_map_updates(&newmap, updates, allowSystemTableMods);
894 /* Write out the updated map and do other necessary tasks */
895 write_relmap_file(shared, &newmap, true, true, true,
896 (shared ? InvalidOid : MyDatabaseId),
897 (shared ? GLOBALTABLESPACE_OID : MyDatabaseTableSpace),
900 /* Now we can release the lock */
901 LWLockRelease(RelationMappingLock);
905 * RELMAP resource manager's routines
908 relmap_redo(XLogRecPtr lsn, XLogRecord *record)
910 uint8 info = record->xl_info & ~XLR_INFO_MASK;
912 /* Backup blocks are not used in relmap records */
913 Assert(!(record->xl_info & XLR_BKP_BLOCK_MASK));
915 if (info == XLOG_RELMAP_UPDATE)
917 xl_relmap_update *xlrec = (xl_relmap_update *) XLogRecGetData(record);
921 if (xlrec->nbytes != sizeof(RelMapFile))
922 elog(PANIC, "relmap_redo: wrong size %u in relmap update record",
924 memcpy(&newmap, xlrec->data, sizeof(newmap));
926 /* We need to construct the pathname for this database */
927 dbpath = GetDatabasePath(xlrec->dbid, xlrec->tsid);
930 * Write out the new map and send sinval, but of course don't write a
931 * new WAL entry. There's no surrounding transaction to tell to
932 * preserve files, either.
934 * There shouldn't be anyone else updating relmaps during WAL replay,
935 * so we don't bother to take the RelationMappingLock. We would need
936 * to do so if load_relmap_file needed to interlock against writers.
938 write_relmap_file((xlrec->dbid == InvalidOid), &newmap,
940 xlrec->dbid, xlrec->tsid, dbpath);
945 elog(PANIC, "relmap_redo: unknown op code %u", info);