Better Stack PostgreSQL logging

Start logging in 2 minutes

What you would like to collect from your PostgreSQL?

Collect logs & metrics

Collect logs and metrics from your PostgreSQL database using Vector  and Prometheus postgres exporter .

1. Set up PostgreSQL exporter

Create a dedicated PostgreSQL user for Vector to securely scrape metrics:

Create a new user
psql -h localhost -U postgres \
  -c "CREATE USER better_stack_metrics WITH PASSWORD 'your_password_here'; \
      GRANT SELECT ON pg_stat_database TO better_stack_metrics;"

Fill in your password

Replace your_password_here with password of your choice.

Create /etc/postgres_exporter.conf config file using PostgreSQL user password you've just set:

/etc/postgres_exporter.cnf
export DATA_SOURCE_NAME="postgresql://better_stack_metrics:your_password_here@localhost:5432/postgres"

2. Install PostgreSQL exporter

Install latest postgres exporter:

Install postgres exporter
curl -sSL https://logs.betterstack.com/install/postgres_exporter | sudo -E bash

3. Run exporter

Start the PostgreSQL exporter:

Linux macOS
systemctl start postgres_exporter
launchctl start com.prometheus.postgres_exporter

4. Set up Vector

Select your platform:

Ubuntu • Debian

Install and configure Vector  on Ubuntu or Debian:

Set up Vector
curl -sSL https://logs.betterstack.com/setup-vector/postgresql_with_metrics/$SOURCE_TOKEN \
  -o /tmp/setup-vector.sh && \
  bash /tmp/setup-vector.sh

Curious about what the script does?

  • Installs Vector using official package.
  • Configures Vector for your Better Stack source.
  • Enables and restarts Vector.

The script will ask for confirmation before making any changes.

You should see your logs in Better Stack → Live tail .

Colect only logs

Collect logs from your PostgreSQL database using Vector .

Select your platform:

Ubuntu • Debian

Install and configure Vector  on Ubuntu or Debian:

Set up Vector
curl -sSL https://logs.betterstack.com/setup-vector/postgresql/$SOURCE_TOKEN \
  -o /tmp/setup-vector.sh && \
  bash /tmp/setup-vector.sh

Curious about what the script does?

  • Installs Vector using official package.
  • Configures Vector for your Better Stack source.
  • Enables and restarts Vector.

The script will ask for confirmation before making any changes.

You should see your logs in Better Stack → Live tail .

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏

Additional information

Looking for manual instructions to set up Vector?

Find step-by-step instructions in our dedicated Vector guide.