1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2026-10-23 12:08:57 +03:00
Files
postgres_exporter/docs/getting-started.md
Nicolas Takashi f10a723513 Add --datasource.* CLI flags to replace DATA_SOURCE_* env vars (#1376)
Closes #1372. Part of #1371.

Adds CLI flags for the parts of the Postgres connection config that
aren't secrets: --datasource.uri (replaces DATA_SOURCE_URI), plus
--datasource.uri-file, --datasource.user-file and --datasource.pass-file
(replacing the *_FILE env vars) for values sourced from mounted files.

The user and password values themselves stay env-var only
(DATA_SOURCE_USER / DATA_SOURCE_PASS), since CLI flags are readable via
/proc and the Kubernetes API and would leak the secret itself. The
*-file flags carry only a path, the same pattern Prometheus uses for
password_file, so no secret ever reaches the command line.

Flag and env var reading now lives in cmd/postgres_exporter rather than
the exporter package, which we're trying to shrink. exporter.GetDataSources
stays for embedders, marked deprecated with a migration note, and will be
removed in v0.22.0.

The four env vars that gained a flag are deprecated: the exporter warns
at startup when one is set, the CHANGELOG maps each to its replacement,
and the docs now configure the exporter by flag.

Each flag falls back to its env var when unset, so behavior is unchanged
when only env vars are set. Precedence is unchanged: DATA_SOURCE_NAME
wins over everything, *_FILE wins over the plain value.

Signed-off-by: Nicolas Takashi <nicolas.takashi@dash0.com>
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
2026-10-15 17:06:27 -04:00

97 lines
3.3 KiB
Markdown

---
title: Getting Started
sort_rank: 2
---
# Getting Started
## Install
The exporter is a single static binary with no runtime dependencies, distributed as a container image and as release tarballs. Pick whichever fits your environment — the rest of this page is the same either way.
### Docker
```bash
docker pull quay.io/prometheuscommunity/postgres-exporter
```
See [Docker Images](docker.md) for the other registries, the tagging scheme, and details about the image itself.
### Prebuilt binary
Download the tarball for your platform from the [releases page](https://github.com/prometheus-community/postgres_exporter/releases) and extract it:
```bash
VERSION=0.20.1
curl -LO "https://github.com/prometheus-community/postgres_exporter/releases/download/v${VERSION}/postgres_exporter-${VERSION}.linux-amd64.tar.gz"
tar xzf "postgres_exporter-${VERSION}.linux-amd64.tar.gz"
cd "postgres_exporter-${VERSION}.linux-amd64"
```
Builds are published for Linux, macOS, Windows, and several BSDs across a range of architectures.
### Kubernetes
The `prometheus-postgres-exporter` [Helm chart](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-postgres-exporter) is the supported way to deploy the exporter on Kubernetes. It's a Prometheus Community project like this one, but it lives in the [helm-charts](https://github.com/prometheus-community/helm-charts) repository and has its own maintainers — report chart problems there, not here.
### From source
```bash
git clone https://github.com/prometheus-community/postgres_exporter.git
cd postgres_exporter
make build
```
### Elsewhere
The exporter is also packaged by various Linux distributions, the FreeBSD ports tree, and other third parties. Those packages are not produced or supported by this project; their contents and versions may differ from the official releases above.
## Run the exporter
Point the exporter at an existing PostgreSQL server. With Docker:
```bash
docker run \
--net=host \
-e DATA_SOURCE_USER=postgres \
-e DATA_SOURCE_PASS=password \
quay.io/prometheuscommunity/postgres-exporter \
--datasource.uri="my-postgres-host:5432/postgres?sslmode=disable"
```
Or, with the binary:
```bash
export DATA_SOURCE_USER=postgres
export DATA_SOURCE_PASS=password
./postgres_exporter --datasource.uri="my-postgres-host:5432/postgres?sslmode=disable"
```
See [Connecting to PostgreSQL](connecting.md) for the different ways to specify the database connection, and [Secrets](secrets.md) for how to avoid putting passwords on the command line or in plain environment variables.
## Verify it's working
By default the exporter listens on port `9187` and serves metrics at `/metrics`:
```bash
curl "http://localhost:9187/metrics"
```
You should see PostgreSQL metrics prefixed with `pg_`, along with the exporter's own internal metrics (`go_*`, `promhttp_*`, etc).
## Point Prometheus at it
Add a scrape job to your Prometheus configuration:
```yaml
scrape_configs:
- job_name: postgres
static_configs:
- targets: ["127.0.0.1:9187"] # replace with the exporter's actual host:port
```
## Next steps
- [Configure](configuration.md) which collectors are enabled and how the exporter is deployed.
- Grant the exporter's database user the right [permissions](database-permissions.md).
- Review [secrets](secrets.md) options before running this in anything beyond a local test.