36 #define half_rounded(x) (((x) + ((x) < 0 ? -1 : 1)) / 2)
51 {
"bytes", 10 * 1024,
false, 0},
52 {
"kB", 20 * 1024 - 1,
true, 10},
53 {
"MB", 20 * 1024 - 1,
true, 20},
54 {
"GB", 20 * 1024 - 1,
true, 30},
55 {
"TB", 20 * 1024 - 1,
true, 40},
56 {
"PB", 20 * 1024 - 1,
true, 50},
87 while ((direntry =
ReadDir(dirdesc, path)) != NULL)
93 if (strcmp(direntry->
d_name,
".") == 0 ||
94 strcmp(direntry->
d_name,
"..") == 0)
143 snprintf(pathname,
sizeof(pathname),
"base/%u", dbOid);
150 while ((direntry =
ReadDir(dirdesc, dirpath)) != NULL)
154 if (strcmp(direntry->
d_name,
".") == 0 ||
155 strcmp(direntry->
d_name,
"..") == 0)
158 snprintf(pathname,
sizeof(pathname),
"pg_tblspc/%s/%s/%u",
226 if (tblspcOid == DEFAULTTABLESPACE_OID)
228 else if (tblspcOid == GLOBALTABLESPACE_OID)
239 while ((direntry =
ReadDir(dirdesc, tblspcPath)) != NULL)
245 if (strcmp(direntry->
d_name,
".") == 0 ||
246 strcmp(direntry->
d_name,
"..") == 0)
249 snprintf(pathname,
sizeof(pathname),
"%s/%s", tblspcPath, direntry->
d_name);
251 if (
stat(pathname, &fst) < 0)
258 errmsg(
"could not stat file \"%s\": %m", pathname)));
314 unsigned int segcount = 0;
318 for (segcount = 0;; segcount++)
329 relationpath, segcount);
331 if (
stat(pathname, &fst) < 0)
338 errmsg(
"could not stat file \"%s\": %m", pathname)));
390 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
398 foreach(lc, indexlist)
404 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
433 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
459 if (rel->
rd_rel->relhasindex)
464 foreach(cell, index_oids)
472 for (forkNum = 0; forkNum <=
MAX_FORKNUM; forkNum++)
600 + (unit->
round ==
true));
601 size /= ((int64) 1) << bits;
660 Datum divisor_numeric;
677 unsigned int shiftby;
680 if (unit[1].
name == NULL ||
699 + (unit->
round ==
true));
719 bool have_digits =
false;
725 while (isspace((
unsigned char) *strptr))
732 if (*endptr ==
'-' || *endptr ==
'+')
736 if (isdigit((
unsigned char) *endptr))
741 while (isdigit((
unsigned char) *endptr));
748 if (isdigit((
unsigned char) *endptr))
753 while (isdigit((
unsigned char) *endptr));
760 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
764 if (*endptr ==
'e' || *endptr ==
'E')
773 exponent = strtol(endptr + 1, &cp, 10);
783 saved_char = *endptr;
791 *endptr = saved_char;
795 while (isspace((
unsigned char) *strptr))
802 int64 multiplier = 0;
807 while (isspace((
unsigned char) *endptr))
821 if (unit->
name == NULL)
834 if (unit->
name == NULL)
836 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
838 errdetail(
"Invalid size unit: \"%s\".", strptr),
839 errhint(
"Valid units are \"bytes\", \"B\", \"kB\", \"MB\", \"GB\", \"TB\", and \"PB\".")));
841 multiplier = ((int64) 1) << unit->
unitbits;
888 if (RELKIND_HAS_STORAGE(relform->relkind))
890 if (relform->relfilenode)
891 result = relform->relfilenode;
894 relform->relisshared);
962 if (RELKIND_HAS_STORAGE(relform->relkind))
965 if (relform->reltablespace)
966 rlocator.
spcOid = relform->reltablespace;
969 if (rlocator.
spcOid == GLOBALTABLESPACE_OID)
973 if (relform->relfilenode)
974 rlocator.
relNumber = relform->relfilenode;
977 relform->relisshared);
995 switch (relform->relpersistence)
997 case RELPERSISTENCE_UNLOGGED:
998 case RELPERSISTENCE_PERMANENT:
1001 case RELPERSISTENCE_TEMP:
1012 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 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 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 calculate_relation_size(RelFileLocator *rfn, BackendId backend, ForkNumber forknum)
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)
static Numeric DatumGetNumeric(Datum X)
#define PG_GETARG_NUMERIC(n)
static Datum NumericGetDatum(Numeric X)
FormData_pg_class * Form_pg_class
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)
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)
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)