Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef RUDB_AWR_HPP
#define RUDB_AWR_HPP
 
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
 
extern "C" void rudb_awr_init(void);
extern "C" void rudb_awr_postmaster_init(void);
 
extern "C"
{
#include "postgres.h"
#include "utils/timestamp.h"
}
 
/**
 * Назначение:
 * Управление локальными снимками AWR, архивирование записей ASH
 * и подготовка данных для отчётных пакетов.
 */
namespace rudb::awr
{
enum class WorkerState : int
{
    Empty = 0,
    Pending,
    Starting,
    Running,
    Backoff,
    Disabled,
    Stopping,
    Error
};
 
/** Параметры XML с метаданными выбора временного диапазона. */
struct TimepickerMetadataRequest
{
    bool include_metadata = false;
    int64_t dbid = 0;
    int retention_seconds = 0;
};
 
/** Границы отчёта по снимкам AWR применяются как (начало, конец]. */
struct SnapshotReportRequest
{
    int64_t dbid = 0;
    int64_t inst_num = 1;
    int64_t begin_snap_id = 0;
    int64_t end_snap_id = 0;
    std::optional<int64_t> options;
};
 
/** Параметры SQL-отчёта с необязательным ограничением SQL_ID и DBID контейнера. */
struct SqlReportRequest
{
    int64_t dbid = 0;
    int64_t inst_num = 1;
    int64_t begin_snap_id = 0;
    int64_t end_snap_id = 0;
    std::optional<std::string> sql_id;
    std::optional<int64_t> options;
    std::optional<int64_t> con_dbid;
};
 
// Инициализация и локальный DBID.
void initialize(void);
bool is_initialized(void);
int64_t local_dbid(void);
std::optional<int64_t> get_awr_id(const std::optional<std::string>& hub_name,
                                  const std::optional<std::string>& source_name);
int64_t validate_local_dbid(const std::optional<int64_t>& requested_dbid);
// Создание и удаление снимков AWR.
const char* launcher_database(void);
int snapshot_interval_seconds(void);
int retention_seconds(void);
int effective_snapshot_interval_seconds(int64_t dbid);
int effective_retention_seconds(int64_t dbid);
void modify_snapshot_settings(int64_t dbid,
                              const std::optional<int>& retention_minutes,
                              const std::optional<int>& interval_minutes);
void maybe_rotate_snapshot_marker(TimestampTz now);
int64_t create_snapshot(int64_t dbid, int64_t instance_number, bool automatic = false);
void drop_snapshot_range(int64_t dbid, int64_t low_snap_id, int64_t high_snap_id);
void purge_expired_history(int64_t dbid, TimestampTz now);
// Формирование отчётов.
std::vector<std::string> report_text(const SnapshotReportRequest& request);
std::vector<std::string> report_html(const SnapshotReportRequest& request);
std::vector<std::string> sql_report_text(const SqlReportRequest& request);
std::vector<std::string> sql_report_html(const SqlReportRequest& request);
// Метаданные выбора временного диапазона.
std::string build_timepicker_metadata_xml(const TimepickerMetadataRequest& request);
// Состояние механизма.
std::string service_state(void);
} // namespace rudb::awr
 
#endif