|
| 1 | +:sectnums: |
| 2 | +:sectnumlevels: 5 |
| 3 | + |
| 4 | += pgnodemx |
| 5 | + |
| 6 | +== Overview |
| 7 | + |
| 8 | +`pgnodemx` exposes Linux operating-system, process, filesystem, cgroup, and Kubernetes Downward API metrics through SQL. Monitoring agents can collect node and IvorySQL process metrics over an existing database connection without deploying a separate exporter endpoint. |
| 9 | + |
| 10 | +This guide was verified with IvorySQL 5.4 (PostgreSQL 18.4) and pgnodemx 1.7 on Ubuntu 22.04 x86_64. |
| 11 | + |
| 12 | +== Verified compatibility |
| 13 | + |
| 14 | +[cols="2,1,3"] |
| 15 | +|=== |
| 16 | +|Capability |Status |Verification |
| 17 | + |
| 18 | +|PGXS build and installation |
| 19 | +|Supported |
| 20 | +|pgnodemx 1.7 built against IvorySQL 5.4 headers and libraries |
| 21 | + |
| 22 | +|Linux `/proc` metrics |
| 23 | +|Supported |
| 24 | +|Memory, disk, process, network, load, and mount functions returned data |
| 25 | + |
| 26 | +|cgroup detection |
| 27 | +|Supported with limitations |
| 28 | +|`cgroup_mode()` detected the host layout; upstream pgnodemx 1.7 does not support hybrid-mode metric reads |
| 29 | + |
| 30 | +|Oracle-compatible sessions |
| 31 | +|Supported |
| 32 | +|Version, memory, and disk metric queries succeeded after switching compatibility mode |
| 33 | + |
| 34 | +|Kubernetes Downward API |
| 35 | +|Environment dependent |
| 36 | +|Available when the configured Downward API volume exists |
| 37 | +|=== |
| 38 | + |
| 39 | +== Prerequisites |
| 40 | + |
| 41 | +* IvorySQL 5.4 was built with server development headers and PGXS installed. |
| 42 | +* The target is Linux and exposes the required `/proc` and cgroup files to the IvorySQL server process. |
| 43 | +* A C compiler and GNU make are installed. |
| 44 | +* pgnodemx must be built with the same OpenSSL headers and libraries used by IvorySQL. |
| 45 | + |
| 46 | +[IMPORTANT] |
| 47 | +Do not mix OpenSSL major versions in the IvorySQL server process. If startup reports an undefined OpenSSL symbol after adding pgnodemx, rebuild pgnodemx against the matching IvorySQL build environment. Linking a second incompatible OpenSSL library into the extension is not a safe workaround. |
| 48 | + |
| 49 | +== Build and install |
| 50 | + |
| 51 | +[source,shell] |
| 52 | +---- |
| 53 | +git clone --branch v1.7 --depth 1 \ |
| 54 | + https://github.com/CrunchyData/pgnodemx.git |
| 55 | +cd pgnodemx |
| 56 | +
|
| 57 | +make USE_PGXS=1 \ |
| 58 | + PG_CONFIG=/usr/local/ivorysql/ivorysql-5/bin/pg_config |
| 59 | +sudo make USE_PGXS=1 \ |
| 60 | + PG_CONFIG=/usr/local/ivorysql/ivorysql-5/bin/pg_config install |
| 61 | +---- |
| 62 | + |
| 63 | +Confirm that the selected `pg_config` belongs to IvorySQL 5.4 before compiling: |
| 64 | + |
| 65 | +[source,shell] |
| 66 | +---- |
| 67 | +/usr/local/ivorysql/ivorysql-5/bin/pg_config --version |
| 68 | +---- |
| 69 | + |
| 70 | +== Configure preloading |
| 71 | + |
| 72 | +Append pgnodemx to the existing `shared_preload_libraries` value in `postgresql.conf`. Do not remove IvorySQL's existing preload libraries. |
| 73 | + |
| 74 | +[source,ini] |
| 75 | +---- |
| 76 | +shared_preload_libraries = 'liboracle_parser, ivorysql_ora, gb18030_2022, pgnodemx' |
| 77 | +---- |
| 78 | + |
| 79 | +For a non-Kubernetes host, disable Downward API access to avoid unnecessary startup warnings: |
| 80 | + |
| 81 | +[source,ini] |
| 82 | +---- |
| 83 | +pgnodemx.kdapi_enabled = off |
| 84 | +---- |
| 85 | + |
| 86 | +The other relevant defaults are: |
| 87 | + |
| 88 | +[source,ini] |
| 89 | +---- |
| 90 | +pgnodemx.cgroup_enabled = on |
| 91 | +pgnodemx.containerized = off |
| 92 | +pgnodemx.cgrouproot = '/sys/fs/cgroup' |
| 93 | +pgnodemx.kdapi_path = '/etc/podinfo' |
| 94 | +---- |
| 95 | + |
| 96 | +Restart IvorySQL after changing `shared_preload_libraries`, then create the extension in each database that will expose metrics: |
| 97 | + |
| 98 | +[source,sql] |
| 99 | +---- |
| 100 | +CREATE EXTENSION pgnodemx; |
| 101 | +
|
| 102 | +SELECT extversion |
| 103 | +FROM pg_extension |
| 104 | +WHERE extname = 'pgnodemx'; |
| 105 | +---- |
| 106 | + |
| 107 | +The expected extension version is `1.7`. |
| 108 | + |
| 109 | +== Grant monitoring access |
| 110 | + |
| 111 | +pgnodemx checks that callers belong to the predefined `pg_monitor` role. Grant that role to a dedicated monitoring login rather than allowing the monitoring agent to connect as a superuser. |
| 112 | + |
| 113 | +[source,sql] |
| 114 | +---- |
| 115 | +CREATE ROLE node_monitor LOGIN PASSWORD 'replace-with-a-strong-password'; |
| 116 | +GRANT pg_monitor TO node_monitor; |
| 117 | +GRANT CONNECT ON DATABASE monitoring TO node_monitor; |
| 118 | +---- |
| 119 | + |
| 120 | +Also restrict `pg_hba.conf`, network access, and TLS configuration to the monitoring system. |
| 121 | + |
| 122 | +== Query metrics |
| 123 | + |
| 124 | +=== Extension and runtime information |
| 125 | + |
| 126 | +[source,sql] |
| 127 | +---- |
| 128 | +SELECT pgnodemx_version(); |
| 129 | +SELECT exec_path(); |
| 130 | +SELECT openssl_version(); |
| 131 | +SELECT cgroup_mode(); |
| 132 | +---- |
| 133 | + |
| 134 | +=== Memory, CPU, disk, and network information |
| 135 | + |
| 136 | +[source,sql] |
| 137 | +---- |
| 138 | +SELECT * FROM proc_meminfo() |
| 139 | +WHERE key IN ('MemTotal', 'MemAvailable'); |
| 140 | +
|
| 141 | +SELECT * FROM proc_loadavg(); |
| 142 | +SELECT * FROM proc_cputime(); |
| 143 | +SELECT * FROM proc_diskstats(); |
| 144 | +SELECT * FROM proc_network_stats(); |
| 145 | +---- |
| 146 | + |
| 147 | +=== IvorySQL process information |
| 148 | + |
| 149 | +[source,sql] |
| 150 | +---- |
| 151 | +SELECT * FROM proc_pid_cmdline(); |
| 152 | +SELECT * FROM proc_pid_io(); |
| 153 | +SELECT * FROM proc_pid_stat(); |
| 154 | +---- |
| 155 | + |
| 156 | +The functions read the operating-system view visible to the IvorySQL process. In a container, results therefore describe the namespaces and mounted filesystems made available to that container. |
| 157 | + |
| 158 | +== Oracle-compatible mode |
| 159 | + |
| 160 | +The extension remains available after a session changes mode: |
| 161 | + |
| 162 | +[source,sql] |
| 163 | +---- |
| 164 | +SET ivorysql.compatible_mode = oracle; |
| 165 | +
|
| 166 | +SELECT pgnodemx_version() FROM dual; |
| 167 | +SELECT val FROM proc_meminfo() WHERE key = 'MemTotal'; |
| 168 | +SELECT count(*) FROM proc_diskstats(); |
| 169 | +---- |
| 170 | + |
| 171 | +All three queries completed successfully in the IvorySQL 5.4 validation. |
| 172 | + |
| 173 | +== Limitations and security |
| 174 | + |
| 175 | +* pgnodemx 1.7 supports cgroup v1 (`legacy`) and cgroup v2 (`unified`), but not the mixed `hybrid` layout. `/proc` functions remain usable when cgroup metric access is unavailable. |
| 176 | +* Kubernetes functions return NULL or no rows when `pgnodemx.kdapi_path` is absent; disable the facility outside Kubernetes. |
| 177 | +* Host files can contain sensitive process, mount, and environment information. Grant `pg_monitor` only to trusted monitoring roles. |
| 178 | +* Metric collection adds SQL and filesystem-read workload. Set an appropriate polling interval and select only required columns/functions. |
| 179 | +* This extension is Linux-specific and depends on the files exposed by the kernel, container runtime, and security policy. |
| 180 | + |
| 181 | +For the complete function list, see the https://access.crunchydata.com/documentation/pgnodemx/1.7/[pgnodemx 1.7 documentation]. |
0 commit comments