Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
688781d4
Commit
688781d4
authored
23 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Fix contrib/dbsize for schema-qualified table names.
parent
1dc43ea7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
contrib/dbsize/dbsize.c
+23
-28
23 additions, 28 deletions
contrib/dbsize/dbsize.c
contrib/dbsize/dbsize.sql.in
+3
-3
3 additions, 3 deletions
contrib/dbsize/dbsize.sql.in
with
26 additions
and
31 deletions
contrib/dbsize/dbsize.c
+
23
−
28
View file @
688781d4
#include
"postgres.h"
#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
<sys/types.h>
#include
<dirent.h>
#include
<dirent.h>
#include
<sys/stat.h>
#include
<sys/stat.h>
#include
<unistd.h>
#include
<unistd.h>
#include
<errno.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
*
static
char
*
psnprintf
(
size_t
len
,
const
char
*
fmt
,...)
psnprintf
(
size_t
len
,
const
char
*
fmt
,...)
...
@@ -38,6 +39,8 @@ psnprintf(size_t len, const char *fmt,...)
...
@@ -38,6 +39,8 @@ psnprintf(size_t len, const char *fmt,...)
PG_FUNCTION_INFO_V1
(
database_size
);
PG_FUNCTION_INFO_V1
(
database_size
);
Datum
database_size
(
PG_FUNCTION_ARGS
);
Datum
Datum
database_size
(
PG_FUNCTION_ARGS
)
database_size
(
PG_FUNCTION_ARGS
)
{
{
...
@@ -107,39 +110,29 @@ 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
);
PG_FUNCTION_INFO_V1
(
relation_size
);
Datum
relation_size
(
PG_FUNCTION_ARGS
);
Datum
Datum
relation_size
(
PG_FUNCTION_ARGS
)
relation_size
(
PG_FUNCTION_ARGS
)
{
{
Name
relname
=
PG_GETARG_
NAME
(
0
);
text
*
relname
=
PG_GETARG_
TEXT_P
(
0
);
HeapTuple
tuple
;
RangeVar
*
relrv
;
Relation
relation
;
Relation
relation
;
ScanKeyData
scanKey
;
HeapScanDesc
scan
;
Oid
relnode
;
Oid
relnode
;
int64
totalsize
;
int64
totalsize
;
unsigned
int
segcount
;
unsigned
int
segcount
;
relation
=
heap_openr
(
RelationRelationName
,
AccessShareLock
);
relrv
=
makeRangeVarFromNameList
(
textToQualifiedNameList
(
relname
,
ScanKeyEntryInitialize
(
&
scanKey
,
0
,
Anum_pg_class_relname
,
"relation_size"
));
F_NAMEEQ
,
NameGetDatum
(
relname
));
relation
=
relation_openrv
(
relrv
,
AccessShareLock
);
scan
=
heap_beginscan
(
relation
,
0
,
SnapshotNow
,
1
,
&
scanKey
);
tuple
=
heap_getnext
(
scan
,
0
);
if
(
!
HeapTupleIsValid
(
tuple
))
elog
(
ERROR
,
"relation %s does not exist"
,
NameStr
(
*
relname
));
relnode
=
((
Form_pg_class
)
GETSTRUCT
(
tuple
))
->
relfilenode
;
relnode
=
relation
->
rd_rel
->
relfilenode
;
if
(
relnode
==
InvalidOid
)
elog
(
ERROR
,
"invalid relation node id"
);
heap_endscan
(
scan
);
heap_close
(
relation
,
NoLock
);
totalsize
=
0
;
totalsize
=
0
;
segcount
=
0
;
segcount
=
0
;
...
@@ -158,12 +151,14 @@ relation_size(PG_FUNCTION_ARGS)
...
@@ -158,12 +151,14 @@ relation_size(PG_FUNCTION_ARGS)
if
(
errno
==
ENOENT
)
if
(
errno
==
ENOENT
)
break
;
break
;
else
else
elog
(
ERROR
,
"could not stat %s: %
s
"
,
fullname
,
strerror
(
errno
)
);
elog
(
ERROR
,
"could not stat %s: %
m
"
,
fullname
);
}
}
totalsize
+=
statbuf
.
st_size
;
totalsize
+=
statbuf
.
st_size
;
pfree
(
fullname
);
pfree
(
fullname
);
segcount
++
;
segcount
++
;
}
}
relation_close
(
relation
,
AccessShareLock
);
PG_RETURN_INT64
(
totalsize
);
PG_RETURN_INT64
(
totalsize
);
}
}
This diff is collapsed.
Click to expand it.
contrib/dbsize/dbsize.sql.in
+
3
−
3
View file @
688781d4
CREATE FUNCTION database_size (name) RETURNS bigint
CREATE FUNCTION database_size (name) RETURNS bigint
AS '
@
MODULE_
FILE
NAME
@
', 'database_size'
AS 'MODULE_
PATH
NAME', 'database_size'
LANGUAGE C WITH (isstrict);
LANGUAGE C WITH (isstrict);
CREATE FUNCTION relation_size (
name
) RETURNS bigint
CREATE FUNCTION relation_size (
text
) RETURNS bigint
AS '
@
MODULE_
FILE
NAME
@
', 'relation_size'
AS 'MODULE_
PATH
NAME', 'relation_size'
LANGUAGE C WITH (isstrict);
LANGUAGE C WITH (isstrict);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment