Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
676bb9a6
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
676bb9a6
编写于
8月 12, 2004
作者:
B
Bruce Momjian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbsize modification to support tablespaces
Gavin Sherry
上级
a5836751
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
11 deletion
+55
-11
contrib/dbsize/dbsize.c
contrib/dbsize/dbsize.c
+55
-11
未找到文件。
contrib/dbsize/dbsize.c
浏览文件 @
676bb9a6
...
...
@@ -6,13 +6,18 @@
#include "access/heapam.h"
#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/namespace.h"
#include "catalog/pg_tablespace.h"
#include "commands/dbcommands.h"
#include "fmgr.h"
#include "storage/fd.h"
#include "utils/builtins.h"
static
int64
get_tablespace_size
(
Oid
dbid
,
Oid
spcid
,
bool
baddirOK
);
static
char
*
psnprintf
(
size_t
len
,
const
char
*
fmt
,...)
{
...
...
@@ -44,10 +49,12 @@ database_size(PG_FUNCTION_ARGS)
Name
dbname
=
PG_GETARG_NAME
(
0
);
Oid
dbid
;
char
*
dbpath
;
DIR
*
dirdesc
;
struct
dirent
*
direntry
;
int64
totalsize
;
#ifdef SYMLINK
Relation
dbrel
;
HeapScanDesc
scan
;
HeapTuple
tuple
;
#endif
dbid
=
get_database_oid
(
NameStr
(
*
dbname
));
if
(
!
OidIsValid
(
dbid
))
...
...
@@ -55,14 +62,55 @@ database_size(PG_FUNCTION_ARGS)
(
errcode
(
ERRCODE_UNDEFINED_DATABASE
),
errmsg
(
"database
\"
%s
\"
does not exist"
,
NameStr
(
*
dbname
))));
dbpath
=
GetDatabasePath
(
dbid
);
#ifdef SYMLINK
dbrel
=
heap_openr
(
TableSpaceRelationName
,
AccessShareLock
);
scan
=
heap_beginscan
(
dbrel
,
SnapshotNow
,
0
,
(
ScanKey
)
NULL
);
totalsize
=
0
;
while
((
tuple
=
heap_getnext
(
scan
,
ForwardScanDirection
)))
{
Oid
spcid
=
HeapTupleGetOid
(
tuple
);
if
(
spcid
!=
GLOBALTABLESPACE_OID
)
totalsize
+=
get_tablespace_size
(
dbid
,
spcid
,
true
);
}
heap_endscan
(
scan
);
heap_close
(
dbrel
,
AccessShareLock
);
#else
/* Same as always */
totalsize
=
get_tablespace_size
(
dbid
,
DEFAULTTABLESPACE_OID
,
false
);
#endif
/*
* We need to keep in mind that we may not be called from the database
* whose size we're reporting so, we need to look in every tablespace
* to see if our database has data in there
*/
PG_RETURN_INT64
(
totalsize
);
}
static
int64
get_tablespace_size
(
Oid
dbid
,
Oid
spcid
,
bool
baddirOK
)
{
char
*
dbpath
;
DIR
*
dirdesc
;
struct
dirent
*
direntry
;
int64
totalsize
;
dbpath
=
GetDatabasePath
(
dbid
,
spcid
);
dirdesc
=
AllocateDir
(
dbpath
);
if
(
!
dirdesc
)
ereport
(
ERROR
,
{
if
(
baddirOK
)
return
0
;
else
ereport
(
ERROR
,
(
errcode_for_file_access
(),
errmsg
(
"could not open directory
\"
%s
\"
: %m"
,
dbpath
)));
}
totalsize
=
0
;
for
(;;)
{
...
...
@@ -87,18 +135,14 @@ database_size(PG_FUNCTION_ARGS)
ereport
(
ERROR
,
(
errcode_for_file_access
(),
errmsg
(
"could not stat
\"
%s
\"
: %m"
,
fullname
)));
totalsize
+=
statbuf
.
st_size
;
pfree
(
fullname
);
}
FreeDir
(
dirdesc
);
PG_RETURN_INT64
(
totalsize
);
return
(
totalsize
);
}
/*
* SQL function: relation_size(text) returns bigint
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录