OTel postgresqlreceiver による metrics の計裝の仕方
metadata
各 metrics がどう計裝されてゐるかを見よう
實裝
databaseStats
getDatabaseStats
$ SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files, tup_updated, tup_returned, tup_fetched, tup_inserted, tup_deleted, blks_hit, blks_read FROM pg_stat_database
The pg_stat_database view will contain one row for each database in the cluster, plus one for shared objects, showing database-wide statistics.
pg_stat_database ビューには、クラスター内のデータベースごとに 1 つの行に加えて、共有オブジェクトごとに 1 つの行が含まれ、データベース全体の統計が表示されます。
resource_attributes postgresql.database.name
description: The name of the database.
datname
Name of this database, or NULL for shared objects.
postgresql.commits
The number of commits.
xact_commit
Number of transactions in this database that have been committed
postgresql.rollbacks
The number of rollbacks.
xact_rollback
Number of transactions in this database that have been rolled back
postgresql.deadlocks
The number of deadlocks.
deadlocks
Number of deadlocks detected in this database
postgresql.temp_files
The number of temp files.
temp_files
Number of temporary files created by queries in this database. All temporary files are counted, regardless of why the temporary file was created (e.g., sorting or hashing), and regardless of the log_temp_files setting.
このデータベース内のクエリによって作成された一時ファイルの数。一時ファイルが作成された理由(ソートやハッシュなど)や log_temp_files の設定に関係なく、すべての一時ファイルがカウントされます。
postgresql.tup_updated
Number of rows updated by queries in the database.
tup_updated
Number of rows updated by queries in this database
postgresql.tup_returned
Number of rows returned by queries in the database.
tup_returned
Number of live rows fetched by sequential scans and index entries returned by index scans in this database
このデータベース内のシーケンシャル スキャンによってフェッチされたライブ行とインデックス スキャンによって返されたインデックス エントリの数
postgresql.tup_fetched
Number of rows fetched by queries in the database.
tup_fetched
Number of live rows fetched by index scans in this database
postgresql.tup_inserted
Number of rows inserted by queries in the database.
tup_inserted
Number of rows inserted by queries in this database
postgresql.tup_deleted
Number of rows deleted by queries in the database.
tup_deleted
Number of rows deleted by queries in this database
postgresql.blks_hit
Number of times disk blocks were found already in the buffer cache.
blks_hit
Number of times disk blocks were found already in the buffer cache, so that a read was not necessary (this only includes hits in the PostgreSQL buffer cache, not the operating system's file system cache)
バッファキャッシュに既にディスクブロックが見つかった回数が多いため、読み取りは必要ありませんでした(これには、PostgreSQL バッファキャッシュのヒットのみが含まれ、オペレーティングシステムのファイルシステムキャッシュは含まれません)
postgresql.blks_read
Number of disk blocks read in this database.
blks_read
Number of disk blocks read in this database
getDatabaseLocks
code:sql
SELECT relname AS relation, mode, locktype,COUNT(pid)
AS locks FROM pg_locks
JOIN pg_class ON pg_locks.relation = pg_class.oid
GROUP BY relname, mode, locktype;
The view pg_locks provides access to information about the locks held by active processes within the database server. See Chapter 13 for more discussion of locking.
ビュー pg_locks は、データベース サーバー内のアクティブなプロセスによって保持されているロックに関する情報へのアクセスを提供します。ロックの詳細については、第 13 章を参照してください。
The catalog pg_class describes tables and other objects that have columns or are otherwise similar to a table. This includes indexes (but see also pg_index), sequences (but see also pg_sequence), views, materialized views, composite types, and TOAST tables; see relkind. Below, when we mean all of these kinds of objects we speak of “relations”. Not all of pg_class's columns are meaningful for all relation kinds.
カタログ pg_class は、列を持つテーブルやその他のオブジェクト、またはテーブルに類似したオブジェクトについて説明します。これには、インデックス(ただし、pg_index も参照)、シーケンス(ただし、pg_sequence も参照)、ビュー、マテリアライズド ビュー、コンポジット タイプ、および TOAST テーブルが含まれます。再親切を参照してください。以下では、この種のオブジェクトをすべて意味する場合、“relations” について話します。pg_class の列のすべてがすべての関係種にとって意味があるわけではありません。
attributes relation
OID of the relation targeted by the lock, or null if the target is not a relation or part of a relation.
relname
Name of the table, index, view, etc.
attributes mode
Name of the lock mode held or desired by the process.
mode
Name of the lock mode held or desired by this process (see Section 13.3.1 and Section 13.2.3)
attributes lock_type
Type of the lockable object.
locktype
Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also Table 27.11.)
postgresql.database.locks
The number of database locks.
pid
Process ID of the server process holding or awaiting this lock, or null if the lock is held by a prepared transaction
getBackends
getBackends returns a map of database names to the number of active connections
$ SELECT datname, count(*) as count from pg_stat_activity
The pg_stat_activity view will have one row per server process, showing information related to the current activity of that process.
pg_stat_activity ビューにはサーバー プロセスごとに 1 行があり、そのプロセスの現在のアクティビティに関する情報が表示されます。
resource_attributes postgresql.database.name
The name of the database.
datname
Name of the database this backend is connected to
postgresql.backends
The number of backends.
getDatabaseSize
$ SELECT datname, pg_database_size(datname) FROM pg_catalog.pg_database WHERE datistemplate = false
The catalog pg_database stores information about the available databases. Databases are created with the CREATE DATABASE command. Consult Chapter 22 for details about the meaning of some of the parameters.
カタログ pg_database には、利用可能なデータベースに関する情報が保存されます。データベースは CREATE DATABASE コマンドで作成されます。一部のパラメータの意味の詳細については、第 22 章を参照してください。
resource_attributes postgresql.database.name
The name of the database.
datname
Database name
postgresql.db_size
The database disk usage.
pg_database_size
Computes the total disk space used by the database with the specified name or OID. To use this function, you must have CONNECT privilege on the specified database (which is granted by default) or have privileges of the pg_read_all_stats role.
指定された名前または OID でデータベースが使用するディスク容量の合計を計算します。この関数を使用するには、指定されたデータベース(デフォルトで付与される)に CONNECT 権限があるか、pg_read_all_stats ロールの権限がある必要があります。
datistemplate
If true, then this database can be cloned by any user with CREATEDB privileges; if false, then only superusers or the owner of the database can clone it.
true の場合、このデータベースは CREATEDB 権限を持つ任意のユーザーによってクローン化できます。false の場合、データベースのクローンを作成できるのはスーパーユーザーまたはデータベースの所有者のみです。
tableStats
tableStats contains a result for a row of the getDatabaseTableMetrics result
getDatabaseTableMetrics
code:sql
SELECT schemaname as schema, relname AS table,
n_live_tup AS live,
n_dead_tup AS dead,
n_tup_ins AS ins,
n_tup_upd AS upd,
n_tup_del AS del,
n_tup_hot_upd AS hot_upd,
seq_scan AS seq_scans,
pg_relation_size(relid) AS table_size,
vacuum_count
FROM pg_stat_user_tables;
Same as pg_stat_all_tables, except that only user tables are shown.
The pg_stat_all_tables view will contain one row for each table in the current database (including TOAST tables), showing statistics about accesses to that specific table. The pg_stat_user_tables and pg_stat_sys_tables views contain the same information, but filtered to only show user and system tables respectively.
pg_stat_all_tables ビューには、現在のデータベース(TOAST テーブルを含む)内の各テーブルに 1 つの行が含まれ、その特定のテーブルへのアクセスに関する統計が表示されます。pg_stat_user_tables ビューと pg_stat_sys_tables ビューには同じ情報が含まれていますが、フィルタリングされてそれぞれユーザー テーブルとシステム テーブルのみが表示されます。
resource_attributes postgresql.schema.name
The name of the database.
schemaname
Name of the schema that this table is in
resource_attributes postgresql.table.name
The table name.
relname
Name of this table
postgresql.rows
The number of rows in the database.
n_live_tup
Estimated number of live rows
n_dead_tup
Estimated number of dead rows
postgresql.operations
The number of db row operations.
n_tup_ins
Total number of rows inserted
n_tup_upd
Total number of rows updated. (This includes row updates counted in n_tup_hot_upd and n_tup_newpage_upd, and remaining non-HOT updates.)
更新された行の総数。(これには、n_tup_hot_upd および n_tup_newpage_upd でカウントされる行の更新と、HOT 以外の残りの更新が含まれます。)
n_tup_del
Total number of rows deleted
n_tup_hot_upd
Total number of rows deleted
postgresql.sequential_scans
The number of sequential scans.
seq_scan
Number of sequential scans initiated on this table
postgresql.table.size
Disk space used by a table.
pg_relation_size(relid)
pg_relation_size
Computes the disk space used by one “fork” of the specified relation. (Note that for most purposes it is more convenient to use the higher-level functions pg_total_relation_size or pg_table_size, which sum the sizes of all forks.) With one argument, this returns the size of the main data fork of the relation.
指定された関係の 1 つの “fork” によって使用されるディスク領域を計算します。(ほとんどの目的では、すべてのフォークのサイズを合計する上位関数 pg_total_relation_size または pg_table_size を使用する方が便利であることに注意してください。) 1 つの引数を使用すると、リレーションのメイン データ フォークのサイズが返されます。
relid
OID of the table for this index
postgresql.table.vacuum.count
Number of times a table has manually been vacuumed.
vacuum_count
Number of times this table has been manually vacuumed (not counting VACUUM FULL)
tableIOStats
getBlocksReadByTable
code:sql
SELECT schemaname as schema, relname AS table,
coalesce(heap_blks_read, 0) AS heap_read,
coalesce(heap_blks_hit, 0) AS heap_hit,
coalesce(idx_blks_read, 0) AS idx_read,
coalesce(idx_blks_hit, 0) AS idx_hit,
coalesce(toast_blks_read, 0) AS toast_read,
coalesce(toast_blks_hit, 0) AS toast_hit,
coalesce(tidx_blks_read, 0) AS tidx_read,
coalesce(tidx_blks_hit, 0) AS tidx_hit
FROM pg_statio_user_tables;
Same as pg_statio_all_tables, except that only user tables are shown.
The pg_statio_all_tables view will contain one row for each table in the current database (including TOAST tables), showing statistics about I/O on that specific table. The pg_statio_user_tables and pg_statio_sys_tables views contain the same information, but filtered to only show user and system tables respectively.
pg_statio_all_tables ビューには、現在のデータベース(TOAST テーブルを含む)内の各テーブルに 1 つの行が含まれ、その特定のテーブルの I/O に関する統計が表示されます。pg_statio_user_tables ビューと pg_statio_sys_tables ビューには同じ情報が含まれていますが、フィルタリングされてそれぞれユーザー テーブルとシステム テーブルのみが表示されます。
resource_attributes postgresql.schema.name
The name of the database.
schemaname
Name of the schema that this table is in
resource_attributes postgresql.table.name
The table name.
relname
Name of this table
postgresql.blocks_read
The number of blocks read.
heap_blks_read
Number of disk blocks read from this table
heap_blks_hit
Number of buffer hits in this table
idx_blks_read
Number of disk blocks read from all indexes on this table
idx_blks_hit
Number of buffer hits in all indexes on this table
toast_blks_read
Number of disk blocks read from this table's TOAST table (if any)
toast_blks_hit
Number of buffer hits in this table's TOAST table (if any)
tidx_blks_read
Number of disk blocks read from this table's TOAST table indexes (if any)
tidx_blks_hit
Number of buffer hits in this table's TOAST table indexes (if any)
indexStat
getIndexStats
code:sql
SELECT schemaname, relname, indexrelname,
pg_relation_size(indexrelid) AS index_size,
idx_scan
FROM pg_stat_user_indexes;
Same as pg_stat_all_indexes, except that only indexes on user tables are shown.
The pg_stat_all_indexes view will contain one row for each index in the current database, showing statistics about accesses to that specific index. The pg_stat_user_indexes and pg_stat_sys_indexes views contain the same information, but filtered to only show user and system indexes respectively.
pg_stat_all_indexes ビューには、現在のデータベース内のインデックスごとに 1 つの行が含まれ、その特定のインデックスへのアクセスに関する統計が表示されます。pg_stat_user_indexes ビューと pg_stat_sys_indexes ビューには同じ情報が含まれていますが、フィルタリングされてそれぞれユーザー インデックスとシステム インデックスのみが表示されます。
resource_attributes postgresql.schema.name
The name of the database.
schemaname
Name of the schema that this table is in
resource_attributes postgresql.table.name
The table name.
relname
Name of the table for this index
resource_attributes postgresql.index.name
The name of the index on a table.
indexrelname
Name of this index
postgresql.index.size
The size of the index on disk.
pg_relation_size
Computes the disk space used by one “fork” of the specified relation. (Note that for most purposes it is more convenient to use the higher-level functions pg_total_relation_size or pg_table_size, which sum the sizes of all forks.) With one argument, this returns the size of the main data fork of the relation.
指定された関係の 1 つの “fork” によって使用されるディスク領域を計算します。(ほとんどの目的では、すべてのフォークのサイズを合計する上位関数 pg_total_relation_size または pg_table_size を使用する方が便利であることに注意してください。) 1 つの引数を使用すると、リレーションのメイン データ フォークのサイズが返されます。
indexrelid
OID of this index
postgresql.index.scans
The number of index scans on a table.
idx_scan
Number of index scans initiated on this index
bgStat
getBGWriterStats
code:sql
SELECT
checkpoints_req AS checkpoint_req,
checkpoints_timed AS checkpoint_scheduled,
checkpoint_write_time AS checkpoint_duration_write,
checkpoint_sync_time AS checkpoint_duration_sync,
buffers_clean AS bg_writes,
buffers_backend AS backend_writes,
buffers_backend_fsync AS buffers_written_fsync,
buffers_checkpoint AS buffers_checkpoints,
buffers_alloc AS buffers_allocated,
maxwritten_clean AS maxwritten_count
FROM pg_stat_bgwriter;
The pg_stat_bgwriter view will always have a single row, containing data about the background writer of the cluster.
checkpoints_req、checkpoints_timed、checkpoint_write_time、checkpoint_sync_time、buffers_backend、buffers_backend_fsync、buffers_checkpoint は 17 からは消えてる
16 には在る
checkpoint の統計は pg_stat_checkpointer view に移動
The pg_stat_checkpointer view will always have a single row, containing data about the checkpointer process of the cluster.
buffers_backend、buffers_backend_fsync は pg_stat_io view を見よう
postgresql.bgwriter.checkpoint.count
The number of checkpoints performed.
checkpoints_req
Number of requested checkpoints that have been performed
checkpoints_timed
Number of scheduled checkpoints that have been performed
postgresql.bgwriter.duration
Total time spent writing and syncing files to disk by checkpoints.
checkpoint_write_time
Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds
checkpoint_sync_time
Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds
postgresql.bgwriter.buffers.writes
Number of buffers written.
buffers_clean
Number of buffers written by the background writer
buffers_backend
Number of buffers written directly by a backend
buffers_backend_fsync
Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)
buffers_checkpoint
Number of buffers written during checkpoints
postgresql.bgwriter.buffers.allocated
Number of buffers allocated.
buffers_alloc
Number of buffers allocated
postgresql.bgwriter.maxwritten
Number of times the background writer stopped a cleaning scan because it had written too many buffers.
maxwritten_clean
Number of times the background writer stopped a cleaning scan because it had written too many buffers
getMaxConnections
$ SHOW max_connections;
postgresql.connection.max
Configured maximum number of client connections allowed
max_connections
The TCP port the server listens on; 5432 by default. Note that the same port number is used for all IP addresses the server listens on. This parameter can only be set at server start.
replicationStats
getDeprecatedReplicationStats
略
getReplicationStats
code:sql
SELECT
coalesce(cast(client_addr as varchar), 'unix') AS client_addr,
coalesce(pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn), -1) AS replication_bytes_pending,
extract('epoch' from coalesce(write_lag, '-1 seconds'))::decimal AS write_lag_fractional,
extract('epoch' from coalesce(flush_lag, '-1 seconds'))::decimal AS flush_lag_fractional,
extract('epoch' from coalesce(replay_lag, '-1 seconds'))::decimal AS replay_lag_fractional
FROM pg_stat_replication;
The pg_stat_replication view will contain one row per WAL sender process, showing statistics about replication to that sender's connected standby server. Only directly connected standbys are listed; no information is available about downstream standby servers.
pg_stat_replication ビューには、WAL 送信者プロセスごとに 1 行が含まれ、その送信者の接続されたスタンバイ サーバーへのレプリケーションに関する統計が表示されます。直接接続されたスタンバイのみがリストされています。ダウンストリーム スタンバイ サーバーに関する情報は入手できません。
attributes replication_client
The IP address of the client connected to this backend. If this field is "unix", it indicates either that the client is connected via a Unix socket.
client_addr
IP address of the client connected to this WAL sender. If this field is null, it indicates that the client is connected via a Unix socket on the server machine.
postgresql.replication.data_delay
The amount of data delayed in replication.
pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn)
pg_wal_lsn_diff
Calculates the difference in bytes (lsn1 - lsn2) between two write-ahead log locations. This can be used with pg_stat_replication or some of the functions shown in Table 9.95 to get the replication lag.
2 つの書き込み先ログの場所間のバイト数(lsn1 ~ lsn2) の差を計算します。これは、pg_stat_replication または表 9。95 に示す一部の関数を使用して、レプリケーション ラグを取得できます。
pg_current_wal_lsn
Returns the current write-ahead log write location (see notes below).
replay_lsn
Last write-ahead log location replayed into the database on this standby server
postgresql.wal.lag
Time between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.
write_lag
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written it (but not yet flushed it or applied it). This can be used to gauge the delay that synchronous_commit level remote_write incurred while committing if this server was configured as a synchronous standby.
最近の WAL をローカルでフラッシュしてから、このスタンバイ サーバーが WAL を書き込んだ(ただし、まだフラッシュまたは適用していない)という通知を受信するまでの時間が経過しました。これは、このサーバーが同期スタンバイとして構成されている場合に、コミット中に発生する synchronous_commit レベルの remote_write の遅延を測定するために使用できます。
flush_lag
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written and flushed it (but not yet applied it). This can be used to gauge the delay that synchronous_commit level on incurred while committing if this server was configured as a synchronous standby.
最近の WAL をローカルでフラッシュしてから、このスタンバイ サーバーが WAL を書き込んでフラッシュしたという通知を受信するまでの時間が経過しました(ただし、まだ適用されていません)。これは、このサーバーが同期スタンバイとして構成されている場合に、コミット中に発生した同期コミット レベルの遅延を測定するために使用できます。
replay_lag
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written, flushed and applied it. This can be used to gauge the delay that synchronous_commit level remote_apply incurred while committing if this server was configured as a synchronous standby.
最近の WAL をローカルでフラッシュしてから、このスタンバイ サーバーが WAL を書き込み、フラッシュし、適用したという通知を受信するまでの時間が経過しました。これは、このサーバーが同期スタンバイとして構成されている場合に、committing 中に発生した synchronous_commit level remote_apply の遅延を測定するために使用できます。
getLatestWalAgeSeconds
code:sql
SELECT
coalesce(last_archived_time, CURRENT_TIMESTAMP) AS last_archived_wal,
CURRENT_TIMESTAMP
FROM pg_stat_archiver;
The pg_stat_archiver view will always have a single row, containing data about the archiver process of the cluster.
pg_stat_archiver ビューには常に 1 つの行があり、クラスターのアーカイバー プロセスに関するデータが含まれます。
postgresql.wal.age
Age of the oldest WAL file.
This metric requires WAL to be enabled with at least one replica.
last_archived_time
Time of the most recent successful archive operation
listDatabases
code:sql
SELECT datname FROM pg_database
WHERE datistemplate = false;
The catalog pg_database stores information about the available databases. Databases are created with the CREATE DATABASE command. Consult Chapter 22 for details about the meaning of some of the parameters.
カタログ pg_database には、利用可能なデータベースに関する情報が保存されます。データベースは CREATE DATABASE コマンドで作成されます。一部のパラメータの意味の詳細については、第 22 章を参照してください。
postgresql.database.name
The name of the database.
datname
Database name
datistemplate
If true, then this database can be cloned by any user with CREATEDB privileges; if false, then only superusers or the owner of the database can clone it.