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",
225 if (tblspcOid == DEFAULTTABLESPACE_OID)
227 else if (tblspcOid == GLOBALTABLESPACE_OID)
238 while ((direntry =
ReadDir(dirdesc, tblspcPath)) != NULL)
244 if (strcmp(direntry->
d_name,
".") == 0 ||
245 strcmp(direntry->
d_name,
"..") == 0)
248 snprintf(pathname,
sizeof(pathname),
"%s/%s", tblspcPath, direntry->
d_name);
250 if (
stat(pathname, &fst) < 0)
257 errmsg(
"could not stat file \"%s\": %m", pathname)));
313 unsigned int segcount = 0;
317 for (segcount = 0;; segcount++)
328 relationpath, segcount);
330 if (
stat(pathname, &fst) < 0)
337 errmsg(
"could not stat file \"%s\": %m", pathname)));
389 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
397 foreach(lc, indexlist)
403 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
432 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
458 if (rel->
rd_rel->relhasindex)
463 foreach(cell, index_oids)
471 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
578 uint64 abs_size =
size < 0 ? 0 - (uint64)
size : (uint64)
size;
584 if (unit[1].
name == NULL || abs_size < unit->
limit)
603 + (unit->
round ==
true));
604 size /= ((int64) 1) << bits;
663 Datum divisor_numeric;
680 unsigned int shiftby;
683 if (unit[1].
name == NULL ||
702 + (unit->
round ==
true));
722 bool have_digits =
false;
728 while (isspace((
unsigned char) *strptr))
735 if (*endptr ==
'-' || *endptr ==
'+')
739 if (isdigit((
unsigned char) *endptr))
744 while (isdigit((
unsigned char) *endptr));
751 if (isdigit((
unsigned char) *endptr))
756 while (isdigit((
unsigned char) *endptr));
763 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
767 if (*endptr ==
'e' || *endptr ==
'E')
776 exponent = strtol(endptr + 1, &cp, 10);
786 saved_char = *endptr;
794 *endptr = saved_char;
798 while (isspace((
unsigned char) *strptr))
805 int64 multiplier = 0;
810 while (isspace((
unsigned char) *endptr))
824 if (unit->
name == NULL)
837 if (unit->
name == NULL)
839 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
841 errdetail(
"Invalid size unit: \"%s\".", strptr),
842 errhint(
"Valid units are \"bytes\", \"B\", \"kB\", \"MB\", \"GB\", \"TB\", and \"PB\".")));
844 multiplier = ((int64) 1) << unit->
unitbits;
891 if (RELKIND_HAS_STORAGE(relform->relkind))
893 if (relform->relfilenode)
894 result = relform->relfilenode;
897 relform->relisshared);
965 if (RELKIND_HAS_STORAGE(relform->relkind))
968 if (relform->reltablespace)
969 rlocator.
spcOid = relform->reltablespace;
972 if (rlocator.
spcOid == GLOBALTABLESPACE_OID)
976 if (relform->relfilenode)
977 rlocator.
relNumber = relform->relfilenode;
980 relform->relisshared);
998 switch (relform->relpersistence)
1000 case RELPERSISTENCE_UNLOGGED:
1001 case RELPERSISTENCE_PERMANENT:
1004 case RELPERSISTENCE_TEMP:
1015 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)
char * get_database_name(Oid dbid)
Oid get_database_oid(const char *dbname, bool missing_ok)
static int64 calculate_total_relation_size(Relation rel)
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)
static char * numeric_to_cstring(Numeric n)
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,...)
struct dirent * ReadDir(DIR *dir, const char *dirname)
DIR * AllocateDir(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 char * DatumGetCString(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
#define ProcNumberForTempRelations()
#define INVALID_PROC_NUMBER
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 VARSIZE_ANY_EXHDR(PTR)
char * text_to_cstring(const text *t)
text * cstring_to_text(const char *s)