35#define half_rounded(x) (((x) + ((x) < 0 ? -1 : 1)) / 2)
50 {
"bytes", 10 * 1024,
false, 0},
51 {
"kB", 20 * 1024 - 1,
true, 10},
52 {
"MB", 20 * 1024 - 1,
true, 20},
53 {
"GB", 20 * 1024 - 1,
true, 30},
54 {
"TB", 20 * 1024 - 1,
true, 40},
55 {
"PB", 20 * 1024 - 1,
true, 50},
86 while ((direntry =
ReadDir(dirdesc, path)) != NULL)
92 if (strcmp(direntry->
d_name,
".") == 0 ||
93 strcmp(direntry->
d_name,
"..") == 0)
142 snprintf(pathname,
sizeof(pathname),
"base/%u", dbOid);
149 while ((direntry =
ReadDir(dirdesc, dirpath)) != NULL)
153 if (strcmp(direntry->
d_name,
".") == 0 ||
154 strcmp(direntry->
d_name,
"..") == 0)
157 snprintf(pathname,
sizeof(pathname),
"%s/%s/%s/%u",
179 errcode(ERRCODE_UNDEFINED_OBJECT),
180 errmsg(
"database with OID %u does not exist", dbOid));
234 if (tblspcOid == DEFAULTTABLESPACE_OID)
236 else if (tblspcOid == GLOBALTABLESPACE_OID)
247 while ((direntry =
ReadDir(dirdesc, tblspcPath)) != NULL)
253 if (strcmp(direntry->
d_name,
".") == 0 ||
254 strcmp(direntry->
d_name,
"..") == 0)
257 snprintf(pathname,
sizeof(pathname),
"%s/%s", tblspcPath, direntry->
d_name);
259 if (
stat(pathname, &fst) < 0)
266 errmsg(
"could not stat file \"%s\": %m", pathname)));
292 errcode(ERRCODE_UNDEFINED_OBJECT),
293 errmsg(
"tablespace with OID %u does not exist", tblspcOid));
331 unsigned int segcount = 0;
335 for (segcount = 0;; segcount++)
346 relationpath, segcount);
348 if (
stat(pathname, &fst) < 0)
355 errmsg(
"could not stat file \"%s\": %m", pathname)));
407 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
415 foreach(lc, indexlist)
421 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
450 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
476 if (rel->
rd_rel->relhasindex)
481 foreach(cell, index_oids)
489 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
602 if (unit[1].
name == NULL || abs_size < unit->
limit)
621 + (unit->
round ==
true));
681 Datum divisor_numeric;
698 unsigned int shiftby;
701 if (unit[1].
name == NULL ||
720 + (unit->
round ==
true));
740 bool have_digits =
false;
746 while (isspace((
unsigned char) *strptr))
753 if (*endptr ==
'-' || *endptr ==
'+')
757 if (isdigit((
unsigned char) *endptr))
762 while (isdigit((
unsigned char) *endptr));
769 if (isdigit((
unsigned char) *endptr))
774 while (isdigit((
unsigned char) *endptr));
781 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
785 if (*endptr ==
'e' || *endptr ==
'E')
794 exponent = strtol(endptr + 1, &cp, 10);
804 saved_char = *endptr;
812 *endptr = saved_char;
816 while (isspace((
unsigned char) *strptr))
823 int64 multiplier = 0;
828 while (isspace((
unsigned char) *endptr))
842 if (unit->
name == NULL)
855 if (unit->
name == NULL)
857 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
859 errdetail(
"Invalid size unit: \"%s\".", strptr),
860 errhint(
"Valid units are \"bytes\", \"B\", \"kB\", \"MB\", \"GB\", \"TB\", and \"PB\".")));
909 if (RELKIND_HAS_STORAGE(relform->relkind))
911 if (relform->relfilenode)
912 result = relform->relfilenode;
915 relform->relisshared);
983 if (RELKIND_HAS_STORAGE(relform->relkind))
986 if (relform->reltablespace)
987 rlocator.
spcOid = relform->reltablespace;
990 if (rlocator.
spcOid == GLOBALTABLESPACE_OID)
994 if (relform->relfilenode)
995 rlocator.
relNumber = relform->relfilenode;
998 relform->relisshared);
1016 switch (relform->relpersistence)
1018 case RELPERSISTENCE_UNLOGGED:
1019 case RELPERSISTENCE_PERMANENT:
1022 case RELPERSISTENCE_TEMP:
1033 elog(
ERROR,
"invalid relpersistence: %c", relform->relpersistence);
bool has_privs_of_role(Oid member, Oid role)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
char * get_tablespace_name(Oid spc_oid)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Datum numeric_sub(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
Datum numeric_int8(PG_FUNCTION_ARGS)
Datum numeric_ge(PG_FUNCTION_ARGS)
Datum numeric_out(PG_FUNCTION_ARGS)
Datum numeric_div_trunc(PG_FUNCTION_ARGS)
Datum numeric_in(PG_FUNCTION_ARGS)
Datum numeric_lt(PG_FUNCTION_ARGS)
Datum numeric_add(PG_FUNCTION_ARGS)
Datum numeric_abs(PG_FUNCTION_ARGS)
Datum numeric_mul(PG_FUNCTION_ARGS)
#define Assert(condition)
#define OidIsValid(objectId)
Oid get_database_oid(const char *dbname, bool missing_ok)
char * get_database_name(Oid dbid)
static int64 calculate_total_relation_size(Relation rel)
static char * numeric_to_cstring(Numeric n)
static bool numeric_is_less(Numeric a, Numeric b)
Datum pg_indexes_size(PG_FUNCTION_ARGS)
Datum pg_size_bytes(PG_FUNCTION_ARGS)
static Numeric numeric_truncated_divide(Numeric n, int64 divisor)
static const struct size_bytes_unit_alias size_bytes_aliases[]
Datum pg_database_size_oid(PG_FUNCTION_ARGS)
Datum pg_total_relation_size(PG_FUNCTION_ARGS)
Datum pg_tablespace_size_name(PG_FUNCTION_ARGS)
static int64 calculate_tablespace_size(Oid tblspcOid)
Datum pg_size_pretty_numeric(PG_FUNCTION_ARGS)
Datum pg_relation_size(PG_FUNCTION_ARGS)
static int64 calculate_indexes_size(Relation rel)
static int64 db_dir_size(const char *path)
Datum pg_database_size_name(PG_FUNCTION_ARGS)
static Numeric numeric_absolute(Numeric n)
Datum pg_size_pretty(PG_FUNCTION_ARGS)
static int64 calculate_database_size(Oid dbOid)
Datum pg_table_size(PG_FUNCTION_ARGS)
Datum pg_tablespace_size_oid(PG_FUNCTION_ARGS)
static Numeric numeric_half_rounded(Numeric n)
Datum pg_relation_filenode(PG_FUNCTION_ARGS)
Datum pg_filenode_relation(PG_FUNCTION_ARGS)
static const struct size_pretty_unit size_pretty_units[]
static int64 calculate_relation_size(RelFileLocator *rfn, ProcNumber backend, ForkNumber forknum)
Datum pg_relation_filepath(PG_FUNCTION_ARGS)
static int64 calculate_toast_table_size(Oid toastrelid)
static int64 calculate_table_size(Relation rel)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
#define PG_GETARG_TEXT_PP(n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_RETURN_INT64(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_INT64(n)
#define PG_GETARG_NAME(n)
#define PG_RETURN_TEXT_P(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define HeapTupleIsValid(tuple)
void list_free(List *list)
#define CHECK_FOR_INTERRUPTS()
bool isTempOrTempToastNamespace(Oid namespaceId)
ProcNumber GetTempNamespaceProcNumber(Oid namespaceId)
static Numeric DatumGetNumeric(Datum X)
#define PG_GETARG_NUMERIC(n)
static Datum NumericGetDatum(Numeric X)
FormData_pg_class * Form_pg_class
static const char * dbName
int pg_strcasecmp(const char *s1, const char *s2)
static bool DatumGetBool(Datum X)
static int64 DatumGetInt64(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
#define INVALID_PROC_NUMBER
#define ProcNumberForTempRelations()
char * psprintf(const char *fmt,...)
List * RelationGetIndexList(Relation relation)
Oid RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
RelFileNumber RelationMapOidToFilenumber(Oid relationId, bool shared)
ForkNumber forkname_to_number(const char *forkName)
#define InvalidRelFileNumber
#define relpathbackend(rlocator, backend, forknum)
#define TABLESPACE_VERSION_DIRECTORY
#define RelFileNumberIsValid(relnumber)
static pg_noinline void Size size
void relation_close(Relation relation, LOCKMODE lockmode)
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
RelFileLocator rd_locator
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define SearchSysCacheExists1(cacheId, key1)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)