mirror of
https://github.com/postgres/postgres.git
synced 2026-03-01 21:01:12 -05:00
RelFileNumbers are now assigned using a separate counter, instead of being assigned from the OID counter. This counter never wraps around: if all 2^56 possible RelFileNumbers are used, an internal error occurs. As the cluster is limited to 2^64 total bytes of WAL, this limitation should not cause a problem in practice. If the counter were 64 bits wide rather than 56 bits wide, we would need to increase the width of the BufferTag, which might adversely impact buffer lookup performance. Also, this lets us use bigint for pg_class.relfilenode and other places where these values are exposed at the SQL level without worrying about overflow. This should remove the need to keep "tombstone" files around until the next checkpoint when relations are removed. We do that to keep RelFileNumbers from being recycled, but now that won't happen anyway. However, this patch doesn't actually change anything in this area; it just makes it possible for a future patch to do so. Dilip Kumar, based on an idea from Andres Freund, who also reviewed some earlier versions of the patch. Further review and some wordsmithing by me. Also reviewed at various points by Ashutosh Sharma, Vignesh C, Amul Sul, Álvaro Herrera, and Tom Lane. Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com
100 lines
3 KiB
C
100 lines
3 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* relpath.h
|
|
* Declarations for GetRelationPath() and friends
|
|
*
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/common/relpath.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef RELPATH_H
|
|
#define RELPATH_H
|
|
|
|
/*
|
|
* 'pgrminclude ignore' needed here because CppAsString2() does not throw
|
|
* an error if the symbol is not defined.
|
|
*/
|
|
#include "catalog/catversion.h" /* pgrminclude ignore */
|
|
|
|
/*
|
|
* RelFileNumber data type identifies the specific relation file name.
|
|
*/
|
|
typedef uint64 RelFileNumber;
|
|
#define InvalidRelFileNumber ((RelFileNumber) 0)
|
|
#define RelFileNumberIsValid(relnumber) \
|
|
((bool) ((relnumber) != InvalidRelFileNumber))
|
|
#define atorelnumber(x) ((RelFileNumber) strtou64((x), NULL, 10))
|
|
#define MAX_RELFILENUMBER UINT64CONST(0x00FFFFFFFFFFFFFF)
|
|
|
|
/*
|
|
* Name of major-version-specific tablespace subdirectories
|
|
*/
|
|
#define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \
|
|
CppAsString2(CATALOG_VERSION_NO)
|
|
|
|
/* Characters to allow for an OID in a relation path */
|
|
#define OIDCHARS 10 /* max chars printed by %u */
|
|
#define RELNUMBERCHARS 20 /* max chars printed by UINT64_FORMAT */
|
|
|
|
/*
|
|
* Stuff for fork names.
|
|
*
|
|
* The physical storage of a relation consists of one or more forks.
|
|
* The main fork is always created, but in addition to that there can be
|
|
* additional forks for storing various metadata. ForkNumber is used when
|
|
* we need to refer to a specific fork in a relation.
|
|
*/
|
|
typedef enum ForkNumber
|
|
{
|
|
InvalidForkNumber = -1,
|
|
MAIN_FORKNUM = 0,
|
|
FSM_FORKNUM,
|
|
VISIBILITYMAP_FORKNUM,
|
|
INIT_FORKNUM
|
|
|
|
/*
|
|
* NOTE: if you add a new fork, change MAX_FORKNUM and possibly
|
|
* FORKNAMECHARS below, and update the forkNames array in
|
|
* src/common/relpath.c
|
|
*/
|
|
} ForkNumber;
|
|
|
|
#define MAX_FORKNUM INIT_FORKNUM
|
|
|
|
#define FORKNAMECHARS 4 /* max chars for a fork name */
|
|
|
|
extern PGDLLIMPORT const char *const forkNames[];
|
|
|
|
extern ForkNumber forkname_to_number(const char *forkName);
|
|
extern int forkname_chars(const char *str, ForkNumber *fork);
|
|
|
|
/*
|
|
* Stuff for computing filesystem pathnames for relations.
|
|
*/
|
|
extern char *GetDatabasePath(Oid dbOid, Oid spcOid);
|
|
|
|
extern char *GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber,
|
|
int backendId, ForkNumber forkNumber);
|
|
|
|
/*
|
|
* Wrapper macros for GetRelationPath. Beware of multiple
|
|
* evaluation of the RelFileLocator or RelFileLocatorBackend argument!
|
|
*/
|
|
|
|
/* First argument is a RelFileLocator */
|
|
#define relpathbackend(rlocator, backend, forknum) \
|
|
GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
|
|
backend, forknum)
|
|
|
|
/* First argument is a RelFileLocator */
|
|
#define relpathperm(rlocator, forknum) \
|
|
relpathbackend(rlocator, InvalidBackendId, forknum)
|
|
|
|
/* First argument is a RelFileLocatorBackend */
|
|
#define relpath(rlocator, forknum) \
|
|
relpathbackend((rlocator).locator, (rlocator).backend, forknum)
|
|
|
|
#endif /* RELPATH_H */
|