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},
73 while ((direntry =
ReadDir(dirdesc, path)) != NULL)
79 if (strcmp(direntry->
d_name,
".") == 0 ||
80 strcmp(direntry->
d_name,
"..") == 0)
129 snprintf(pathname,
sizeof(pathname),
"base/%u", dbOid);
136 while ((direntry =
ReadDir(dirdesc, dirpath)) != NULL)
140 if (strcmp(direntry->
d_name,
".") == 0 ||
141 strcmp(direntry->
d_name,
"..") == 0)
144 snprintf(pathname,
sizeof(pathname),
"pg_tblspc/%s/%s/%u",
212 if (tblspcOid == DEFAULTTABLESPACE_OID)
214 else if (tblspcOid == GLOBALTABLESPACE_OID)
225 while ((direntry =
ReadDir(dirdesc, tblspcPath)) != NULL)
231 if (strcmp(direntry->
d_name,
".") == 0 ||
232 strcmp(direntry->
d_name,
"..") == 0)
235 snprintf(pathname,
sizeof(pathname),
"%s/%s", tblspcPath, direntry->
d_name);
237 if (
stat(pathname, &fst) < 0)
244 errmsg(
"could not stat file \"%s\": %m", pathname)));
300 unsigned int segcount = 0;
304 for (segcount = 0;; segcount++)
315 relationpath, segcount);
317 if (
stat(pathname, &fst) < 0)
324 errmsg(
"could not stat file \"%s\": %m", pathname)));
376 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
384 foreach(lc, indexlist)
390 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
419 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
445 if (rel->
rd_rel->relhasindex)
450 foreach(cell, index_oids)
458 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
586 + (unit->
round ==
true));
587 size /= ((int64) 1) << bits;
646 Datum divisor_numeric;
663 unsigned int shiftby;
666 if (unit[1].
name == NULL ||
685 + (unit->
round ==
true));
705 bool have_digits =
false;
711 while (isspace((
unsigned char) *strptr))
718 if (*endptr ==
'-' || *endptr ==
'+')
722 if (isdigit((
unsigned char) *endptr))
727 while (isdigit((
unsigned char) *endptr));
734 if (isdigit((
unsigned char) *endptr))
739 while (isdigit((
unsigned char) *endptr));
746 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
750 if (*endptr ==
'e' || *endptr ==
'E')
759 exponent = strtol(endptr + 1, &cp, 10);
769 saved_char = *endptr;
777 *endptr = saved_char;
781 while (isspace((
unsigned char) *strptr))
788 int64 multiplier = 0;
793 while (isspace((
unsigned char) *endptr))
804 multiplier = ((int64) 1) << unit->
unitbits;
810 if (unit->
name == NULL)
812 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
814 errdetail(
"Invalid size unit: \"%s\".", strptr),
815 errhint(
"Valid units are \"bytes\", \"kB\", \"MB\", \"GB\", \"TB\", and \"PB\".")));
862 if (RELKIND_HAS_STORAGE(relform->relkind))
864 if (relform->relfilenode)
865 result = relform->relfilenode;
868 relform->relisshared);
936 if (RELKIND_HAS_STORAGE(relform->relkind))
939 if (relform->reltablespace)
940 rnode.
spcNode = relform->reltablespace;
943 if (rnode.
spcNode == GLOBALTABLESPACE_OID)
947 if (relform->relfilenode)
948 rnode.
relNode = relform->relfilenode;
951 relform->relisshared);
969 switch (relform->relpersistence)
971 case RELPERSISTENCE_UNLOGGED:
972 case RELPERSISTENCE_PERMANENT:
975 case RELPERSISTENCE_TEMP:
986 elog(
ERROR,
"invalid relpersistence: %c", relform->relpersistence);
bool has_privs_of_role(Oid member, Oid role)
AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult pg_database_aclcheck(Oid db_oid, 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 BackendIdForTempRelations()
#define OidIsValid(objectId)
char * get_database_name(Oid dbid)
Oid get_database_oid(const char *dbname, bool missing_ok)
elog(ERROR, "%s: %s", p2, msg)
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 int64 calculate_relation_size(RelFileNode *rfn, BackendId backend, ForkNumber forknum)
static Numeric numeric_truncated_divide(Numeric n, int64 divisor)
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[]
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
void list_free(List *list)
#define CHECK_FOR_INTERRUPTS()
bool isTempOrTempToastNamespace(Oid namespaceId)
int GetTempNamespaceBackendId(Oid namespaceId)
#define DatumGetNumeric(X)
#define NumericGetDatum(X)
#define PG_GETARG_NUMERIC(n)
FormData_pg_class * Form_pg_class
int pg_strcasecmp(const char *s1, const char *s2)
#define CStringGetDatum(X)
#define ObjectIdGetDatum(X)
#define DatumGetCString(X)
#define VARSIZE_ANY_EXHDR(PTR)
char * psprintf(const char *fmt,...)
List * RelationGetIndexList(Relation relation)
Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
Oid RelationMapOidToFilenode(Oid relationId, bool shared)
ForkNumber forkname_to_number(const char *forkName)
#define relpathbackend(rnode, backend, forknum)
#define TABLESPACE_VERSION_DIRECTORY
void relation_close(Relation relation, LOCKMODE lockmode)
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
char * text_to_cstring(const text *t)
text * cstring_to_text(const char *s)