Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc5037c7

Browse files
committed
Add cfs_fragmentation function
1 parent7a12174 commitc5037c7

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

‎src/backend/storage/file/cfs.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,11 @@ static bool cfs_gc_file(char* map_path)
702702
endTime=GetCurrentTimestamp();
703703
TimestampDifference(startTime,endTime,&secs,&usecs);
704704

705-
elog(LOG,"%d: defragment file %s: old size %d, new size %d, logical size %d, used %d, compression ratio %f, time %ld usec",
706-
MyProcPid,file_path,physSize,newSize,virtSize,usedSize, (double)virtSize/newSize,
707-
secs*USECS_PER_SEC+usecs);
708-
705+
if (succeed) {
706+
elog(LOG,"%d: defragment file %s: old size %d, new size %d, logical size %d, used %d, compression ratio %f, time %ld usec",
707+
MyProcPid,file_path,physSize,newSize,virtSize,usedSize, (double)virtSize/newSize,
708+
secs*USECS_PER_SEC+usecs);
709+
}
709710
pfree(file_path);
710711
pfree(file_bck_path);
711712
pfree(map_bck_path);
@@ -839,6 +840,7 @@ PG_FUNCTION_INFO_V1(cfs_enable_gc);
839840
PG_FUNCTION_INFO_V1(cfs_version);
840841
PG_FUNCTION_INFO_V1(cfs_estimate);
841842
PG_FUNCTION_INFO_V1(cfs_compression_ratio);
843+
PG_FUNCTION_INFO_V1(cfs_fragmentation);
842844
PG_FUNCTION_INFO_V1(cfs_gc_activity_processed_bytes);
843845
PG_FUNCTION_INFO_V1(cfs_gc_activity_processed_pages);
844846
PG_FUNCTION_INFO_V1(cfs_gc_activity_processed_files);
@@ -985,6 +987,55 @@ Datum cfs_compression_ratio(PG_FUNCTION_ARGS)
985987
PG_RETURN_FLOAT8((double)virtSize/physSize);
986988
}
987989

990+
Datumcfs_fragmentation(PG_FUNCTION_ARGS)
991+
{
992+
Oidoid=PG_GETARG_OID(0);
993+
Relationrel=try_relation_open(oid,AccessShareLock);
994+
uint64usedSize=0;
995+
uint64physSize=0;
996+
997+
if (rel!=NULL) {
998+
char*path=relpathbackend(rel->rd_node,rel->rd_backend,MAIN_FORKNUM);
999+
char*map_path= (char*)palloc(strlen(path)+16);
1000+
inti=0;
1001+
1002+
while (true) {
1003+
intmd;
1004+
FileMap*map;
1005+
1006+
if (i==0) {
1007+
sprintf(map_path,"%s.cfm",path);
1008+
}else {
1009+
sprintf(map_path,"%s.%u.cfm",path,i);
1010+
}
1011+
md=open(map_path,O_RDWR|PG_BINARY,0);
1012+
if (md<0) {
1013+
break;
1014+
}
1015+
map=cfs_mmap(md);
1016+
if (map==MAP_FAILED) {
1017+
elog(LOG,"cfs_compression_ration failed to map file %s: %m",map_path);
1018+
close(md);
1019+
break;
1020+
}
1021+
usedSize+=pg_atomic_read_u32(&map->usedSize);
1022+
physSize+=pg_atomic_read_u32(&map->physSize);
1023+
1024+
if (cfs_munmap(map)<0) {
1025+
elog(LOG,"Failed to unmap file %s: %m",map_path);
1026+
}
1027+
if (close(md)<0) {
1028+
elog(LOG,"Failed to close file %s: %m",map_path);
1029+
}
1030+
i+=1;
1031+
}
1032+
pfree(path);
1033+
pfree(map_path);
1034+
relation_close(rel,AccessShareLock);
1035+
}
1036+
PG_RETURN_FLOAT8((double)physSize/usedSize);
1037+
}
1038+
9881039
Datumcfs_gc_activity_processed_bytes(PG_FUNCTION_ARGS)
9891040
{
9901041
PG_RETURN_INT64(cfs_state->gc_stat.processedBytes);

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5358,6 +5358,8 @@ DATA(insert OID = 6107 ( cfs_gc_activity_processed_pages PGNSP PGUID 12 1 0
53585358
DESCR("Number of transferred pages by CFS garbage collectors since system start");
53595359
DATA(insert OID = 6108 ( cfs_gc_activity_scanned_files PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 20 "" _null_ _null_ _null_ _null_ _null_ cfs_gc_activity_scanned_files _null_ _null_ _null_ ));
53605360
DESCR("Number of files scanned by CFS garbage collectors since system start");
5361+
DATA(insert OID = 6109 ( cfs_fragmentation PGNSP PGUID 12 1 0 0 0 f f f f t f v s 1 0 701 "2205" _null_ _null_ _null_ _null_ _null_ cfs_fragmentation _null_ _null_ _null_ ));
5362+
DESCR("Fragmentation level of relation");
53615363

53625364
/* distance functions */
53635365
DATA(insert OID = 3343 ( int2_distPGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 21 "21 21"_null_ _null_ _null_ _null_ _null_int2_dist_null_ _null_ _null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp