|
| 1 | +--- |
| 2 | +title: Command-Line Options & Environment Variables |
| 3 | +--- |
| 4 | + |
| 5 | +## General Usage |
| 6 | + |
| 7 | +```terminal |
| 8 | + pgwatch [OPTIONS] [config | metric | source] |
| 9 | +``` |
| 10 | + |
| 11 | +When no command is specified, the default is to start in a monitoring mode. pgwatch will read the |
| 12 | +configuration from the specified sources and metrics first, and then will start the measurements collection |
| 13 | +from resolved databases. |
| 14 | + |
| 15 | +## Options |
| 16 | + |
| 17 | +### Sources |
| 18 | + |
| 19 | +- `-s`, `--sources=` |
| 20 | + |
| 21 | + Postgres URI, file or folder of YAML files containing info on which DBs to monitor. |
| 22 | + ENV: `$PW_SOURCES` |
| 23 | + |
| 24 | + Examples: `postgresql://pgwatch@localhost:5432/pgwatch`, |
| 25 | + `/etc/sources.yaml`, |
| 26 | + `/etc/pgwatch/sources/` |
| 27 | + |
| 28 | +- `--refresh=` |
| 29 | + |
| 30 | + How frequently to resync sources and metrics (default: 120). |
| 31 | + ENV: `$PW_REFRESH` |
| 32 | + |
| 33 | +- `-g`, `--group=` |
| 34 | + |
| 35 | + Groups for filtering which databases to monitor. By default all are monitored. |
| 36 | + ENV: `$PW_GROUP` |
| 37 | + |
| 38 | +- `--min-db-size-mb=` |
| 39 | + |
| 40 | + Smaller size databases will be ignored and not monitored until they reach the threshold (default: 0). |
| 41 | + ENV: `$PW_MIN_DB_SIZE_MB` |
| 42 | + |
| 43 | +- `--max-parallel-connections-per-db=` |
| 44 | + |
| 45 | + Max parallel metric fetches per monitored database. Note the multiplication effect on multi-DB instances (default: 4). |
| 46 | + ENV: `$PW_MAX_PARALLEL_CONNECTIONS_PER_DB` |
| 47 | + |
| 48 | +- `--try-create-listed-exts-if-missing=` |
| 49 | + |
| 50 | + Try creating the listed extensions (comma sep.) on first connect for all monitored DBs when missing. Main usage - pg_stat_statements. |
| 51 | + ENV: `$PW_TRY_CREATE_LISTED_EXTS_IF_MISSING` |
| 52 | + |
| 53 | + Example: `pg_stat_statements,pg_hint_plan` |
| 54 | + |
| 55 | +### Metrics |
| 56 | + |
| 57 | +- `-m`, `--metrics=` |
| 58 | + |
| 59 | + Postgres URI, YAML file or folder of YAML files with metrics definitions. |
| 60 | + ENV: `$PW_METRICS` |
| 61 | + |
| 62 | +- `--create-helpers` |
| 63 | + |
| 64 | + Create helper database objects from metric definitions. |
| 65 | + ENV: `$PW_CREATE_HELPERS` |
| 66 | + |
| 67 | +- `--direct-os-stats` |
| 68 | + |
| 69 | + Extract OS related psutil statistics not via PL/Python wrappers but directly on host. |
| 70 | + ENV: `$PW_DIRECT_OS_STATS` |
| 71 | + |
| 72 | +- `--instance-level-cache-max-seconds=` |
| 73 | + |
| 74 | + Max allowed staleness for instance level metric data shared between DBs of an instance. Set to 0 to disable (default: 30). |
| 75 | + ENV: `$PW_INSTANCE_LEVEL_CACHE_MAX_SECONDS` |
| 76 | + |
| 77 | +- `--emergency-pause-triggerfile=` |
| 78 | + |
| 79 | + When the file exists no metrics will be temporarily fetched / scraped (default: /tmp/pgwatch-emergency-pause). |
| 80 | + ENV: `$PW_EMERGENCY_PAUSE_TRIGGERFILE` |
| 81 | + |
| 82 | +### Sinks |
| 83 | + |
| 84 | +- `--sink=` |
| 85 | + |
| 86 | + URI where metrics will be stored, can be used multiple times. |
| 87 | + ENV: `$PW_SINK` |
| 88 | + |
| 89 | + Examples: `postgresql://pgwatch@localhost:5432/metrics`, |
| 90 | + `prometheus://localhost:9090`, |
| 91 | + `jsonfile:///tmp/metrics.json`, |
| 92 | + `rpc://localhost:5000/` |
| 93 | + |
| 94 | +- `--batching-delay=` |
| 95 | + |
| 96 | + Max milliseconds to wait for a batched metrics flush (default: 250ms). |
| 97 | + ENV: `$PW_BATCHING_DELAY` |
| 98 | + |
| 99 | +- `--retention=` |
| 100 | + |
| 101 | + If set, metrics older than that will be deleted (default: 14). |
| 102 | + ENV: `$PW_RETENTION` |
| 103 | + |
| 104 | +- `--real-dbname-field=` |
| 105 | + |
| 106 | + Tag key for real database name (default: real_dbname). |
| 107 | + ENV: `$PW_REAL_DBNAME_FIELD` |
| 108 | + |
| 109 | +- `--system-identifier-field=` |
| 110 | + |
| 111 | + Tag key for system identifier value (default: sys_id). |
| 112 | + ENV: `$PW_SYSTEM_IDENTIFIER_FIELD` |
| 113 | + |
| 114 | +### Logging |
| 115 | + |
| 116 | +- `--log-level=[debug|info|error]` |
| 117 | + |
| 118 | + Verbosity level for stdout and log file (default: info) |
| 119 | + |
| 120 | +- `--log-file=` |
| 121 | + |
| 122 | + File name to store logs |
| 123 | + |
| 124 | +- `--log-file-format=[json|text]` |
| 125 | + |
| 126 | + Format of file logs (default: json) |
| 127 | + |
| 128 | +- `--log-file-rotate` |
| 129 | + |
| 130 | + Rotate log files |
| 131 | + |
| 132 | +- `--log-file-size=` |
| 133 | + |
| 134 | + Maximum size in MB of the log file before it gets rotated (default: 100) |
| 135 | + |
| 136 | +- `--log-file-age=` |
| 137 | + |
| 138 | + Number of days to retain old log files, 0 means forever (default: 0) |
| 139 | + |
| 140 | +- `--log-file-number=` |
| 141 | + |
| 142 | + Maximum number of old log files to retain, 0 to retain all (default: 0) |
| 143 | + |
| 144 | +### WebUI |
| 145 | + |
| 146 | +- `--web-disable=[all|ui]` |
| 147 | + |
| 148 | + Disable REST API and/or web UI. |
| 149 | + ENV: `$PW_WEBDISABLE` |
| 150 | + |
| 151 | +- `--web-addr=` |
| 152 | + |
| 153 | + TCP address in the form 'host:port' to listen on (default: :8080). |
| 154 | + ENV: `$PW_WEBADDR` |
| 155 | + |
| 156 | +- `--web-user=` |
| 157 | + |
| 158 | + Admin login. |
| 159 | + ENV: `$PW_WEBUSER` |
| 160 | + |
| 161 | +- `--web-password=` |
| 162 | + |
| 163 | + Admin password. |
| 164 | + ENV: `$PW_WEBPASSWORD` |
| 165 | + |
| 166 | +### Help Options |
| 167 | + |
| 168 | +- `-h`, `--help` |
| 169 | + |
| 170 | + Show this help message |
| 171 | + |
| 172 | +## Available commands |
| 173 | + |
| 174 | +### Manage configurations |
| 175 | + |
| 176 | +```terminal |
| 177 | + pgwatch [OPTIONS] config <init | upgrade> |
| 178 | +``` |
| 179 | + |
| 180 | +!!! info |
| 181 | + To use `config` command, you need to specify the `-s`, `--sources` and\or `-m`, `--metrics` options. |
| 182 | + |
| 183 | +- `init` |
| 184 | + |
| 185 | + Initialize the configuration database with the required tables and functions. If file is used, it will |
| 186 | + be created in the specified location and filled with built-in defaults. |
| 187 | + |
| 188 | +- `upgrade` |
| 189 | + |
| 190 | + Upgrade the database to the latest version. File or folder based configurations are not supported yet. |
| 191 | + |
| 192 | +### Manage metrics |
| 193 | + |
| 194 | +```terminal |
| 195 | + pgwatch [OPTIONS] metric <print-init | print-sql> |
| 196 | +``` |
| 197 | + |
| 198 | +!!! info |
| 199 | + To use `config` command, you need to specify the `-m`, `--metrics` option. |
| 200 | + |
| 201 | +- `print-init` |
| 202 | + |
| 203 | + Get and print init SQL for a given metric(s) or preset(s) |
| 204 | + |
| 205 | + Examples: `pgwatch metric print-init bgwriter cpu_load`, |
| 206 | + `pgwatch metric print-init exhaustive` |
| 207 | + |
| 208 | +- `print-sql` |
| 209 | + |
| 210 | + Get and print SQL for a given metric. Optional parameter `-v, --version=` specifies |
| 211 | + PostgreSQL version to get SQL for. |
| 212 | + |
| 213 | + Examples: `pgwatch metric print-sql bgwriter`, |
| 214 | + `pgwatch metric print-sql bgwriter -v 14` |
| 215 | + |
| 216 | +### Manage sources |
| 217 | + |
| 218 | +```terminal |
| 219 | + pgwatch [OPTIONS] source <ping | resolve> |
| 220 | +``` |
| 221 | + |
| 222 | +!!! info |
| 223 | + To use `source` command, you need to specify the `-s`, `--sources` option. |
| 224 | + |
| 225 | +- `ping` |
| 226 | + |
| 227 | + Ping the sources (databases, patroni clusters, poolers, etc.) to check if they are reachable. |
| 228 | + |
| 229 | +- `resolve` |
| 230 | + |
| 231 | + Resolve the monitored databases from sources (postgres clusters and patroni clusters) to check |
| 232 | + if they are reachableand if the configuration is correct. The output will be a list of the |
| 233 | + resolved databases with their connection strings. |
0 commit comments