PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/xact.h"
#include "libpq/libpq-be.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "pgstat.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/ascii.h"
#include "utils/guc.h"
#include "utils/memutils.h"
Go to the source code of this file.
Macros | |
#define | NumBackendStatSlots (MaxBackends + NUM_AUXILIARY_PROCS) |
Variables | |
bool | pgstat_track_activities = false |
int | pgstat_track_activity_query_size = 1024 |
PgBackendStatus * | MyBEEntry = NULL |
static PgBackendStatus * | BackendStatusArray = NULL |
static char * | BackendAppnameBuffer = NULL |
static char * | BackendClientHostnameBuffer = NULL |
static char * | BackendActivityBuffer = NULL |
static Size | BackendActivityBufferSize = 0 |
static LocalPgBackendStatus * | localBackendStatusTable = NULL |
static int | localNumBackends = 0 |
static MemoryContext | backendStatusSnapContext |
#define NumBackendStatSlots (MaxBackends + NUM_AUXILIARY_PROCS) |
Definition at line 35 of file backend_status.c.
void BackendStatusShmemInit | ( | void | ) |
Definition at line 114 of file backend_status.c.
References BackendActivityBuffer, BackendActivityBufferSize, BackendAppnameBuffer, BackendClientHostnameBuffer, BackendStatusArray, i, MemSet, mul_size(), NAMEDATALEN, NumBackendStatSlots, pgstat_track_activity_query_size, ShmemInitStruct(), size, PgBackendStatus::st_activity_raw, PgBackendStatus::st_appname, PgBackendStatus::st_clienthostname, PgBackendStatus::st_gssstatus, and PgBackendStatus::st_sslstatus.
Referenced by CreateOrAttachShmemStructs().
Size BackendStatusShmemSize | ( | void | ) |
Definition at line 81 of file backend_status.c.
References add_size(), mul_size(), NAMEDATALEN, NumBackendStatSlots, pgstat_track_activity_query_size, and size.
Referenced by CalculateShmemSize().
|
static |
Definition at line 1047 of file backend_status.c.
References a, b, and LocalPgBackendStatus::proc_number.
Referenced by pgstat_get_local_beentry_by_proc_number().
void pgstat_beinit | ( | void | ) |
Definition at line 245 of file backend_status.c.
References Assert, BackendStatusArray, INVALID_PROC_NUMBER, MyBEEntry, MyProcNumber, NumBackendStatSlots, on_shmem_exit(), and pgstat_beshutdown_hook().
Referenced by AuxiliaryProcessMainCommon(), and InitPostgres().
|
static |
Definition at line 438 of file backend_status.c.
References MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, and PgBackendStatus::st_procpid.
Referenced by pgstat_beinit().
void pgstat_bestart | ( | void | ) |
Definition at line 271 of file backend_status.c.
References application_name, Assert, B_BACKEND, B_BG_WORKER, B_WAL_SENDER, be_gssapi_get_auth(), be_gssapi_get_delegation(), be_gssapi_get_enc(), be_gssapi_get_princ(), be_tls_get_cipher(), be_tls_get_cipher_bits(), be_tls_get_peer_issuer_name(), be_tls_get_peer_serial(), be_tls_get_peer_subject_name(), be_tls_get_version(), GetSessionUserId(), Port::gss, PgBackendGSSStatus::gss_auth, PgBackendGSSStatus::gss_delegation, PgBackendGSSStatus::gss_enc, PgBackendGSSStatus::gss_princ, InvalidOid, MemSet, MyBackendType, MyBEEntry, MyDatabaseId, MyProcPid, MyProcPort, MyStartTimestamp, NAMEDATALEN, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_report_appname(), pgstat_track_activity_query_size, PROGRESS_COMMAND_INVALID, Port::raddr, Port::remote_hostname, PgBackendSSLStatus::ssl_bits, PgBackendSSLStatus::ssl_cipher, PgBackendSSLStatus::ssl_client_dn, PgBackendSSLStatus::ssl_client_serial, Port::ssl_in_use, PgBackendSSLStatus::ssl_issuer_dn, PgBackendSSLStatus::ssl_version, PgBackendStatus::st_activity_raw, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_appname, PgBackendStatus::st_backendType, PgBackendStatus::st_changecount, PgBackendStatus::st_clientaddr, PgBackendStatus::st_clienthostname, PgBackendStatus::st_databaseid, PgBackendStatus::st_gss, PgBackendStatus::st_gssstatus, PgBackendStatus::st_proc_start_timestamp, PgBackendStatus::st_procpid, PgBackendStatus::st_progress_command, PgBackendStatus::st_progress_command_target, PgBackendStatus::st_query_id, PgBackendStatus::st_ssl, PgBackendStatus::st_sslstatus, PgBackendStatus::st_state, PgBackendStatus::st_state_start_timestamp, PgBackendStatus::st_userid, PgBackendStatus::st_xact_start_timestamp, STATE_UNDEFINED, strlcpy(), and unvolatize.
Referenced by AuxiliaryProcessMainCommon(), and InitPostgres().
void pgstat_clear_backend_activity_snapshot | ( | void | ) |
Definition at line 465 of file backend_status.c.
References backendStatusSnapContext, localBackendStatusTable, localNumBackends, and MemoryContextDelete().
Referenced by pgstat_clear_snapshot().
char* pgstat_clip_activity | ( | const char * | raw_activity | ) |
Definition at line 1162 of file backend_status.c.
References cliplen(), pg_mbcliplen(), pgstat_track_activity_query_size, and pnstrdup().
Referenced by pg_stat_get_activity(), pg_stat_get_backend_activity(), and pgstat_get_backend_current_activity().
int pgstat_fetch_stat_numbackends | ( | void | ) |
Definition at line 1146 of file backend_status.c.
References localNumBackends, and pgstat_read_current_status().
Referenced by pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_stat_get_db_numbackends(), and pg_stat_get_progress_info().
const char* pgstat_get_backend_current_activity | ( | int | pid, |
bool | checkUser | ||
) |
Definition at line 883 of file backend_status.c.
References BackendStatusArray, CHECK_FOR_INTERRUPTS, GetUserId(), i, MaxBackends, pgstat_begin_read_activity, pgstat_clip_activity(), pgstat_end_read_activity, pgstat_read_activity_complete, PgBackendStatus::st_activity_raw, PgBackendStatus::st_procpid, PgBackendStatus::st_userid, and superuser().
Referenced by DeadLockReport().
PgBackendStatus* pgstat_get_beentry_by_proc_number | ( | ProcNumber | procNumber | ) |
Definition at line 1070 of file backend_status.c.
References LocalPgBackendStatus::backendStatus, and pgstat_get_local_beentry_by_proc_number().
Referenced by pg_signal_backend(), pg_stat_get_backend_activity(), pg_stat_get_backend_activity_start(), pg_stat_get_backend_client_addr(), pg_stat_get_backend_client_port(), pg_stat_get_backend_dbid(), pg_stat_get_backend_pid(), pg_stat_get_backend_start(), pg_stat_get_backend_userid(), pg_stat_get_backend_wait_event(), pg_stat_get_backend_wait_event_type(), and pg_stat_get_backend_xact_start().
const char* pgstat_get_crashed_backend_activity | ( | int | pid, |
char * | buffer, | ||
int | buflen | ||
) |
Definition at line 961 of file backend_status.c.
References ascii_safe_strlcpy(), BackendActivityBuffer, BackendActivityBufferSize, BackendStatusArray, i, MaxBackends, Min, pgstat_track_activity_query_size, PgBackendStatus::st_activity_raw, and PgBackendStatus::st_procpid.
Referenced by LogChildExit().
LocalPgBackendStatus* pgstat_get_local_beentry_by_index | ( | int | idx | ) |
Definition at line 1126 of file backend_status.c.
References idx(), localBackendStatusTable, localNumBackends, and pgstat_read_current_status().
Referenced by pg_stat_get_activity(), pg_stat_get_backend_idset(), pg_stat_get_db_numbackends(), and pg_stat_get_progress_info().
LocalPgBackendStatus* pgstat_get_local_beentry_by_proc_number | ( | ProcNumber | procNumber | ) |
Definition at line 1095 of file backend_status.c.
References cmp_lbestatus(), sort-test::key, localBackendStatusTable, localNumBackends, and pgstat_read_current_status().
Referenced by pg_stat_get_backend_subxact(), and pgstat_get_beentry_by_proc_number().
uint64 pgstat_get_my_query_id | ( | void | ) |
Definition at line 1025 of file backend_status.c.
References MyBEEntry, and PgBackendStatus::st_query_id.
Referenced by _brin_begin_parallel(), _bt_begin_parallel(), ExecSerializePlan(), log_status_format(), parallel_vacuum_init(), write_csvlog(), and write_jsonlog().
|
static |
Definition at line 707 of file backend_status.c.
References LocalPgBackendStatus::backend_subxact_count, LocalPgBackendStatus::backend_subxact_overflowed, LocalPgBackendStatus::backend_xid, LocalPgBackendStatus::backend_xmin, LocalPgBackendStatus::backendStatus, BackendStatusArray, backendStatusSnapContext, CHECK_FOR_INTERRUPTS, localBackendStatusTable, localNumBackends, MemoryContextAlloc(), MemoryContextAllocHuge(), NAMEDATALEN, NumBackendStatSlots, pgstat_begin_read_activity, pgstat_end_read_activity, pgstat_read_activity_complete, pgstat_setup_backend_status_context(), pgstat_track_activity_query_size, LocalPgBackendStatus::proc_number, ProcNumberGetTransactionIds(), PgBackendStatus::st_activity_raw, PgBackendStatus::st_appname, PgBackendStatus::st_clienthostname, PgBackendStatus::st_gss, PgBackendStatus::st_gssstatus, PgBackendStatus::st_procpid, PgBackendStatus::st_ssl, PgBackendStatus::st_sslstatus, and unvolatize.
Referenced by pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), and pgstat_get_local_beentry_by_proc_number().
void pgstat_report_activity | ( | BackendState | state, |
const char * | cmd_str | ||
) |
Definition at line 501 of file backend_status.c.
References GetCurrentStatementStartTimestamp(), GetCurrentTimestamp(), len, Min, MyBEEntry, MyProc, PGSTAT_BEGIN_WRITE_ACTIVITY, pgstat_count_conn_active_time, pgstat_count_conn_txn_idle_time, PGSTAT_END_WRITE_ACTIVITY, pgstat_track_activities, pgstat_track_activity_query_size, PgBackendStatus::st_activity_raw, PgBackendStatus::st_activity_start_timestamp, PgBackendStatus::st_query_id, PgBackendStatus::st_state, PgBackendStatus::st_state_start_timestamp, PgBackendStatus::st_xact_start_timestamp, STATE_DISABLED, STATE_FASTPATH, STATE_IDLEINTRANSACTION, STATE_IDLEINTRANSACTION_ABORTED, STATE_RUNNING, TimestampDifference(), and PGPROC::wait_event_info.
Referenced by _brin_parallel_build_main(), _bt_parallel_build_main(), apply_handle_begin(), apply_handle_begin_prepare(), apply_handle_commit(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_rollback_prepared(), apply_handle_stream_commit(), apply_handle_stream_prepare(), apply_handle_stream_start(), apply_handle_stream_stop(), apply_spooled_messages(), autovac_report_activity(), autovac_report_workitem(), exec_bind_message(), exec_execute_message(), exec_parse_message(), exec_replication_command(), exec_simple_query(), initialize_worker_spi(), LogicalRepApplyLoop(), pa_stream_abort(), parallel_vacuum_main(), ParallelQueryMain(), PostgresMain(), and worker_spi_main().
void pgstat_report_appname | ( | const char * | appname | ) |
Definition at line 651 of file backend_status.c.
References len, MyBEEntry, NAMEDATALEN, pg_mbcliplen(), PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, and PgBackendStatus::st_appname.
Referenced by assign_application_name(), and pgstat_bestart().
void pgstat_report_query_id | ( | uint64 | query_id, |
bool | force | ||
) |
Definition at line 611 of file backend_status.c.
References MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_track_activities, and PgBackendStatus::st_query_id.
Referenced by _brin_parallel_build_main(), _bt_parallel_build_main(), exec_bind_message(), exec_execute_message(), exec_simple_query(), ExecutorStart(), parallel_vacuum_main(), parse_analyze_fixedparams(), parse_analyze_varparams(), and parse_analyze_withcb().
void pgstat_report_xact_timestamp | ( | TimestampTz | tstamp | ) |
Definition at line 680 of file backend_status.c.
References MyBEEntry, PGSTAT_BEGIN_WRITE_ACTIVITY, PGSTAT_END_WRITE_ACTIVITY, pgstat_track_activities, and PgBackendStatus::st_xact_start_timestamp.
Referenced by AbortTransaction(), CommitTransaction(), PrepareTransaction(), and StartTransaction().
|
static |
Definition at line 480 of file backend_status.c.
References ALLOCSET_SMALL_SIZES, AllocSetContextCreate, backendStatusSnapContext, and TopMemoryContext.
Referenced by pgstat_read_current_status().
|
static |
Definition at line 53 of file backend_status.c.
Referenced by BackendStatusShmemInit(), and pgstat_get_crashed_backend_activity().
|
static |
Definition at line 54 of file backend_status.c.
Referenced by BackendStatusShmemInit(), and pgstat_get_crashed_backend_activity().
|
static |
Definition at line 51 of file backend_status.c.
Referenced by BackendStatusShmemInit().
|
static |
Definition at line 52 of file backend_status.c.
Referenced by BackendStatusShmemInit().
|
static |
Definition at line 50 of file backend_status.c.
Referenced by BackendStatusShmemInit(), pgstat_beinit(), pgstat_get_backend_current_activity(), pgstat_get_crashed_backend_activity(), and pgstat_read_current_status().
|
static |
Definition at line 69 of file backend_status.c.
Referenced by pgstat_clear_backend_activity_snapshot(), pgstat_read_current_status(), and pgstat_setup_backend_status_context().
|
static |
Definition at line 64 of file backend_status.c.
Referenced by pgstat_clear_backend_activity_snapshot(), pgstat_get_local_beentry_by_index(), pgstat_get_local_beentry_by_proc_number(), and pgstat_read_current_status().
|
static |
Definition at line 67 of file backend_status.c.
Referenced by pgstat_clear_backend_activity_snapshot(), pgstat_fetch_stat_numbackends(), pgstat_get_local_beentry_by_index(), pgstat_get_local_beentry_by_proc_number(), and pgstat_read_current_status().
PgBackendStatus* MyBEEntry = NULL |
Definition at line 47 of file backend_status.c.
Referenced by pgstat_beinit(), pgstat_beshutdown_hook(), pgstat_bestart(), pgstat_get_my_query_id(), pgstat_progress_end_command(), pgstat_progress_incr_param(), pgstat_progress_start_command(), pgstat_progress_update_multi_param(), pgstat_progress_update_param(), pgstat_report_activity(), pgstat_report_appname(), pgstat_report_query_id(), and pgstat_report_xact_timestamp().
Definition at line 42 of file backend_status.c.
Referenced by pgstat_progress_end_command(), pgstat_progress_incr_param(), pgstat_progress_start_command(), pgstat_progress_update_multi_param(), pgstat_progress_update_param(), pgstat_report_activity(), pgstat_report_query_id(), and pgstat_report_xact_timestamp().
int pgstat_track_activity_query_size = 1024 |
Definition at line 43 of file backend_status.c.
Referenced by BackendStatusShmemInit(), BackendStatusShmemSize(), pgstat_bestart(), pgstat_clip_activity(), pgstat_get_crashed_backend_activity(), pgstat_read_current_status(), and pgstat_report_activity().