The gp_toolkit Administrative Schema
Apache Cloudberry provides an administrative schema called gp_toolkit that you can use to query the system catalogs, log files, and operating environment for system status information. The gp_toolkit schema contains a number of views that you can access using SQL commands. The gp_toolkit schema is accessible to all database users, although some objects may require superuser permissions. For convenience, you may want to add the gp_toolkit schema to your schema search path. For example:
=> ALTER ROLE myrole SET search_path TO myschema,gp_toolkit;
This document describes the most useful views and user-defined functions (UDFs) in gp_toolkit. You may notice other objects (views, functions, and external tables) within the gp_toolkit schema that are not described in this documentation (these are supporting objects to the views described in this section).
Do not change database objects in the gp_toolkit schema. Do not create database objects in the schema. Changes to objects in the schema might affect the accuracy of administrative information returned by schema objects. Any changes made in the gp_toolkit schema are lost when the database is backed up and then restored with the gpbackup and gprestore utilities.
These are the categories for views in the gp_toolkit schema.
- Check for tables that need routine maintenance
- Check for locks
- Check append-optimized tables
- View server log files
- Check server configuration files
- Check for failed segments
- Check resource group activity and status
- Check resource queue activity and status
- Check query disk spill space usage
- View users and groups (roles)
- Check database object sizes and disk space
- Check for missing and orphaned data files
- Move orphaned data files
- Check for uneven data distribution
- Maintain partitions
About the extension
gp_toolkit is implemented as an extension in Apache Cloudberry v2.0.0. Because this extension is registered in the template1 database, it is both registered an immediately available to use in every Apache Cloudberry database that you create.
Upgrade the extension
The gp_toolkit extension is installed when you install or upgrade Apache Cloudberry. A previous version of the extension will continue to work in existing databases after you upgrade Apache Cloudberry. To upgrade to the most recent version of the extension, you must:
ALTER EXTENSION gp_toolkit UPDATE TO '1.4';
in every database in which you use the extension.
Check for tables that need routine maintenance
The following views can help identify tables that need routine table maintenance (VACUUM and/or ANALYZE).
The VACUUM or VACUUM FULL command reclaims disk space occupied by deleted or obsolete rows. Because of the MVCC transaction concurrency model used in Apache Cloudberry, data rows that are deleted or updated still occupy physical space on disk even though they are not visible to any new transactions. Expired rows increase table size on disk and eventually slow down scans of the table.
The ANALYZE command collects column-level statistics needed by the query optimizer. Apache Cloudberry uses a cost-based query optimizer that relies on database statistics. Accurate statistics allow the query optimizer to better estimate selectivity and the number of rows retrieved by a query operation in order to choose the most efficient query plan.
gp_bloat_diag
This view shows regular heap-storage tables that have bloat (the actual number of pages on disk exceeds the expected number of pages given the table statistics). Tables that are bloated require a VACUUM or a VACUUM FULL in order to reclaim disk space occupied by deleted or obsolete rows. This view is accessible to all users, however non-superusers will only be able to see the tables that they have permission to access.
Note
For diagnostic functions that return append-optimized table information, see Check append-optimized tables.
The columns of this view are described as follows:
bdirelid: Table object id.bdinspname: Schema name.bdirelname: Table name.bdirelpages: Actual number of pages on disk.bdiexppages: Expected number of pages given the table data.bdidiag: Bloat diagnostic message.
gp_stats_missing
This view shows tables that do not have statistics and therefore may require an ANALYZE be run on the table.
The columns of this view are described as follows:
smischema: Schema name.smitable: Table name.smisize: Does this table have statistics? False if the table does not have row count and row sizing statistics recorded in the system catalog, which may indicate that the table needs to be analyzed. This will also be false if the table does not contain any rows. For example, the parent tables of partitioned tables are always empty and will always return a false result.smicols: Number of columns in the table.smirecs: The total number of columns in the table that have statistics recorded.
Check for locks
When a transaction accesses a relation (such as a table), it acquires a lock. Depending on the type of lock acquired, subsequent transactions may have to wait before they can access the same relation. For more information on the types of locks, see the Transaction. Apache Cloudberry resource queues (used for resource management) also use locks to control the admission of queries into the system.
The gp_locks_* family of views can help diagnose queries and sessions that are waiting to access an object due to a lock.
gp_locks_on_relation
This view shows any locks currently being held on a relation, and the associated session information about the query associated with the lock. For more information on the types of locks, see the Transaction. This view is accessible to all users, however non-superusers will only be able to see the locks for relations that they have permission to access.
The columns of this view are described as follows:
lorlocktype: Type of the lockable object:relation,extend,page,tuple,transactionid,object,userlock,resource queue, oradvisory.lordatabase: Object ID of the database in which the object exists, zero if the object is a shared object.lorrelname: The name of the relation.lorrelation: The object ID of the relation.lortransaction: The transaction ID that is affected by the lock.lorpid: Process ID of the server process holding or awaiting this lock.NULLif the lock is held by a prepared transaction.lormode: Name of the lock mode held or desired by this process.lorgranted: Displays whether the lock is granted (true) or not granted (false).lorcurrentquery: The current query in the session.
gp_locks_on_resqueue
The gp_locks_on_resqueue view is valid only when resource queue-based resource management is active.
This view shows any locks currently being held on a resource queue, and the associated session information about the query associated with the lock. This view is accessible to all users, however non-superusers will only be able to see the locks associated with their own sessions.
The columns of this view are described as follows:
lorusename: Name of the user running the session.lorrsqname: The resource queue name.lorlocktype: Type of the lockable object:resource queue.lorobjid: The ID of the locked transaction.lortransaction: The ID of the transaction that is affected by the lock.lorpid: The process ID of the transaction that is affected by the lock.lormode: The name of the lock mode held or desired by this process.lorgranted: Displays whether the lock is granted (true) or not granted (false).lorwaiteventtype: The type of waiting event (for example, I/O, lock, network).lorwaitevent: The name or description of the waiting event (for example, the I/O operation or lock object of a file).
Check append-optimized tables
The gp_toolkit schema includes a set of diagnostic functions you can use to investigate the state of append-optimized tables.
When an append-optimized table (or column-oriented append-optimized table) is created, another table is implicitly created, containing metadata about the current state of the table. The metadata includes information such as the number of records in each of the table's segments.
Append-optimized tables may have non-visible rows—rows that have been updated or deleted, but remain in storage until the table is compacted using VACUUM. The hidden rows are tracked using an auxiliary visibility map table, or visimap.
The following functions let you access the metadata for append-optimized and column-oriented tables and view non-visible rows.
For most of the functions, the input argument is regclass, either the table name or the oid of a table.
__gp_aovisimap_compaction_info(oid)
This function displays compaction information for an append-optimized table. The information is for the on-disk data files on database segments that store the table data. You can use the information to determine the data files that will be compacted by a VACUUM operation on an append-optimized table.
Until a VACUUM operation deletes the row from the data file, deleted or updated data rows occupy physical space on disk even though they are hidden to new transactions. The configuration parameter gp_appendonly_compaction controls the functionality of the VACUUM command.
This table describes the __gp_aovisimap_compaction_info function output table. The columns of this table are described as follows:
content: Database segment ID.datafile: ID of the data file on the segment.compaction_possible: The value is eithertorf. The valuetindicates that the data in data file be compacted when a VACUUM operation is performed. The server configuration parametergp_appendonly_compaction_thresholdaffects this value.hidden_tupcount: In the data file, the number of hidden (deleted or updated) rows.total_tupcount: In the data file, the total number of rows.percent_hidden: In the data file, the ratio (as a percentage) of hidden (deleted or updated) rows to total rows.
__gp_aoseg(regclass)
This function returns metadata information contained in the append-optimized table's on-disk segment file.
The input argument is the name or the oid of an append-optimized table. The columns of the output are described as follows:
segment_id: The ID of the data segment in the cluster.segno: The file segment number.eof: The effective end of file for this file segment.tupcount: The total number of tuples in the segment, including invisible tuples.varblockcount: The total number of varblocks in the file segment.eof_uncompressed: The end of file if the file segment were uncompressed.modcount: The number of data modification operations.formatversion: The version of the AO file storage format, which indicates the format version of the file.state: The state of the file segment. Indicates if the segment is active or ready to be dropped after compaction.
__gp_aoseg_history(regclass)
This function returns metadata information contained in the append-optimized table's on-disk segment file. It displays all different versions (heap tuples) of the aoseg meta information. The data is complex, but users with a deep understanding of the system may find it useful for debugging.
The input argument is the name or the oid of an append-optimized table. The columns of the output are described as follows:
segment_id: The ID of the data segment in the cluster.segno: The number of the segment in the segment file.tupcount: The number of tuples, including hidden tuples.eof: The effective end of file for the segment.eof_uncompressed: The end of file for the segment if data were uncompressed.modcount: A count of data modifications.formatversion: The version of the AO file storage format, which indicates the format version of the file.state: The status of the segment.
__gp_aocsseg(regclass)
This function returns metadata information contained in a column-oriented append-optimized table's on-disk segment file, excluding non-visible rows. Each row describes a segment for a column in the table.
The input argument is the name or the oid of a column-oriented append-optimized table. The columns of the output are described as follows:
segment_id: The ID of the data segment in the cluster.segno: The segment number.column_num: The column number.physical_segno: The number of the segment in the segment file.tupcount: The number of rows in the segment, excluding hidden tuples.eof: The effective end of file for the segment.eof_uncompressed: The end of file for the segment if the data were uncompressed.modcount: A count of data modification operations for the segment.formatversion: The version of the AO file storage format, which indicates the format version of the file.state: The status of the segment.
__gp_aocsseg_history(regclass)
This function returns metadata information contained in a column-oriented append-optimized table's on-disk segment file. Each row describes a segment for a column in the table. The data is complex, but users with a deep understanding of the system may find it useful for debugging.
The input argument is the name or the oid of a column-oriented append-optimized table. The columns of the output are described as follows:
segment_id: The ID of the data segment in the cluster.segno: The segment number in the segment file.column_num: The column number.physical_segno: The segment containing data for the column.tupcount: The total number of tuples in the segment.eof: The effective end of file for the segment.eof_uncompressed: The end of file for the segment if the data were uncompressed.modcount: A count of the data modification operations.formatversion: The version of the AO file storage format, which indicates the format version of the file.state: The state of the segment.
__gp_aovisimap(regclass)
This function returns the tuple ID, the segment file, and the row number of each non-visible tuple according to the visibility map.
The input argument is the name or the oid of an append-optimized table. The columns of the output are described as follows:
tid: The tuple id.segno: The number of the segment file.row_num: The row number of a row that has been deleted or updated.
__gp_aovisimap_hidden_info(regclass)
This function returns the numbers of hidden and visible tuples in the segment files for an append-optimized table.
The input argument is the name or the oid of an append-optimized table. The columns of the output are described as follows:
segno: The number of the segment file.hidden_tupcount: The number of hidden tuples in the segment file.total_tupcount: The total number of tuples in the segment file.
__gp_aovisimap_entry(regclass)
This function returns information about each visibility map entry for the table.
The input argument is the name or the oid of an append-optimized table. The columns of the output are described as follows:
segno: Segment number of the visibility map entry.first_row_num: The first row number of the entry.hidden_tupcount: The number of hidden tuples in the entry.bitmap: A text representation of the visibility bitmap.
__gp_aoblkdir(regclass)
For a given AO/AOCO table that had or has an index, this function returns a row for each block directory entry recorded in the block directory relation; it flattens the minipage column of block directory relations and returns a row for each minipage entry.
The input argument is the name or the oid of an append-optimized table.
You must execute this function in utility mode against every segment, or with gp_dist_random() as shown here:
SELECT (gp_toolkit.__gp_aoblkdir('<table_name>')).*
FROM gp_dist_random('gp_id');
The columns of the output are described as follows:
tupleid: The tuple id of the block directory row containing this block directory entry.segno: The physical segment file number.columngroup_no: Theattnumof the column described by thisminipageentry (always0for row-oriented tables).entry_no: The entry serial number inside thisminipagecontaining this block directory entry.first_row_no: The first row number of the rows covered by this block directory entry.file_offset: The starting file offset of the rows covered by this block directory entry.row_count: The count of rows covered by this block directory entry.
get_column_size(oid)
For a given AOCO table, this function returns the column size and compression ratio for all columns in the table.
The input argument is the object identifier of a column-oriented append-optimized table. The columns of the output are described as follows:
segment: The segment id.attnum: The attribute number of the column.size: The size of the column in bytes.size_uncompressed: The size of the column in bytes if the column was not compressed.compression_ratio: The compression ratio.
gp_column_size
This view gathers the column size and compression ratio for column-oriented append-optimized tables from all segments. The columns of the view are described as follows:
gp_segment_id: Segment ID.relid: The object identifier (OID) of the table.schema: The schema to which the table belongs.relname: The table name.attnum: The attribute number of the column.attname: The column name.size: The size of the column in bytes.size_uncompressed: The size of the column in bytes if the column was not compressed.compression_ratio: The compression ratio.
gp_column_size_summary
This view shows a summary of the gp_column_size view. It aggregates the column size and compression ratio for each column in each column-oriented append-optimized table from all segments. The columns of the view are described as follows:
relid: The object identifier (OID) of the table.schema: The schema to which the table belongs.relname: The table name.attnum: The attribute number of the column.attname: The column name.size: The size of the column in bytes.size_uncompressed: The size of the column in bytes if the column were uncompressed.compression_ratio: The compression ratio.
View server log files
Each component of a Apache Cloudberry system (coordinator, standby coordinator, primary segments, and mirror segments) keeps its own server log files. The gp_log_* family of views allows you to issue SQL queries against the server log files to find particular entries of interest. The use of these views require superuser permissions.
gp_log_command_timings
This view uses an external table to read the log files on the coordinator and report the run time of SQL commands in a database session. The use of this view requires superuser permissions. The columns of the view are described as follows:
logsession: The session identifier (prefixed with "con").logcmdcount: The command number within a session (prefixed with "cmd").logdatabase: The name of the database.loguser: The name of the database user.logpid: The process id (prefixed with "p").logtimemin: The time of the first log message for this command.logtimemax: The time of the last log message for this command.logduration: Statement duration from start to end time.
gp_log_database
This view uses an external table to read the server log files of the entire Apache Cloudberry system (coordinator, segments, and mirrors) and lists log entries associated with the current database. Associated log entries can be identified by the session id (logsession) and command id (logcmdcount). The use of this view requires superuser permissions. The columns of the view are described as follows:
logtime: The timestamp of the log message.loguser: The name of the database user.logdatabase: The name of the database.logpid: The associated process id (prefixed with "p").logthread: The associated thread count (prefixed with "th").loghost: The segment or coordinator host name.logport: The segment or coordinator port.logsessiontime: Time session connection was opened.logtransaction: Global transaction id.logsession: The session identifier (prefixed with "con").logcmdcount: The command number within a session (prefixed with "cmd").logsegment: The segment content identifier (prefixed with "seg" for primary or "mir" for mirror. The coordinator always has a content id of -1).logslice: The slice id (portion of the query plan being run).logdistxact: Distributed transaction id.loglocalxact: Local transaction id.logsubxact: Subtransaction id.logseverity: LOG, ERROR, FATAL, PANIC, DEBUG1 or DEBUG2.logstate: SQL state code associated with the log message.logmessage: Log or error message text.logdetail: Detail message text associated with an error message.loghint: Hint message text associated with an error message.logquery: The internally-generated query text.logquerypos: The cursor index into the internally-generated query text.logcontext: The context in which this message gets generated.logdebug: Query string with full detail for debugging.logcursorpos: The cursor index into the query string.logfunction: The function in which this message is generated.logfile: The log file in which this message is generated.logline: The line in the log file in which this message is generated.logstack: Full text of the stack trace associated with this message.
gp_log_coordinator_concise
This view uses an external table to read a subset of the log fields from the coordinator log file. The use of this view requires superuser permissions. The columns of the view are described as follows:
logtime: The timestamp of the log message.logdatabase: The name of the database.logsession: The session identifier (prefixed with "con").logcmdcount: The command number within a session (prefixed with "cmd").logseverity: The log severity level.logmessage: Log or error message text.
gp_log_system
This view uses an external table to read the server log files of the entire Apache Cloudberry system (coordinator, segments, and mirrors) and lists all log entries. Associated log entries can be identified by the session id (logsession) and command id (logcmdcount). The use of this view requires superuser permissions. The columns of the view are described as follows:
logtime: The timestamp of the log message.loguser: The name of the database user.logdatabase: The name of the database.logpid: The associated process id (prefixed with "p").logthread: The associated thread count (prefixed with "th").loghost: The segment or coordinator host name.logport: The segment or coordinator port.logsessiontime: Time session connection was opened.logtransaction: Global transaction id.logsession: The session identifier (prefixed with "con").logcmdcount: The command number within a session (prefixed with "cmd").logsegment: The segment content identifier (prefixed with "seg" for primary or "mir" for mirror. The coordinator always has a content id of -1).logslice: The slice id (portion of the query plan being run).logdistxact: Distributed transaction id.loglocalxact: Local transaction id.logsubxact: Subtransaction id.logseverity: LOG, ERROR, FATAL, PANIC, DEBUG1 or DEBUG2.logstate: SQL state code associated with the log message.logmessage: Log or error message text.logdetail: Detail message text associated with an error message.loghint: Hint message text associated with an error message.logquery: The internally-generated query text.logquerypos: The cursor index into the internally-generated query text.logcontext: The context in which this message gets generated.logdebug: Query string with full detail for debugging.logcursorpos: The cursor index into the query string.logfunction: The function in which this message is generated.logfile: The log file in which this message is generated.logline: The line in the log file in which this message is generated.logstack: Full text of the stack trace associated with this message.
Check server configuration files
Each component of a Apache Cloudberry system (coordinator, standby coordinator, primary segments, and mirror segments) has its own server configuration file (postgresql.conf). The following gp_toolkit objects can be used to check parameter settings across all primary postgresql.conf files in the system:
gp_param_setting('parameter_name')
This function takes the name of a server configuration parameter and returns the postgresql.conf value for the coordinator and each active segment. This function is accessible to all users. The columns of the view are described as follows:
paramsegment: The segment content id (only active segments are shown). The coordinator content id is always -1.paramname: The name of the parameter.paramvalue: The value of the parameter.
Example:
SELECT * FROM gp_toolkit.gp_param_setting('max_connections');
gp_param_settings_seg_value_diffs
Server configuration parameters that are classified as local parameters (meaning each segment gets the parameter value from its own postgresql.conf file), should be set identically on all segments. This view shows local parameter settings that are inconsistent. Parameters that are supposed to have different values (such as port) are not included. This view is accessible to all users.
The columns of the view are described as follows:
psdname: The name of the parameter.psdvalue: The value of the parameter.psdcount: The number of segments that have this value.
Check for failed segments
The gp_pgdatabase_invalid view can be used to check for down segments.
gp_pgdatabase_invalid
This view shows information about segments that are marked as down in the system catalog. This view is accessible to all users. The columns of the view are described as follows:
pgdbidbid: The segment dbid. Every segment has a unique dbid.pgdbiisprimary: Is the segment currently acting as the primary (active) segment? (t or f).pgdbicontent: The content id of this segment. A primary and mirror will have the same content id.pgdbivalid: Is this segment up and valid? (t or f).pgdbidefinedprimary: Was this segment assigned the role of primary at system initialization time? (t or f).
Check resource group activity and status
Note
The resource group activity and status views described in this section are valid only when resource group-based resource management is active.
Resource groups manage transactions to avoid exhausting system CPU and memory resources. Every database user is assigned a resource group. Apache Cloudberry evaluates every transaction submitted by a user against the limits configured for the user's resource group before running the transaction.
You can use the gp_resgroup_config view to check the configuration of each resource group. You can use the gp_resgroup_status* views to display the current transaction status and resource usage of each resource group.
gp_resgroup_configgp_resgroup_rolegp_resgroup_statusgp_resgroup_status_per_hostgp_resgroup_status_per_segment
gp_resgroup_config
The gp_resgroup_config view allows administrators to see the current CPU, memory, and concurrency limits for a resource group.
This view is accessible to all users. The columns of the view are described as follows:
groupid: The ID of the resource group.groupname: The name of the resource group.concurrency: The concurrency (CONCURRENCY) value specified for the resource group.cpu_max_percent: The CPU limit (CPU_MAX_PERCENT) value specified for the resource group, or-1.cpu_weight: The scheduling priority of the resource group (CPU_WEIGHT).cpuset: The CPU cores reserved for the resource group (CPUSET), or -1.memory_quota: The memory limit value specified for the resource group.min_cost: The minimum cost of a query plan to be included in the resource group (MIN_COST).io_limit: The maximum read/write sequential disk I/O throughput, and the maximum read/write I/O operations per second for the queries assigned to a specific tablespace (shown as the tablespace oid) and resource group (IO_LIMIT).
gp_resgroup_role
The gp_resgroup_role view allows administrators to see the resource group assigned to every role.
This view is accessible to all users. The columns of the view are described as follows:
rrrolname: The name of the role.rrrsgname: The name of the resource group.
gp_resgroup_status
The gp_resgroup_status view allows administrators to see status and activity for a resource group. It shows how many queries are waiting to run and how many queries are currently active in the system for each resource group. The view also displays current memory and CPU usage for the resource group.
Resource groups use the Linux control groups (cgroups) configured on the host systems. The cgroups are used to manage host system resources. When resource groups use cgroups that are as part of a nested set of cgroups, resource group limits are relative to the parent cgroup allotment. For information about nested cgroups and Apache Cloudberry resource group limits, see the Use Resource Groups document.
This view is accessible to all users. The columns of the view are described as follows:
groupid: The ID of the resource group.groupname: The name of the resource group.num_running: The number of transactions currently running in the resource group.num_queueing: The number of currently queued transactions for the resource group.num_queued: The total number of queued transactions for the resource group since the Apache Cloudberry cluster was last started, excluding the num_queueing.num_executed: The total number of transactions run in the resource group since the Apache Cloudberry cluster was last started, excluding the num_running.total_queue_duration: The total time any transaction was queued since the Apache Cloudberry cluster was last started.
Sample output for the gp_resgroup_status view:
select * from gp_toolkit.gp_resgroup_status;
groupid | groupname | num_running | num_queueing | num_queued | num_executed | total_queue_duration
---------+-----------+-------------+--------------+------------+--------------+----------------------
(0 rows)