Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/build-cloudberry-rocky8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ jobs:
"make_configs":["gpcontrib/gp_stats_collector:installcheck"],
"extension":"gp_stats_collector"
},
{"test":"gpcontrib-gp-relsizes-stats",
"make_configs":["gpcontrib/gp_relsizes_stats:installcheck"],
"extension":"gp_relsizes_stats"
},
{"test":"ic-fixme",
"make_configs":["src/test/regress:installcheck-fixme"],
"enable_core_check":false
Expand Down Expand Up @@ -1445,6 +1449,17 @@ jobs:
exit 1
fi
;;
gp_relsizes_stats)
if ! su - gpadmin -c "source ${BUILD_DESTINATION}/cloudberry-env.sh && \
source ${SRC_DIR}/gpAux/gpdemo/gpdemo-env.sh && \
echo 'CREATE EXTENSION IF NOT EXISTS gp_relsizes_stats; \
TABLE pg_extension;' | \
psql postgres"
then
echo "Error creating gp_relsizes_stats extension"
exit 1
fi
;;
*)
echo "Unknown extension: ${{ matrix.extension }}"
exit 1
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/build-cloudberry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ jobs:
"make_configs":["gpcontrib/gp_stats_collector:installcheck"],
"extension":"gp_stats_collector"
},
{"test":"gpcontrib-gp-relsizes-stats",
"make_configs":["gpcontrib/gp_relsizes_stats:installcheck"],
"extension":"gp_relsizes_stats"
},
{"test":"ic-expandshrink",
"make_configs":["src/test/isolation2:installcheck-expandshrink"]
},
Expand Down Expand Up @@ -1457,6 +1461,17 @@ jobs:
exit 1
fi
;;
gp_relsizes_stats)
if ! su - gpadmin -c "source ${BUILD_DESTINATION}/cloudberry-env.sh && \
source ${SRC_DIR}/gpAux/gpdemo/gpdemo-env.sh && \
echo 'CREATE EXTENSION IF NOT EXISTS gp_relsizes_stats; \
TABLE pg_extension;' | \
psql postgres"
then
echo "Error creating gp_relsizes_stats extension"
exit 1
fi
;;
*)
echo "Unknown extension: ${{ matrix.extension }}"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions gpcontrib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ifeq "$(enable_debug_extensions)" "yes"
gp_inject_fault \
gp_exttable_fdw \
gp_legacy_string_agg \
gp_relsizes_stats \
Comment thread
tuhaihe marked this conversation as resolved.
gp_replica_check \
gp_toolkit \
pg_hint_plan
Expand All @@ -30,6 +31,7 @@ else
gp_distribution_policy \
gp_internal_tools \
gp_legacy_string_agg \
gp_relsizes_stats \
gp_exttable_fdw \
gp_toolkit \
pg_hint_plan
Expand Down
192 changes: 192 additions & 0 deletions gpcontrib/gp_relsizes_stats/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

6 changes: 6 additions & 0 deletions gpcontrib/gp_relsizes_stats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.o
*.so
src/protos/
results
.vscode
compile_commands.json
43 changes: 43 additions & 0 deletions gpcontrib/gp_relsizes_stats/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#-------------------------------------------------------------------------
#
# Makefile for gp_relsizes_stats extension.
#
# By default this Makefile is intended to be included from the surrounding
# Cloudberry source tree (in-tree build); pass USE_PGXS=1 to build against an
# already-installed Cloudberry/PostgreSQL using pg_config.
#
# IDENTIFICATION
# gpcontrib/gp_relsizes_stats/Makefile
#
#-------------------------------------------------------------------------

MODULE_big = gp_relsizes_stats
OBJS = ./src/gp_relsizes_stats.o
EXTENSION = gp_relsizes_stats
EXTVERSION = 1.0
DATA = $(wildcard sql/*--*.sql)
REGRESS = grants gp_relsizes_stats
REGRESS_OPTS = --inputdir=test/
PGFILEDESC = "gp_relsizes_stats - an extension to track table on-disc sizes in Cloudberry"
PG_CXXFLAGS += $(COMMON_CPP_FLAGS)

# Auto-detect build mode: if we are sitting inside a Cloudberry source tree
# (i.e. ../../src/Makefile.global is reachable), build in-tree; otherwise fall
# back to a standalone PGXS build driven by pg_config. USE_PGXS=1 forces PGXS
# even when an in-tree Makefile.global is available.
ifeq ($(USE_PGXS),)
ifeq ($(wildcard ../../src/Makefile.global),)
USE_PGXS = 1
endif
endif

ifdef USE_PGXS
PG_CONFIG ?= pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = gpcontrib/gp_relsizes_stats
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
70 changes: 70 additions & 0 deletions gpcontrib/gp_relsizes_stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# gp_relsizes_stats: Table sizes monitoring tool for Cloudberry

### Features
gp_relsizes_stats is an extension for the Cloudberry database that calculates and stores statistics on the size of files and tables, occupied space on the disks of the master and segment hosts.

#### Features include
- BackgroundWorker support for collecting statistics automatically
- the ability to fine-tune the timeout values between actions, for example, between launches for different databases, or during file processing to distribute the load over time

### Supported versions and platforms
At the moment, the program is being tested only for Cloudberry and Linux.

### Installation
This extension is part of the Cloudberry monorepo under `gpcontrib/gp_relsizes_stats`.

Build and install from the Cloudberry monorepo root:
```bash
make -C gpcontrib/gp_relsizes_stats
sudo make -C gpcontrib/gp_relsizes_stats install
```

### Configuration
gp_relsizes_stats configuration parameters:
| **Parameter** | **Type** | **Default** | **Description** |
| ---------------- | --------------- | ------------ | ------------ |
| `gp_relsizes_stats.enabled` | bool | false | Using `gp_relsizes_stats.enabled` you can enable/disable background stats collection for database where extension installed (actually enable/disable background worker which collecting stats).|
| `gp_relsizes_stats.restart_naptime` | int | 21600000 | Using `gp_relsizes_stats.restart_naptime` you can set naptime between each startup of collecting process. Value set time in milliseconds. Default is equal to 6 hours.|
| `gp_relsizes_stats.database_naptime` | int | 0 | Using `gp_relsizes_stats.database_naptime` you can set naptime between collecting stats for each databases. Value set time in milliseconds. Default is equal to 0 milliseconds.|
| `gp_relsizes_stats.file_naptime` | int | 1 | Using `gp_relsizes_stats.file_naptime` you can set naptime between each file stats calculating. Value set time in milliseconds. Default is equal to 1 millisecond.|

### Usage
You can use a background worker to collect statistics, but if you sometimes need to change the format of the settings or if you don't want to collect statistics on a regular basis, you can do so. In these situations, you could set
```
gp_relsizes_stats.enabled = off
```

And use the function
```
relsizes_stats_schema.relsizes_collect_stats_once()
```
which can be called manually using 'select'.
It will launch a single statistics collection procedure.


### About collected data and tables
| Name of table | Row description | Description |
| ------------- | --------------- | ----------- |
| relsizes_stats_schema.segment_file_sizes | (segment, relfilenode, filepath, size, mtime) | Current size and last modify time of each file of specific relation on specific segment |
| relsizes_stats_schema.namespace_sizes | (nspname, nspsize) | Current size of namespace |
| relsizes_stats_schema.table_sizes | (nspname, relname, relsize) | Current size of relation in specific namespace |
| relsizes_stats_schema.table_sizes_history | (insert_date, nspname, relname, size, mtime) | Size and last modify time of relation in specific namespace with date when information was collected |
5 changes: 5 additions & 0 deletions gpcontrib/gp_relsizes_stats/gp_relsizes_stats.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# gp_relsizes_stats extension
comment = 'gp_relsizes_stats - an extension to track table on-disc sizes in cloudberry'
default_version = '1.0'
module_pathname = '$libdir/gp_relsizes_stats'
trusted = true
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it as it was in greenplum

Loading
Loading