Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
688781d4
Commit
688781d4
authored
Apr 02, 2002
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix contrib/dbsize for schema-qualified table names.
parent
1dc43ea7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
31 deletions
+26
-31
contrib/dbsize/dbsize.c
contrib/dbsize/dbsize.c
+23
-28
contrib/dbsize/dbsize.sql.in
contrib/dbsize/dbsize.sql.in
+3
-3
No files found.
contrib/dbsize/dbsize.c
View file @
688781d4
#include "postgres.h"
#include "fmgr.h"
#include "access/heapam.h"
#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/pg_database.h"
#include "utils/fmgroids.h"
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "access/heapam.h"
#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/namespace.h"
#include "catalog/pg_database.h"
#include "fmgr.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
static
char
*
psnprintf
(
size_t
len
,
const
char
*
fmt
,...)
...
...
@@ -38,6 +39,8 @@ psnprintf(size_t len, const char *fmt,...)
PG_FUNCTION_INFO_V1
(
database_size
);
Datum
database_size
(
PG_FUNCTION_ARGS
);
Datum
database_size
(
PG_FUNCTION_ARGS
)
{
...
...
@@ -107,39 +110,29 @@ database_size(PG_FUNCTION_ARGS)
/*
* SQL function: relation_size(
name
) returns bigint
* SQL function: relation_size(
text
) returns bigint
*/
PG_FUNCTION_INFO_V1
(
relation_size
);
Datum
relation_size
(
PG_FUNCTION_ARGS
);
Datum
relation_size
(
PG_FUNCTION_ARGS
)
{
Name
relname
=
PG_GETARG_NAME
(
0
);
text
*
relname
=
PG_GETARG_TEXT_P
(
0
);
HeapTuple
tuple
;
RangeVar
*
relrv
;
Relation
relation
;
ScanKeyData
scanKey
;
HeapScanDesc
scan
;
Oid
relnode
;
int64
totalsize
;
unsigned
int
segcount
;
relation
=
heap_openr
(
RelationRelationName
,
AccessShareLock
);
ScanKeyEntryInitialize
(
&
scanKey
,
0
,
Anum_pg_class_relname
,
F_NAMEEQ
,
NameGetDatum
(
relname
));
scan
=
heap_beginscan
(
relation
,
0
,
SnapshotNow
,
1
,
&
scanKey
);
tuple
=
heap_getnext
(
scan
,
0
);
relrv
=
makeRangeVarFromNameList
(
textToQualifiedNameList
(
relname
,
"relation_size"
));
relation
=
relation_openrv
(
relrv
,
AccessShareLock
);
if
(
!
HeapTupleIsValid
(
tuple
))
elog
(
ERROR
,
"relation %s does not exist"
,
NameStr
(
*
relname
));
relnode
=
((
Form_pg_class
)
GETSTRUCT
(
tuple
))
->
relfilenode
;
if
(
relnode
==
InvalidOid
)
elog
(
ERROR
,
"invalid relation node id"
);
heap_endscan
(
scan
);
heap_close
(
relation
,
NoLock
);
relnode
=
relation
->
rd_rel
->
relfilenode
;
totalsize
=
0
;
segcount
=
0
;
...
...
@@ -158,12 +151,14 @@ relation_size(PG_FUNCTION_ARGS)
if
(
errno
==
ENOENT
)
break
;
else
elog
(
ERROR
,
"could not stat %s: %
s"
,
fullname
,
strerror
(
errno
)
);
elog
(
ERROR
,
"could not stat %s: %
m"
,
fullname
);
}
totalsize
+=
statbuf
.
st_size
;
pfree
(
fullname
);
segcount
++
;
}
relation_close
(
relation
,
AccessShareLock
);
PG_RETURN_INT64
(
totalsize
);
}
contrib/dbsize/dbsize.sql.in
View file @
688781d4
CREATE FUNCTION database_size (name) RETURNS bigint
AS '
@MODULE_FILENAME@
', 'database_size'
AS '
MODULE_PATHNAME
', 'database_size'
LANGUAGE C WITH (isstrict);
CREATE FUNCTION relation_size (
name
) RETURNS bigint
AS '
@MODULE_FILENAME@
', 'relation_size'
CREATE FUNCTION relation_size (
text
) RETURNS bigint
AS '
MODULE_PATHNAME
', 'relation_size'
LANGUAGE C WITH (isstrict);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment