state

package
v0.56.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: BSD-2-Clause, BSD-3-Clause, PostgreSQL Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CredentialLogSecret - Passwords and other credentials (e.g. private keys)
	CredentialLogSecret

	// ParsingErrorLogSecret - User supplied text during parsing errors - could contain anything, including credentials
	ParsingErrorLogSecret

	// StatementTextLogSecret - All statement texts (which may contain table data if not using bind parameters)
	StatementTextLogSecret

	// StatementParameterLogSecret - Bind parameters for a statement (which may contain table data for INSERT statements)
	StatementParameterLogSecret

	// TableDataLogSecret - Table data contained in constraint violations and COPY errors
	TableDataLogSecret

	// OpsLogSecret - System, network errors, file locations, pg_hba.conf contents, and configured commands (e.g. archive command)
	OpsLogSecret

	// UnidentifiedLogSecret - Text that could not be identified and might contain secrets
	UnidentifiedLogSecret
)
View Source
const (
	PostgresVersion10 = 100000
	PostgresVersion11 = 110000
	PostgresVersion12 = 120000
	PostgresVersion13 = 130000
	PostgresVersion14 = 140000
	PostgresVersion15 = 150000
	PostgresVersion16 = 160000
	PostgresVersion17 = 170000

	// MinRequiredPostgresVersion - We require PostgreSQL 10 or newer
	MinRequiredPostgresVersion = PostgresVersion10
)

Known PostgresVersion values - use these for checks in version-dependent code

View Source
const (
	LOG_IGNORE_STATEMENT uint32 = 1 << iota
	LOG_IGNORE_DURATION
)
View Source
const LogStreamBufferLen = 500
View Source
const StateOnDiskFormatVersion = 6

StateOnDiskFormatVersion - Increment this when an old state preserved to disk should be ignored

Variables

AllLogSecretKinds - List of all defined secret kinds

View Source
var ErrReplicaCollectionDisabled error = errors.New("monitored server is replica and replication collection disabled via config")

Functions

func ReadStateFile

func ReadStateFile(servers []*Server, globalCollectionOpts CollectionOpts, logger *util.Logger)

ReadStateFile - This reads in the prevState structs from the state file - only run this on initial bootup and SIGHUP!

func WriteStateFile

func WriteStateFile(servers []*Server, globalCollectionOpts CollectionOpts, logger *util.Logger)

Types

type CPUInformation

type CPUInformation struct {
	Model             string
	CacheSizeBytes    int32
	SpeedMhz          float64
	SocketCount       int32
	PhysicalCoreCount int32
	LogicalCoreCount  int32
}

type CPUStatistic

type CPUStatistic struct {
	DiffedOnInput bool // True if has already been diffed on input (and we can simply copy the diff)
	DiffedValues  *DiffedSystemCPUStats

	// Seconds (counter values that need to be diff-ed between runs)
	UserSeconds      float64
	SystemSeconds    float64
	IdleSeconds      float64
	NiceSeconds      float64
	IowaitSeconds    float64
	IrqSeconds       float64
	SoftIrqSeconds   float64
	StealSeconds     float64
	GuestSeconds     float64
	GuestNiceSeconds float64
}

CPUStatistic - Statistics for a single CPU core

func (CPUStatistic) DiffSince

func (curr CPUStatistic) DiffSince(prev CPUStatistic) DiffedSystemCPUStats

DiffSince - Calculate the diff between two CPU stats runs

type CPUStatisticMap

type CPUStatisticMap map[string]CPUStatistic

CPUStatisticMap - Map of all CPU statistics (Key = CPU ID)

type CollectionAspect added in v0.56.0

type CollectionAspect int
const (
	CollectionAspectApiConnection CollectionAspect = iota
	CollectionAspectTelemetry
	CollectionAspectSystemStats
	CollectionAspectMonitoringDbConnection
	CollectionAspectPgVersion
	CollectionAspectPgStatStatements
	CollectionAspectActivity
	CollectionAspectLogs
	CollectionAspectExplain
)

type CollectionAspectStatus added in v0.56.0

type CollectionAspectStatus struct {
	State CollectionStateCode
	Msg   string
	Hint  string
}

type CollectionOpts

type CollectionOpts struct {
	StartedAt time.Time

	CollectPostgresRelations bool
	CollectPostgresSettings  bool
	CollectPostgresLocks     bool
	CollectPostgresFunctions bool
	CollectPostgresBloat     bool
	CollectPostgresViews     bool

	CollectLogs              bool
	CollectExplain           bool
	CollectSystemInformation bool

	CollectorApplicationName string

	DiffStatements bool

	SubmitCollectedData    bool
	TestRun                bool
	TestReport             string
	TestRunLogs            bool
	TestExplain            bool
	TestSection            string
	GenerateStatsHelperSql string
	DebugLogs              bool
	DiscoverLogLocation    bool

	StateFilename    string
	WriteStateUpdate bool
	ForceEmptyGrant  bool

	OutputAsJson bool
}

type CollectionStateCode added in v0.56.0

type CollectionStateCode int
const (
	CollectionStateUnchecked CollectionStateCode = iota
	CollectionStateNotAvailable
	CollectionStateWarning
	CollectionStateError
	CollectionStateOkay
)

type CollectionStatus

type CollectionStatus struct {
	CollectionDisabled        bool
	CollectionDisabledReason  string
	LogSnapshotDisabled       bool
	LogSnapshotDisabledReason string
}

type CollectorConfig

type CollectorConfig struct {
	SectionName                string
	DisableLogs                bool
	DisableActivity            bool
	EnableLogExplain           bool
	DbName                     string
	DbUsername                 string
	DbHost                     string
	DbPort                     int32
	DbSslmode                  string
	DbHasSslrootcert           bool
	DbHasSslcert               bool
	DbHasSslkey                bool
	DbExtraNames               []string
	DbAllNames                 bool
	DbURLRedacted              string
	AwsRegion                  string
	AwsDbInstanceId            string
	AwsDbClusterID             string
	AwsDbClusterReadonly       bool
	AwsHasAccessKeyId          bool
	AwsHasAssumeRole           bool
	AwsHasAccountId            bool
	AwsHasWebIdentityTokenFile bool
	AwsHasRoleArn              bool
	AzureDbServerName          string
	AzureEventhubNamespace     string
	AzureEventhubName          string
	AzureAdTenantId            string
	AzureAdClientId            string
	AzureHasAdCertificate      bool
	GcpCloudsqlInstanceId      string
	GcpAlloyDBClusterID        string
	GcpAlloyDBInstanceID       string
	GcpPubsubSubscription      string
	GcpHasCredentialsFile      bool
	GcpProjectId               string
	CrunchyBridgeClusterId     string
	AivenProjectId             string
	AivenServiceId             string
	ApiSystemId                string
	ApiSystemType              string
	ApiSystemScope             string
	ApiSystemIdFallback        string
	ApiSystemTypeFallback      string
	ApiSystemScopeFallback     string
	DbLogLocation              string
	DbLogDockerTail            string
	DbLogSyslogServer          string
	DbLogPgReadFile            bool
	IgnoreTablePattern         string
	IgnoreSchemaRegexp         string
	QueryStatsInterval         int32
	MaxCollectorConnections    int32
	SkipIfReplica              bool
	FilterLogSecret            string
	FilterQuerySample          string
	FilterQueryText            string
	HasProxy                   bool
	ConfigFromEnv              bool
	OtelExporterOtlpEndpoint   string
}

type CollectorPlatform

type CollectorPlatform struct {
	StartedAt            time.Time
	Architecture         string
	Hostname             string
	OperatingSystem      string
	Platform             string
	PlatformFamily       string
	PlatformVersion      string
	VirtualizationSystem string
	KernelVersion        string
}

type CollectorStats

type CollectorStats struct {
	GoVersion string

	MemoryHeapAllocatedBytes uint64 // Bytes allocated and not yet freed
	MemoryHeapObjects        uint64 // Total number of allocated objects
	MemorySystemBytes        uint64 // Bytes obtained from system (sum of heap and fixed-size structures)
	MemoryRssBytes           uint64 // Memory allocated in bytes as seen by the OS

	ActiveGoroutines int32

	CgoCalls int64
}

func (CollectorStats) DiffSince

func (curr CollectorStats) DiffSince(prev CollectorStats) DiffedCollectorStats

type DbCollectionAspect added in v0.56.0

type DbCollectionAspect int
const (
	CollectionAspectSchema DbCollectionAspect = iota
	CollectionAspectColumnStats
	CollectionAspectExtendedStats
)

type DiffState

type DiffState struct {
	StatementStats DiffedPostgresStatementStatsMap
	SchemaStats    map[Oid]*DiffedSchemaStats

	SystemCPUStats     DiffedSystemCPUStatsMap
	SystemNetworkStats DiffedNetworkStatsMap
	SystemDiskStats    DiffedDiskStatsMap

	CollectorStats DiffedCollectorStats

	DatabaseStats DiffedPostgresDatabaseStatsMap
}

DiffState - Result of diff-ing two persistent state structs

type DiffedCollectorStats

type DiffedCollectorStats CollectorStats

type DiffedDiskStats

type DiffedDiskStats struct {
	ReadOperationsPerSecond float64 // The average number of read requests that were issued to the device per second
	ReadsMergedPerSecond    float64 // The average number of read requests merged per second that were queued to the device
	BytesReadPerSecond      float64 // The average number of bytes read from the device per second
	AvgReadLatency          float64 // The average time (in milliseconds) for read requests issued to the device to be served

	WriteOperationsPerSecond float64 // The average number of write requests that were issued to the device per second
	WritesMergedPerSecond    float64 // The average number of write requests merged per second that were queued to the device
	BytesWrittenPerSecond    float64 // The average number of bytes written to the device per second
	AvgWriteLatency          float64 // The average time (in milliseconds) for write requests issued to the device to be served

	AvgQueueSize       int32   // Average I/O operations in flight at the same time (waiting or worked on by the device)
	UtilizationPercent float64 // Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device)
}

type DiffedDiskStatsMap

type DiffedDiskStatsMap map[string]DiffedDiskStats

DiffedDiskStatsMap - Map of all diffed disk statistics (key = device name)

type DiffedNetworkStats

type DiffedNetworkStats struct {
	ReceiveThroughputBytesPerSecond  uint64
	TransmitThroughputBytesPerSecond uint64
}

DiffedNetworkStats - Network statistics for a single interface as a diff

type DiffedNetworkStatsMap

type DiffedNetworkStatsMap map[string]DiffedNetworkStats

DiffedNetworkStatsMap - Map of network statistics as a diff (Key = Interface Name)

type DiffedPostgresDatabaseStats added in v0.47.0

type DiffedPostgresDatabaseStats struct {
	FrozenXIDAge int32
	MinMXIDAge   int32
	XactCommit   int32
	XactRollback int32
}

DiffedPostgresDatabaseStat - Database statistics for a single database as a diff

type DiffedPostgresDatabaseStatsMap added in v0.47.0

type DiffedPostgresDatabaseStatsMap map[Oid]DiffedPostgresDatabaseStats

DiffedDatabaseStats - Map of diffed database statistics (key = database Oid)

type DiffedPostgresFunctionStats

type DiffedPostgresFunctionStats PostgresFunctionStats

type DiffedPostgresFunctionStatsMap

type DiffedPostgresFunctionStatsMap map[Oid]DiffedPostgresFunctionStats

type DiffedPostgresIndexStats

type DiffedPostgresIndexStats PostgresIndexStats

type DiffedPostgresIndexStatsMap

type DiffedPostgresIndexStatsMap map[Oid]DiffedPostgresIndexStats

type DiffedPostgresRelationStats

type DiffedPostgresRelationStats PostgresRelationStats

type DiffedPostgresRelationStatsMap

type DiffedPostgresRelationStatsMap map[Oid]DiffedPostgresRelationStats

type DiffedPostgresStatementStats

type DiffedPostgresStatementStats PostgresStatementStats

func (DiffedPostgresStatementStats) Add

Add - Adds the statistics of one diffed statement to another, returning the result as a copy

type DiffedSchemaStats

type DiffedSchemaStats struct {
	RelationStats DiffedPostgresRelationStatsMap
	IndexStats    DiffedPostgresIndexStatsMap
	FunctionStats DiffedPostgresFunctionStatsMap
}

type DiffedSystemCPUStats

type DiffedSystemCPUStats struct {
	UserPercent      float64
	SystemPercent    float64
	IdlePercent      float64
	NicePercent      float64
	IowaitPercent    float64
	IrqPercent       float64
	SoftIrqPercent   float64
	StealPercent     float64
	GuestPercent     float64
	GuestNicePercent float64
}

DiffedSystemCPUStats - CPU statistics as percentages

type DiffedSystemCPUStatsMap

type DiffedSystemCPUStatsMap map[string]DiffedSystemCPUStats

DiffedSystemCPUStatsMap - Map of all CPU statistics (Key = CPU ID)

type Disk

type Disk struct {
	DiskType        string // Disk type (hdd/sdd/io1/gp2)
	Scheduler       string // Linux Scheduler (noop/anticipatory/deadline/cfq)
	ProvisionedIOPS uint32 // If applicable, how many IOPS are provisioned for this device
	Encrypted       bool   // If applicable, is this device encrypted? (default false)

	ComponentDisks []string // Identifiers for component disks (e.g. for a software RAID)
}

Disk - Information about an individual disk device in the system

type DiskMap

type DiskMap map[string]Disk

DiskMap - Map of all disks (key = device name)

type DiskPartition

type DiskPartition struct {
	DiskName       string // Name of the base device disk that this partition resides on (e.g. /dev/sda)
	PartitionName  string // Platform-specific name of the partition (e.g. /dev/sda1)
	FilesystemType string
	FilesystemOpts string

	UsedBytes  uint64
	TotalBytes uint64
}

DiskPartition - Information and statistics about one of the disk partitions in the system

type DiskPartitionMap

type DiskPartitionMap map[string]DiskPartition

DiskPartitionMap - Map of all disk partitions (key = mountpoint)

type DiskStats

type DiskStats struct {
	DiffedOnInput bool // True if has already been diffed on input (and we can simply copy the diff)
	DiffedValues  *DiffedDiskStats

	// Counter values
	ReadsCompleted  uint64 // /proc/diskstats 4 - reads completed successfully
	ReadsMerged     uint64 // /proc/diskstats 5 - reads merged
	BytesRead       uint64 // /proc/diskstat 6 - sectors read, multiplied by sector size
	ReadTimeMs      uint64 // /proc/diskstat 7 - time spent reading (ms)
	WritesCompleted uint64 // /proc/diskstats 8 - writes completed
	WritesMerged    uint64 // /proc/diskstats 9 - writes merged
	BytesWritten    uint64 // /proc/diskstat 10 - sectors written, multiplied by sector size
	WriteTimeMs     uint64 // /proc/diskstat 11 - time spent writing (ms)
	AvgQueueSize    int32  // /proc/diskstat 12 - I/Os currently in progress
	IoTime          uint64 // /proc/diskstat 13 - time spent doing I/Os (ms)
}

DiskStats - Statistics about an individual disk device in the system

func (DiskStats) DiffSince

func (curr DiskStats) DiffSince(prev DiskStats, collectedIntervalSecs uint32) DiffedDiskStats

DiffSince - Calculate the diff between two disk stats runs

type DiskStatsMap

type DiskStatsMap map[string]DiskStats

DiskStatsMap - Map of all disk statistics (key = device name)

type ExplainPlanContainer added in v0.44.0

type ExplainPlanContainer struct {
	ExecutionTime   *float64              `json:"Execution Time,omitempty"`
	JIT             *ExplainPlanJIT       `json:"JIT,omitempty"`
	Plan            json.RawMessage       `json:"Plan"`
	Planning        *map[string]int64     `json:"Planning,omitempty"`
	PlanningTime    *float64              `json:"Planning Time,omitempty"`
	QueryIdentifier *int64                `json:"Query Identifier,omitempty"`
	QueryText       string                `json:"Query Text,omitempty"`
	Settings        *map[string]string    `json:"Settings,omitempty"`
	Triggers        *[]ExplainPlanTrigger `json:"Triggers,omitempty"`
}

type ExplainPlanJIT added in v0.44.0

type ExplainPlanJIT struct {
	Functions *int64              `json:"Functions,omitempty"`
	Options   *map[string]bool    `json:"Options,omitempty"`
	Timing    *map[string]float64 `json:"Timing,omitempty"`
}

type ExplainPlanTrigger added in v0.44.0

type ExplainPlanTrigger struct {
	Calls          *int64   `json:"Calls,omitempty"`
	ConstraintName *string  `json:"Constraint Name,omitempty"`
	Relation       *string  `json:"Relation,omitempty"`
	Time           *float64 `json:"Time,omitempty"`
	TriggerName    *string  `json:"Trigger Name,omitempty"`
}

type Grant

type Grant struct {
	Valid    bool
	Config   GrantConfig       `json:"config"`
	S3URL    string            `json:"s3_url"`
	S3Fields map[string]string `json:"s3_fields"`
	LocalDir string            `json:"local_dir"`
}

func (Grant) S3

func (g Grant) S3() GrantS3

type GrantConfig

type GrantConfig struct {
	ServerID  string `json:"server_id"`
	ServerURL string `json:"server_url"`
	SentryDsn string `json:"sentry_dsn"`

	Features GrantFeatures `json:"features"`

	EnableActivity bool `json:"enable_activity"`
	EnableLogs     bool `json:"enable_logs"`

	SchemaTableLimit int `json:"schema_table_limit"` // Maximum number of tables that can be monitored per server
}

type GrantFeatures

type GrantFeatures struct {
	Logs bool `json:"logs"`

	StatementResetFrequency     int   `json:"statement_reset_frequency"`
	StatementTimeoutMs          int32 `json:"statement_timeout_ms"`            // Statement timeout for all SQL statements sent to the database (defaults to 30s)
	StatementTimeoutMsQueryText int32 `json:"statement_timeout_ms_query_text"` // Statement timeout for pg_stat_statements query text requests (defaults to 120s)
}

type GrantLogs

type GrantLogs struct {
	Valid         bool
	Config        GrantConfig            `json:"config"`
	Logdata       GrantS3                `json:"logdata"`
	Snapshot      GrantS3                `json:"snapshot"`
	EncryptionKey GrantLogsEncryptionKey `json:"encryption_key"`
}

type GrantLogsEncryptionKey

type GrantLogsEncryptionKey struct {
	CiphertextBlob string `json:"ciphertext_blob"`
	KeyId          string `json:"key_id"`
	Plaintext      string `json:"plaintext"`
}

type GrantS3

type GrantS3 struct {
	S3URL    string            `json:"s3_url"`
	S3Fields map[string]string `json:"s3_fields"`
}

type LogFile

type LogFile struct {
	LogLines []LogLine

	UUID       uuid.UUID
	S3Location string
	S3CekAlgo  string
	S3CmkKeyID string

	ByteSize     int64
	OriginalName string

	TmpFile *os.File

	FilterLogSecret []LogSecretKind
}

LogFile - Log file that we are uploading for reference in log line metadata

func (*LogFile) Cleanup

func (logFile *LogFile) Cleanup(logger *util.Logger)

type LogLine

type LogLine struct {
	UUID       uuid.UUID
	ParentUUID uuid.UUID

	ByteStart        int64
	ByteContentStart int64
	ByteEnd          int64 // Written log line ends *before* this index

	OccurredAt  time.Time
	Username    string
	Database    string
	Query       string
	Application string

	SchemaName   string
	RelationName string

	// Only used for collector-internal bookkeeping to determine how long to wait
	// for associating related loglines with each other
	CollectedAt time.Time

	LogLevel   pganalyze_collector.LogLineInformation_LogLevel
	BackendPid int32

	// %l in log_line_prefix (or similar in syslog)
	LogLineNumber int32

	// Syslog chunk number (within a particular line)
	LogLineNumberChunk int32

	Content string

	Classification pganalyze_collector.LogLineInformation_LogClassification

	Details map[string]interface{}

	RelatedPids []int32

	ReviewedForSecrets bool
	SecretMarkers      []LogSecretMarker
}

LogLine - "Line" in a Postgres log file, and the associated analysis metadata

type LogSecretKind

type LogSecretKind int

LogSecretKind - Enum to classify the kind of log secret identified by a marker

func ParseFilterLogSecret

func ParseFilterLogSecret(input string) (result []LogSecretKind)

type LogSecretMarker

type LogSecretMarker struct {
	// ! Note that these byte indices are from the *content* start of a log line
	ByteStart int // Start of the secret in the log line content
	ByteEnd   int // End of the secret in the log line content (secret ends *before* this index)
	Kind      LogSecretKind
}

LogSecretMarker - Marks log secrets in a log line

type Memory

type Memory struct {
	TotalBytes      uint64
	CachedBytes     uint64
	BuffersBytes    uint64
	FreeBytes       uint64
	WritebackBytes  uint64
	DirtyBytes      uint64
	SlabBytes       uint64
	MappedBytes     uint64
	PageTablesBytes uint64
	ActiveBytes     uint64
	InactiveBytes   uint64
	AvailableBytes  uint64
	SwapUsedBytes   uint64
	SwapTotalBytes  uint64

	HugePagesSizeBytes uint64
	HugePagesFree      uint64
	HugePagesTotal     uint64
	HugePagesReserved  uint64
	HugePagesSurplus   uint64

	ApplicationBytes uint64
}

Memory - Metrics related to system memory

type NetworkStats

type NetworkStats struct {
	DiffedOnInput bool // True if has already been diffed on input (and we can simply copy the diff)
	DiffedValues  *DiffedNetworkStats

	ReceiveThroughputBytes  uint64
	TransmitThroughputBytes uint64
}

NetworkStats - Information about the network activity on a single interface

func (NetworkStats) DiffSince

func (curr NetworkStats) DiffSince(prev NetworkStats, collectedIntervalSecs uint32) DiffedNetworkStats

DiffSince - Calculate the diff between two network stats runs

type NetworkStatsMap

type NetworkStatsMap map[string]NetworkStats

NetworkStatsMap - Map of all network statistics (Key = Interface Name)

type Oid

type Oid uint64

type OidToIdxMap

type OidToIdxMap map[Oid](map[Oid]int32)

func MakeOidToIdxMap

func MakeOidToIdxMap() OidToIdxMap

func (OidToIdxMap) Get

func (m OidToIdxMap) Get(dbOid, objOid Oid) int32

func (OidToIdxMap) Put

func (m OidToIdxMap) Put(dbOid, objOid Oid, idx int32)

type ParsedLogStreamItem added in v0.42.1

type ParsedLogStreamItem struct {
	Identifier config.ServerIdentifier
	LogLine    LogLine
}

type PersistedActivityState

type PersistedActivityState struct {
	ActivitySnapshotAt time.Time
}

type PersistedLogState

type PersistedLogState struct {
	// Markers for pagination of RDS log files
	//
	// We only remember markers for files that have received recent writes,
	// all other markers are discarded
	AwsMarkers map[string]string

	// Markers for pg_read_file-based access
	ReadFileMarkers map[string]int64
}

type PersistedState

type PersistedState struct {
	CollectedAt time.Time

	DatabaseStats  PostgresDatabaseStatsMap
	StatementStats PostgresStatementStatsMap
	SchemaStats    map[Oid]*SchemaStats

	Relations []PostgresRelation
	Functions []PostgresFunction

	System         SystemState
	CollectorStats CollectorStats

	// Incremented every run, indicates whether we should run a pg_stat_statements_reset()
	// on behalf of the user. Only activates once it reaches GrantFeatures.StatementReset,
	// and is reset afterwards.
	StatementResetCounter int

	// Keep track of when we last collected statement stats, to calculate time distance
	LastStatementStatsAt time.Time

	// All statement stats that have not been identified (will be cleared by the next full snapshot)
	UnidentifiedStatementStats HistoricStatementStatsMap
}

PersistedState - State thats kept across collector runs to be used for diffs

type PostgresBackend

type PostgresBackend struct {
	Identity        uint64      // Combination of process start time and PID, used to identify a process over time
	DatabaseOid     null.Int    // OID of the database this backend is connected to
	DatabaseName    null.String // Name of the database this backend is connected to
	RoleOid         null.Int    // OID of the user logged into this backend
	RoleName        null.String // Name of the user logged into this backend
	Pid             int32       // Process ID of this backend
	ApplicationName null.String // Name of the application that is connected to this backend
	ClientAddr      null.String // IP address of the client connected to this backend. If this field is null, it indicates either that the client is connected via a Unix socket on the server machine or that this is an internal process such as autovacuum.
	ClientPort      null.Int    // TCP port number that the client is using for communication with this backend, or -1 if a Unix socket is used
	BackendStart    null.Time   // Time when this process was started, i.e., when the client connected to the server
	XactStart       null.Time   // Time when this process' current transaction was started, or null if no transaction is active. If the current query is the first of its transaction, this column is equal to the query_start column.
	QueryStart      null.Time   // Time when the currently active query was started, or if state is not active, when the last query was started
	StateChange     null.Time   // Time when the state was last changed
	Waiting         null.Bool   // True if this backend is currently waiting on a lock
	BackendXid      null.Int    // Top-level transaction identifier of this backend, if any.
	BackendXmin     null.Int    // The current backend's xmin horizon.

	WaitEventType null.String // 9.6+ The type of event for which the backend is waiting, if any; otherwise NULL
	WaitEvent     null.String // 9.6+ Wait event name if backend is currently waiting, otherwise NULL

	BackendType null.String // 10+ The process type of this backend

	Query null.String // Text of this backend's most recent query

	// Current overall state of this backend. Possible values are:
	// - active: The backend is executing a query.
	// - idle: The backend is waiting for a new client command.
	// - idle in transaction: The backend is in a transaction, but is not currently executing a query.
	// - idle in transaction (aborted): This state is similar to idle in transaction, except one of the statements in the transaction caused an error.
	// - fastpath function call: The backend is executing a fast-path function.
	// - disabled: This state is reported if track_activities is disabled in this backend.
	State null.String

	BlockedByPids []int32 // The list of PIDs this backend is blocked by
}

PostgresBackend - PostgreSQL server backend thats currently working, waiting or idling (also known as an open connection)

See https://www.postgresql.org/docs/9.5/static/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW

type PostgresBackendCount

type PostgresBackendCount struct {
	DatabaseOid    null.Int // OID of the database
	RoleOid        null.Int // OID of the user
	State          string   // Current overall state of this backend
	BackendType    string   // The process type of this backend
	WaitingForLock bool     // True if this backend is currently waiting on a heavyweight lock
	Count          int32    // Number of this kind of backends
}

type PostgresBloatStats

type PostgresBloatStats struct {
	DatabaseName string
	Relations    []PostgresRelationBloat
	Indices      []PostgresIndexBloat
}

type PostgresBuffercache

type PostgresBuffercache struct {
	TotalBytes int64
	FreeBytes  int64

	Entries []PostgresBuffercacheEntry
}

PostgresBuffercache - Details on whats contained in the Postgres buffer cache

type PostgresBuffercacheEntry

type PostgresBuffercacheEntry struct {
	Bytes        int64
	DatabaseName string
	SchemaName   *string
	ObjectName   *string
	ObjectKind   *string
	Toast        bool
}

PostgresBuffercacheEntry - One entry in the buffercache statistics (already aggregated)

type PostgresColumn

type PostgresColumn struct {
	RelationOid  Oid
	Name         string
	DataType     string
	DefaultValue null.String
	NotNull      bool
	Position     int32
	TypeOid      Oid
}

type PostgresColumnStats added in v0.41.0

type PostgresColumnStats struct {
	SchemaName  string
	TableName   string
	ColumnName  string
	Inherited   bool
	NullFrac    float64
	AvgWidth    int32
	NDistinct   float64
	Correlation null.Float
}

type PostgresColumnStatsKey added in v0.41.0

type PostgresColumnStatsKey struct {
	SchemaName string
	TableName  string
	ColumnName string
}

PostgresColumnStatsKey - Information that uniquely identifies column stats

type PostgresColumnStatsMap added in v0.41.0

type PostgresColumnStatsMap map[PostgresColumnStatsKey][]PostgresColumnStats

type PostgresConstraint

type PostgresConstraint struct {
	RelationOid       Oid     // The table this constraint is on
	Name              string  // Constraint name (not necessarily unique!)
	Type              string  // c = check constraint, f = foreign key constraint, p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint
	ConstraintDef     string  // Human-readable representation of the expression
	Columns           []int32 // If a table constraint (including foreign keys, but not constraint triggers), list of the constrained columns
	ForeignOid        Oid     // If a foreign key, the referenced table
	ForeignColumns    []int32 // If a foreign key, list of the referenced columns
	ForeignUpdateType string  // Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
	ForeignDeleteType string  // Foreign key deletion action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
	ForeignMatchType  string  // Foreign key match type: f = full, p = partial, s = simple
}

type PostgresDatabase

type PostgresDatabase struct {
	Oid              Oid    // ID of this database
	Name             string // Database name
	OwnerRoleOid     Oid    // Owner of the database, usually the user who created it
	Encoding         string // Character encoding for this database
	Collate          string // LC_COLLATE for this database
	CType            string // LC_CTYPE for this database
	IsTemplate       bool   // 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.
	AllowConnections bool   // If false then no one can connect to this database. This is used to protect the template0 database from being altered.
	ConnectionLimit  int32  // Sets maximum number of concurrent connections that can be made to this database. -1 means no limit.

	// All transaction IDs before this one have been replaced with a permanent ("frozen") transaction ID in this database.
	// This is used to track whether the database needs to be vacuumed in order to prevent transaction ID wraparound or to
	// allow pg_clog to be shrunk. It is the minimum of the per-table pg_class.relfrozenxid values.
	FrozenXID Xid

	// All multixact IDs before this one have been replaced with a transaction ID in this database.
	// This is used to track whether the database needs to be vacuumed in order to prevent multixact ID wraparound or to
	// allow pg_multixact to be shrunk. It is the minimum of the per-table pg_class.relminmxid values.
	MinimumMultixactXID Xid
}

PostgresDatabase - A database in the PostgreSQL system, with multiple schemas and tables contained in it

type PostgresDatabaseStats added in v0.47.0

type PostgresDatabaseStats struct {
	FrozenXIDAge int32 // Age of FrozenXID
	MinMXIDAge   int32 // Age of MinimumMultixactXID
	XactCommit   int64 // Number of transactions in this database that have been committed
	XactRollback int64 // Number of transactions in this database that have been rolled back
}

PostgresDatabaseStats - Database statistics for a single database

func (PostgresDatabaseStats) DiffSince added in v0.47.0

DiffSince - Calculate the diff between two stats runs

type PostgresDatabaseStatsMap added in v0.47.0

type PostgresDatabaseStatsMap map[Oid]PostgresDatabaseStats

PostgresDatabaseStatsMap - Map of database statistics (key = database Oid)

type PostgresExtension added in v0.45.0

type PostgresExtension struct {
	DatabaseOid   Oid
	ExtensionName string
	Version       string
	SchemaName    string
}

PostgresExtension - an installed extension on a database

type PostgresForeignSerialColumn

type PostgresForeignSerialColumn struct {
	RelationOid  Oid
	SchemaName   string
	RelationName string
	ColumnName   string

	DataType     string
	MaximumValue uint64

	Inferred bool
}

type PostgresFunction

type PostgresFunction struct {
	Oid             Oid
	DatabaseOid     Oid
	SchemaName      string      `json:"schema_name"`
	FunctionName    string      `json:"function_name"`
	Language        string      `json:"language"`
	Source          string      `json:"source"`
	SourceBin       null.String `json:"source_bin"`
	Config          []string    `json:"config"`
	Arguments       string      `json:"arguments"`
	Result          string      `json:"result"`
	Kind            string      `json:"kind"`
	SecurityDefiner bool        `json:"security_definer"`
	Leakproof       bool        `json:"leakproof"`
	Strict          bool        `json:"strict"`
	ReturnsSet      bool        `json:"returns_set"`
	Volatile        string      `json:"volatile"`
}

PostgresFunction - Function/Stored Procedure that runs on the PostgreSQL server

type PostgresFunctionStats

type PostgresFunctionStats struct {
	Calls     int64   `json:"calls"`
	TotalTime float64 `json:"total_time"`
	SelfTime  float64 `json:"self_time"`
}

PostgresFunctionStats - Statistics about a single PostgreSQL function

Note that this will only be populated when "track_functions" is enabled.

func (PostgresFunctionStats) DiffSince

type PostgresFunctionStatsMap

type PostgresFunctionStatsMap map[Oid]PostgresFunctionStats

type PostgresIndex

type PostgresIndex struct {
	RelationOid   Oid
	IndexOid      Oid
	IndexType     string // Equivalent with pg_am.amname, e.g. "btree", "gist", "gin", "brin"
	Columns       []int32
	Name          string
	IsPrimary     bool
	IsUnique      bool
	IsValid       bool
	IndexDef      string
	ConstraintDef null.String
	Options       map[string]string
}

func (PostgresIndex) Fillfactor

func (i PostgresIndex) Fillfactor() int32

Fillfactor - Returns the FILLFACTOR storage parameter set on the index, the default if known (90 for btree), or -1 if unknown

type PostgresIndexBloat

type PostgresIndexBloat struct {
	SchemaName string
	IndexName  string
	TotalBytes int64
	BloatBytes int64
}

type PostgresIndexStats

type PostgresIndexStats struct {
	SizeBytes         int64
	IdxScan           int64 // Number of index scans initiated on this index
	IdxTupRead        int64 // Number of index entries returned by scans on this index
	IdxTupFetch       int64 // Number of live table rows fetched by simple index scans using this index
	IdxBlksRead       int64 // Number of disk blocks read from this index
	IdxBlksHit        int64 // Number of buffer hits in this index
	ExclusivelyLocked bool  // Whether these statistics are zeroed out because the index was locked at collection time
}

func (PostgresIndexStats) DiffSince

type PostgresIndexStatsMap

type PostgresIndexStatsMap map[Oid]PostgresIndexStats

type PostgresQuerySample

type PostgresQuerySample struct {
	OccurredAt time.Time
	Username   string
	Database   string
	Query      string
	Parameters []null.String

	LogLineUUID uuid.UUID

	RuntimeMs float64

	HasExplain        bool
	ExplainOutputText string
	ExplainOutputJSON *ExplainPlanContainer
	ExplainError      string
	ExplainFormat     pganalyze_collector.QuerySample_ExplainFormat
	ExplainSource     pganalyze_collector.QuerySample_ExplainSource
}

type PostgresRelation

type PostgresRelation struct {
	Oid                    Oid
	DatabaseOid            Oid
	SchemaName             string
	RelationName           string
	RelationType           string
	PersistenceType        string
	Columns                []PostgresColumn
	Indices                []PostgresIndex
	Constraints            []PostgresConstraint
	ViewDefinition         string
	Options                map[string]string
	HasOids                bool
	HasInheritanceChildren bool
	HasToast               bool
	FrozenXID              Xid
	MinimumMultixactXID    Xid
	ParentTableOid         Oid
	PartitionBoundary      string
	PartitionStrategy      string
	PartitionColumns       []int32
	PartitionedBy          string

	// True if another process is currently holding an AccessExclusiveLock on this
	// relation, this also means we don't collect columns/index/constraints data
	ExclusivelyLocked bool

	ToastName string
}

func (PostgresRelation) Fillfactor

func (r PostgresRelation) Fillfactor() int32

Fillfactor - Returns the FILLFACTOR storage parameter set on the table, or the default (100)

func (PostgresRelation) FullFrozenXID added in v0.47.0

func (r PostgresRelation) FullFrozenXID(currentXactId int64) int64

FullFrozenXID - Returns frozenXid in 64-bit FullTransactionId

type PostgresRelationBloat

type PostgresRelationBloat struct {
	SchemaName   string
	RelationName string
	TotalBytes   int64
	BloatBytes   int64
}

type PostgresRelationStats

type PostgresRelationStats struct {
	SizeBytes         int64     // On-disk size including FSM and VM, plus TOAST table if any, excluding indices
	ToastSizeBytes    int64     // TOAST table and TOAST index size (included in SizeBytes as well)
	SeqScan           int64     // Number of sequential scans initiated on this table
	SeqTupRead        int64     // Number of live rows fetched by sequential scans
	IdxScan           int64     // Number of index scans initiated on this table
	IdxTupFetch       int64     // Number of live rows fetched by index scans
	NTupIns           int64     // Number of rows inserted
	NTupUpd           int64     // Number of rows updated
	NTupDel           int64     // Number of rows deleted
	NTupHotUpd        int64     // Number of rows HOT updated (i.e., with no separate index update required)
	NLiveTup          int64     // Estimated number of live rows
	NDeadTup          int64     // Estimated number of dead rows
	NModSinceAnalyze  int64     // Estimated number of rows modified since this table was last analyzed
	NInsSinceVacuum   int64     // Estimated number of rows inserted since this table was last vacuumed
	LastVacuum        null.Time // Last time at which this table was manually vacuumed (not counting VACUUM FULL)
	LastAutovacuum    null.Time // Last time at which this table was vacuumed by the autovacuum daemon
	LastAnalyze       null.Time // Last time at which this table was manually analyzed
	LastAutoanalyze   null.Time // Last time at which this table was analyzed by the autovacuum daemon
	VacuumCount       int64     // Number of times this table has been manually vacuumed (not counting VACUUM FULL)
	AutovacuumCount   int64     // Number of times this table has been vacuumed by the autovacuum daemon
	AnalyzeCount      int64     // Number of times this table has been manually analyzed
	AutoanalyzeCount  int64     // Number of times this table has been analyzed by the autovacuum daemon
	HeapBlksRead      int64     // Number of disk blocks read from this table
	HeapBlksHit       int64     // Number of buffer hits in this table
	IdxBlksRead       int64     // Number of disk blocks read from all indexes on this table
	IdxBlksHit        int64     // Number of buffer hits in all indexes on this table
	ToastBlksRead     int64     // Number of disk blocks read from this table's TOAST table (if any)
	ToastBlksHit      int64     // Number of buffer hits in this table's TOAST table (if any)
	TidxBlksRead      int64     // Number of disk blocks read from this table's TOAST table indexes (if any)
	TidxBlksHit       int64     // Number of buffer hits in this table's TOAST table indexes (if any)
	FrozenXIDAge      int32     // Age of frozen XID for this table
	MinMXIDAge        int32     // Age of minimum multixact ID for this table
	Relpages          int32     // Size of the on-disk representation of this table in pages (of size BLCKSZ)
	Reltuples         float32   // Number of live rows in the table. -1 indicating that the row count is unknown
	Relallvisible     int32     // Number of pages that are marked all-visible in the table's visibility map
	ExclusivelyLocked bool      // Whether these statistics are zeroed out because the table was locked at collection time
	ToastReltuples    float32   // Number of live rows in the TOAST table. -1 indicating that the row count is unknown
	ToastRelpages     int32     // Size of the on-disk representation of the TOAST table in pages (of size BLCKSZ)
}

func (PostgresRelationStats) DiffSince

type PostgresRelationStatsExtended added in v0.53.0

type PostgresRelationStatsExtended struct {
	StatisticsSchema string
	StatisticsName   string
	Columns          []int32
	Expressions      []string
	Kind             []string
	Inherited        null.Bool
	NDistinct        null.String
	Dependencies     null.String
}

type PostgresRelationStatsExtendedMap added in v0.53.0

type PostgresRelationStatsExtendedMap map[Oid][]PostgresRelationStatsExtended

type PostgresRelationStatsMap

type PostgresRelationStatsMap map[Oid]PostgresRelationStats

type PostgresReplication

type PostgresReplication struct {
	InRecovery bool

	// Data available on primary
	CurrentXlogLocation null.String
	Standbys            []PostgresReplicationStandby

	// Data available on standby
	IsStreaming        null.Bool
	ReceiveLocation    null.String
	ReplayLocation     null.String
	ApplyByteLag       null.Int
	ReplayTimestamp    null.Time
	ReplayTimestampAge null.Int
}

type PostgresReplicationStandby

type PostgresReplicationStandby struct {
	ClientAddr string

	RoleOid         Oid
	Pid             int64
	ApplicationName string
	ClientHostname  null.String
	ClientPort      int32
	BackendStart    time.Time
	SyncPriority    int32
	SyncState       string

	State          string
	SentLocation   null.String
	WriteLocation  null.String
	FlushLocation  null.String
	ReplayLocation null.String
	RemoteByteLag  null.Int
	LocalByteLag   null.Int
}

PostgresReplicationStandby - Standby information as seen from the primary

type PostgresRole

type PostgresRole struct {
	Oid                Oid       // ID of role
	Name               string    // Role name
	Inherit            bool      // Role automatically inherits privileges of roles it is a member of
	Login              bool      // Role can log in. That is, this role can be given as the initial session authorization identifier
	CreateDb           bool      // Role can create databases
	CreateRole         bool      // Role can create more roles
	SuperUser          bool      // Role has superuser privileges
	Replication        bool      // Role can initiate streaming replication and put the system in and out of backup mode.
	BypassRLS          bool      // Role bypasses every row level security policy, see https://www.postgresql.org/docs/9.5/static/ddl-rowsecurity.html
	ConnectionLimit    int32     // For roles that can log in, this sets maximum number of concurrent connections this role can make. -1 means no limit.
	PasswordValidUntil null.Time // Password expiry time (only used for password authentication); null if no expiration
	Config             []string  // Role-specific defaults for run-time configuration variables
	MemberOf           []Oid     // List of roles that this role is a member of (i.e. whose permissions it inherits)
}

PostgresRole - A role in the PostgreSQL system - note that this includes users (Login=true)

type PostgresSequenceInformation

type PostgresSequenceInformation struct {
	SchemaName   string
	SequenceName string

	LastValue   int64
	StartValue  int64
	IncrementBy int64
	MaxValue    int64
	MinValue    int64
	CacheValue  int64
	IsCycled    bool
}

type PostgresSequenceInformationMap

type PostgresSequenceInformationMap map[Oid]PostgresSequenceInformation

type PostgresSequenceReport

type PostgresSequenceReport struct {
	DatabaseName string

	Sequences            PostgresSequenceInformationMap
	SerialColumns        []PostgresSerialColumn
	ForeignSerialColumns []PostgresForeignSerialColumn
}

type PostgresSerialColumn

type PostgresSerialColumn struct {
	RelationOid  Oid
	SchemaName   string
	RelationName string
	ColumnName   string
	DataType     string
	MaximumValue uint64
	SequenceOid  Oid

	ForeignColumns []PostgresForeignSerialColumn
}

type PostgresServerStats added in v0.47.0

type PostgresServerStats struct {
	CurrentXactId   Xid8
	NextMultiXactId Xid8

	XminHorizonBackend                Xid
	XminHorizonReplicationSlot        Xid
	XminHorizonReplicationSlotCatalog Xid
	XminHorizonPreparedXact           Xid
	XminHorizonStandby                Xid
}

PostgresServerStats - Statistics for a Postgres server.

func (PostgresServerStats) FullXminHorizonBackend added in v0.49.0

func (ss PostgresServerStats) FullXminHorizonBackend() int64

FullXminHorizonBackend - Returns XminHorizonBackend in 64-bit FullTransactionId

func (PostgresServerStats) FullXminHorizonPreparedXact added in v0.49.0

func (ss PostgresServerStats) FullXminHorizonPreparedXact() int64

FullXminHorizonPreparedXact - Returns XminHorizonPreparedXact in 64-bit FullTransactionId

func (PostgresServerStats) FullXminHorizonReplicationSlot added in v0.49.0

func (ss PostgresServerStats) FullXminHorizonReplicationSlot() int64

FullXminHorizonReplicationSlot - Returns XminHorizonReplicationSlot in 64-bit FullTransactionId

func (PostgresServerStats) FullXminHorizonReplicationSlotCatalog added in v0.49.0

func (ss PostgresServerStats) FullXminHorizonReplicationSlotCatalog() int64

FullXminHorizonReplicationSlotCatalog - Returns XminHorizonReplicationSlotCatalog in 64-bit FullTransactionId

func (PostgresServerStats) FullXminHorizonStandby added in v0.49.0

func (ss PostgresServerStats) FullXminHorizonStandby() int64

FullXminHorizonStandby - Returns XminHorizonStandby in 64-bit FullTransactionId

type PostgresSetting

type PostgresSetting struct {
	Name         string      `json:"name"`
	CurrentValue null.String `json:"current_value"`
	Unit         null.String `json:"unit"`
	BootValue    null.String `json:"boot_value"`
	ResetValue   null.String `json:"reset_value"`
	Source       null.String `json:"source"`
	SourceFile   null.String `json:"sourcefile"`
	SourceLine   null.String `json:"sourceline"`
}

type PostgresStatement

type PostgresStatement struct {
	Fingerprint           uint64 // Fingerprint for a specific statement
	QueryTextUnavailable  bool   // True if this represents a statement without query text
	InsufficientPrivilege bool   // True if we're missing permissions to see the statement
	Collector             bool   // True if this statement was produced by the pganalyze collector
}

PostgresStatement - Specific kind of statement that has run one or multiple times on the PostgreSQL server.

type PostgresStatementKey

type PostgresStatementKey struct {
	DatabaseOid Oid       // OID of database in which the statement was executed
	UserOid     Oid       // OID of user who executed the statement
	QueryID     int64     // Internal hash code, computed from the statement's parse tree (note pg_stat_statements stores this as a uint64, but returns it as a int64 in the user-facing API)
	TopLevel    null.Bool // Whether this statement was executed directly (at the top level), or from within a function / stored procedure (on older Postgres versions this is not tracked, so we set it to NULL)
}

PostgresStatementKey - Information that uniquely identifies a query (this needs to match pgssHashKey in pg_stat_statements.c)

type PostgresStatementMap

type PostgresStatementMap map[PostgresStatementKey]PostgresStatement

type PostgresStatementStats

type PostgresStatementStats struct {
	Calls             int64   // Number of times executed
	TotalTime         float64 // Total time spent in the statement, in milliseconds
	Rows              int64   // Total number of rows retrieved or affected by the statement
	SharedBlksHit     int64   // Total number of shared block cache hits by the statement
	SharedBlksRead    int64   // Total number of shared blocks read by the statement
	SharedBlksDirtied int64   // Total number of shared blocks dirtied by the statement
	SharedBlksWritten int64   // Total number of shared blocks written by the statement
	LocalBlksHit      int64   // Total number of local block cache hits by the statement
	LocalBlksRead     int64   // Total number of local blocks read by the statement
	LocalBlksDirtied  int64   // Total number of local blocks dirtied by the statement
	LocalBlksWritten  int64   // Total number of local blocks written by the statement
	TempBlksRead      int64   // Total number of temp blocks read by the statement
	TempBlksWritten   int64   // Total number of temp blocks written by the statement
	BlkReadTime       float64 // Total time the statement spent reading blocks, in milliseconds (if track_io_timing is enabled, otherwise zero)
	BlkWriteTime      float64 // Total time the statement spent writing blocks, in milliseconds (if track_io_timing is enabled, otherwise zero)
	MinTime           float64 // Minimum time spent in the statement, in milliseconds
	MaxTime           float64 // Maximum time spent in the statement, in milliseconds
	MeanTime          float64 // Mean time spent in the statement, in milliseconds
	StddevTime        float64 // Population standard deviation of time spent in the statement, in milliseconds
}

PostgresStatementStats - Statistics from pg_stat_statements extension for a given statement.

See also https://www.postgresql.org/docs/9.5/static/pgstatstatements.html

func (PostgresStatementStats) DiffSince

type PostgresStatementStatsTimeKey

type PostgresStatementStatsTimeKey struct {
	CollectedAt           time.Time
	CollectedIntervalSecs uint32
}

type PostgresStatementTextMap

type PostgresStatementTextMap map[uint64]string

type PostgresType added in v0.41.0

type PostgresType struct {
	Oid               Oid
	ArrayOid          Oid
	DatabaseOid       Oid
	SchemaName        string
	Name              string
	Type              string
	DomainType        null.String
	DomainNotNull     bool
	DomainDefault     null.String
	DomainConstraints []string
	EnumValues        []string
	CompositeAttrs    [][2]string
}

PostgresType - User-defined custom data types

type PostgresVacuumProgress

type PostgresVacuumProgress struct {
	VacuumIdentity  uint64 // Combination of vacuum "query" start time and PID, used to identify a vacuum over time
	BackendIdentity uint64 // Combination of process start time and PID, used to identify a process over time

	DatabaseName string
	SchemaName   string
	RelationName string
	RoleName     string
	StartedAt    time.Time
	Autovacuum   bool
	Toast        bool

	Phase            string
	HeapBlksTotal    int64
	HeapBlksScanned  int64
	HeapBlksVacuumed int64
	IndexVacuumCount int64
	MaxDeadTuples    int64
	NumDeadTuples    int64
}

PostgresVacuumProgress - PostgreSQL vacuum thats currently running

See https://www.postgresql.org/docs/10/static/progress-reporting.html

type PostgresVacuumStats

type PostgresVacuumStats struct {
	DatabaseName string

	// Database-wide settings
	AutovacuumMaxWorkers     int32
	AutovacuumNaptimeSeconds int32

	// Defaults for per-table settings
	AutovacuumEnabled               bool
	AutovacuumVacuumThreshold       int32
	AutovacuumAnalyzeThreshold      int32
	AutovacuumVacuumScaleFactor     float64
	AutovacuumAnalyzeScaleFactor    float64
	AutovacuumFreezeMaxAge          int32
	AutovacuumMultixactFreezeMaxAge int32
	AutovacuumVacuumCostDelay       int32
	AutovacuumVacuumCostLimit       int32

	Relations []PostgresVacuumStatsEntry
}

PostgresVacuumStats - Details on VACUUM configuration and expected runs

type PostgresVacuumStatsEntry

type PostgresVacuumStatsEntry struct {
	SchemaName   string
	RelationName string

	LiveRowCount int32
	DeadRowCount int32
	Relfrozenxid int32
	Relminmxid   int32

	LastManualVacuumRun  null.Time
	LastAutoVacuumRun    null.Time
	LastManualAnalyzeRun null.Time
	LastAutoAnalyzeRun   null.Time

	AutovacuumEnabled               bool
	AutovacuumVacuumThreshold       int32
	AutovacuumAnalyzeThreshold      int32
	AutovacuumVacuumScaleFactor     float64
	AutovacuumAnalyzeScaleFactor    float64
	AutovacuumFreezeMaxAge          int32
	AutovacuumMultixactFreezeMaxAge int32
	AutovacuumVacuumCostDelay       int32
	AutovacuumVacuumCostLimit       int32

	Fillfactor int32
}

PostgresVacuumStatsEntry - One entry in the VACUUM statistics

type PostgresVersion

type PostgresVersion struct {
	Full    string `json:"full"`    // e.g. "PostgreSQL 9.5.1 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit"
	Short   string `json:"short"`   // e.g. "9.5.1"
	Numeric int    `json:"numeric"` // e.g. 90501

	// For collector use only, to avoid calling functions that don't work
	IsAwsAurora bool
	IsCitus     bool
}

PostgresVersion - Identifying information about the PostgreSQL server version and build details

type Scheduler

type Scheduler struct {
	Loadavg1min  float64
	Loadavg5min  float64
	Loadavg15min float64
}

Scheduler - Information about the OS scheduler

type SchemaStats

type SchemaStats struct {
	RelationStats         PostgresRelationStatsMap
	ColumnStats           PostgresColumnStatsMap
	RelationStatsExtended PostgresRelationStatsExtendedMap
	IndexStats            PostgresIndexStatsMap
	FunctionStats         PostgresFunctionStatsMap
}

type SelfTestResult added in v0.56.0

type SelfTestResult struct {
	CollectionSuspended struct {
		Value bool
		Msg   string
	}
	MonitoredDbs        []string
	AspectStatuses      map[CollectionAspect]*CollectionAspectStatus
	AllDbAspectStatuses map[DbCollectionAspect](map[string]*CollectionAspectStatus)
	// contains filtered or unexported fields
}

func MakeSelfTest added in v0.56.0

func MakeSelfTest() (s *SelfTestResult)

func (*SelfTestResult) GetCollectionAspectStatus added in v0.56.0

func (s *SelfTestResult) GetCollectionAspectStatus(aspect CollectionAspect) *CollectionAspectStatus

func (*SelfTestResult) GetDbCollectionAspectStatus added in v0.56.0

func (s *SelfTestResult) GetDbCollectionAspectStatus(dbName string, aspect DbCollectionAspect) *CollectionAspectStatus

func (*SelfTestResult) HintCollectionAspect added in v0.56.0

func (s *SelfTestResult) HintCollectionAspect(aspect CollectionAspect, format string, args ...any)

func (*SelfTestResult) HintDbCollectionAspect added in v0.56.0

func (s *SelfTestResult) HintDbCollectionAspect(dbName string, aspect DbCollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkCollectionAspect added in v0.56.0

func (s *SelfTestResult) MarkCollectionAspect(aspect CollectionAspect, state CollectionStateCode, format string, args ...any)

func (*SelfTestResult) MarkCollectionAspectError added in v0.56.0

func (s *SelfTestResult) MarkCollectionAspectError(aspect CollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkCollectionAspectNotAvailable added in v0.56.0

func (s *SelfTestResult) MarkCollectionAspectNotAvailable(aspect CollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkCollectionAspectOk added in v0.56.0

func (s *SelfTestResult) MarkCollectionAspectOk(aspect CollectionAspect)

func (*SelfTestResult) MarkCollectionAspectWarning added in v0.56.0

func (s *SelfTestResult) MarkCollectionAspectWarning(aspect CollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkCollectionSuspended added in v0.56.0

func (s *SelfTestResult) MarkCollectionSuspended(format string, args ...any)

collection suspended (e.g., if replica)

func (*SelfTestResult) MarkDbCollectionAspect added in v0.56.0

func (s *SelfTestResult) MarkDbCollectionAspect(dbName string, aspect DbCollectionAspect, state CollectionStateCode, format string, args ...any)

func (*SelfTestResult) MarkDbCollectionAspectError added in v0.56.0

func (s *SelfTestResult) MarkDbCollectionAspectError(dbName string, aspect DbCollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkDbCollectionAspectNotAvailable added in v0.56.0

func (s *SelfTestResult) MarkDbCollectionAspectNotAvailable(dbName string, aspect DbCollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkDbCollectionAspectOk added in v0.56.0

func (s *SelfTestResult) MarkDbCollectionAspectOk(dbName string, aspect DbCollectionAspect)

func (*SelfTestResult) MarkDbCollectionAspectWarning added in v0.56.0

func (s *SelfTestResult) MarkDbCollectionAspectWarning(dbName string, aspect DbCollectionAspect, format string, args ...any)

func (*SelfTestResult) MarkMonitoredDb added in v0.56.0

func (s *SelfTestResult) MarkMonitoredDb(dbName string)

func (*SelfTestResult) MarkRemainingDbCollectionAspectError added in v0.56.0

func (s *SelfTestResult) MarkRemainingDbCollectionAspectError(aspect DbCollectionAspect, format string, args ...any)

type Server

type Server struct {
	Config           config.ServerConfig
	RequestedSslMode string
	Grant            Grant
	PGAnalyzeURL     string

	PrevState  PersistedState
	StateMutex *sync.Mutex

	LogPrevState  PersistedLogState
	LogStateMutex *sync.Mutex

	ActivityPrevState  PersistedActivityState
	ActivityStateMutex *sync.Mutex

	CollectionStatus      CollectionStatus
	CollectionStatusMutex *sync.Mutex

	SelfTest *SelfTestResult

	// The time zone that logs are parsed in, synced from the setting log_timezone
	// The StateMutex should be held while updating this
	LogTimezone      *time.Location
	LogTimezoneMutex *sync.Mutex

	// Boolean flags for which log lines should be ignored for processing
	//
	// Internally this uses atomics (not a mutex) due to noticable performance
	// differences (see https://groups.google.com/g/golang-nuts/c/eIqkhXh9PLg),
	// as we access this in high frequency log-related code paths.
	LogIgnoreFlags uint32

	// State to track compact snapshot submissions, and log them routinely
	CompactLogStats map[string]uint8
	CompactLogTime  time.Time
}

func MakeServer added in v0.51.0

func MakeServer(config config.ServerConfig, testRun bool) *Server

func (*Server) GetLogTimezone added in v0.51.0

func (s *Server) GetLogTimezone() *time.Location

func (*Server) IgnoreLogLine added in v0.45.0

func (s *Server) IgnoreLogLine(content string) bool

IgnoreLogLine - helper function that lets callers determine whether a log line should be filtered out early (before any analysis)

This is mainly intended to support Log Insights for servers that have very high log volume due to running with log_statement=all or log_duration=on (something we can't parse effectively with today's regexp-based log parsing), and allow other less frequent log events to be analyzed.

func (*Server) SetLogIgnoreFlags added in v0.45.0

func (s *Server) SetLogIgnoreFlags(ignoreStatement bool, ignoreDuration bool)

func (*Server) SetLogTimezone added in v0.51.0

func (s *Server) SetLogTimezone(settings []PostgresSetting)

type StateOnDisk

type StateOnDisk struct {
	FormatVersion uint

	PrevStateByServer map[config.ServerIdentifier]PersistedState
}

type SystemInfo

type SystemInfo struct {
	Type        SystemType
	SystemScope string
	SystemID    string

	SelfHosted    *SystemInfoSelfHosted
	AmazonRds     *SystemInfoAmazonRds
	CrunchyBridge *SystemInfoCrunchyBridge
	ResourceTags  map[string]string

	BootTime time.Time
}

type SystemInfoAmazonRds

type SystemInfoAmazonRds struct {
	Region                      string
	InstanceClass               string
	InstanceID                  string
	Status                      string
	AvailabilityZone            string
	PubliclyAccessible          bool
	MultiAz                     bool
	SecondaryAvailabilityZone   string
	CaCertificate               string
	AutoMinorVersionUpgrade     bool
	PreferredMaintenanceWindow  string
	PreferredBackupWindow       string
	LatestRestorableTime        time.Time
	BackupRetentionPeriodDays   int32
	MasterUsername              string
	InitialDbName               string
	CreatedAt                   time.Time
	StorageProvisionedIOPS      int32
	StorageAllocatedGigabytes   int32
	StorageEncrypted            bool
	StorageType                 string
	EnhancedMonitoring          bool
	PerformanceInsights         bool
	PostgresLogExport           bool
	IAMAuthentication           bool
	DeletionProtection          bool
	ParameterApplyStatus        string
	ParameterPgssEnabled        bool
	ParameterAutoExplainEnabled bool
	IsAuroraPostgres            bool
}

SystemInfoAmazonRds - System information for Amazon RDS systems

type SystemInfoCrunchyBridge added in v0.52.3

type SystemInfoCrunchyBridge struct {
	ClusterName string
	CreatedAt   time.Time
	PlanID      string
	ProviderID  string
	RegionID    string
	CPUUnits    int32
	StorageGB   int32
	MemoryGB    float32
}

SystemInfoCrunchyBridge - System information for Crunchy Bridge systems

type SystemInfoSelfHosted

type SystemInfoSelfHosted struct {
	Hostname                 string
	Architecture             string
	OperatingSystem          string
	Platform                 string
	PlatformFamily           string
	PlatformVersion          string
	VirtualizationSystem     string // Name of the virtualization system (only if we're a guest)
	KernelVersion            string
	DatabaseSystemIdentifier string
}

SystemInfoSelfHosted - System information for self-hosted systems (both physical and virtual)

type SystemState

type SystemState struct {
	Info         SystemInfo
	Scheduler    Scheduler
	Memory       Memory
	CPUInfo      CPUInformation
	CPUStats     CPUStatisticMap
	NetworkStats NetworkStatsMap

	Disks          DiskMap
	DiskStats      DiskStatsMap
	DiskPartitions DiskPartitionMap

	DataDirectoryPartition string // Partition that the data directory lives on (identified by the partition's mountpoint)
	XlogPartition          string // Partition that the WAL directory lives on
	XlogUsedBytes          uint64
}

SystemState - All kinds of system-related information and metrics

type SystemType

type SystemType int

SystemType - Enum that describes which kind of system we're monitoring

const (
	SelfHostedSystem SystemType = iota
	AmazonRdsSystem
	HerokuSystem
	GoogleCloudSQLSystem
	AzureDatabaseSystem
	CrunchyBridgeSystem
	AivenSystem
	TemboSystem
)

Treat this list as append-only and never change the order

type TransientActivityState

type TransientActivityState struct {
	CollectedAt time.Time

	TrackActivityQuerySize int

	Version  PostgresVersion
	Backends []PostgresBackend

	Vacuums []PostgresVacuumProgress
}

type TransientLogState

type TransientLogState struct {
	CollectedAt time.Time

	LogFiles     []LogFile
	QuerySamples []PostgresQuerySample
}

func (*TransientLogState) Cleanup

func (ls *TransientLogState) Cleanup(logger *util.Logger)

type TransientState

type TransientState struct {
	// Databases we connected to and fetched local catalog data (e.g. schema)
	DatabaseOidsWithLocalCatalog []Oid

	Roles     []PostgresRole
	Databases []PostgresDatabase
	Types     []PostgresType

	Statements             PostgresStatementMap
	StatementTexts         PostgresStatementTextMap
	HistoricStatementStats HistoricStatementStatsMap

	// This is a new zero value that was recorded after a pg_stat_statements_reset(),
	// in order to enable the next snapshot to be able to diff against something
	ResetStatementStats PostgresStatementStatsMap

	ServerStats   PostgresServerStats
	Replication   PostgresReplication
	Settings      []PostgresSetting
	BackendCounts []PostgresBackendCount
	Extensions    []PostgresExtension

	Version PostgresVersion

	SentryClient *raven.Client

	CollectorConfig   CollectorConfig
	CollectorPlatform CollectorPlatform
}

TransientState - State thats only used within a collector run (and not needed for diffs)

type Xid

type Xid uint32 // 32-bit transaction ID

type Xid8 added in v0.47.0

type Xid8 uint64 // 64-bit transaction ID

func XidToXid8 added in v0.49.0

func XidToXid8(xid Xid, currentXactId Xid8) Xid8

XidToXid8 - Converts Xid (32-bit transaction ID) to Xid8 (64-bit FullTransactionId) by calculating and adding an epoch from the current transaction ID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL