Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Implement log rotation for PGBouncer #921

Closed
plirglo opened this issue Feb 17, 2020 · 10 comments
Closed

[FEATURE REQUEST] Implement log rotation for PGBouncer #921

plirglo opened this issue Feb 17, 2020 · 10 comments
Assignees
Milestone

Comments

@plirglo
Copy link
Contributor

plirglo commented Feb 17, 2020

Is your feature request related to a problem? Please describe.
Configure pgbouncer to write logs in standard location searched by filebeat. Also configure log and log rotation to limit log size for pgbouncer.

Describe the solution you'd like
Please see how it's done for Postgres, search what needs to be logged and for how long logs should be stored.

Describe alternatives you've considered

Additional context
Same basic knowledge about log rotation and pgbouncer:
https://www.redhat.com/sysadmin/setting-logrotate
https://www.enterprisedb.com/postgres-tutorials/pgbouncer-logs-rotation-linux-and-windows-tutorial
https://www.postgresql.org/message-id/[email protected] (old, but might be useful)

@toszo toszo added this to the PostgreSQL extensions milestone Feb 26, 2020
@seriva seriva self-assigned this Mar 13, 2020
@mkyc mkyc unassigned seriva Jul 7, 2020
@rafzei rafzei changed the title Implement log rotation for PGBouncer [FEATURE REQUEST] Implement log rotation for PGBouncer Jul 7, 2020
@ghost ghost removed the status/grooming-needed label Aug 21, 2020
@mkyc mkyc modified the milestones: S20200910, S20200924, S20201008 Sep 10, 2020
@mkyc mkyc modified the milestones: S20201008, S20201022 Sep 24, 2020
@mkyc mkyc modified the milestones: S20201022, S20201105 Oct 8, 2020
@ghost ghost self-assigned this Oct 12, 2020
@ghost
Copy link

ghost commented Oct 12, 2020

I was able to deploy epiphany, with separated HA PostgreSQL machine. To enable pgbouncer log rotation, we need to add the following code into our main build YAML file:


kind: configuration/postgresql
title: PostgreSQL
name: default
specification:
config_file:
parameter_groups:
(...)
extensions:
pgaudit:
enabled: yes
(...)
pgbouncer:
enabled: yes
replication:
enabled: yes
(...)
repo.
config: |-
/var/log/postgresql/postgresql*.log {
(...)
}
/var/log/postgresql/pgbouncer.log {
missingok
notifempty
sharedscripts
copytruncate
size 10M
create 0640 postgres postgres
nodateext
postrotate
/bin/kill -HUP cat /run/postgresql/pgbouncer.pid 2>/dev/null 2> /dev/null || true
endscript
}

@ghost
Copy link

ghost commented Oct 13, 2020

PGBouncer log rotation, and sending logs into ELK stack works properly on Ubuntu host.
Will check the RedHat deployment now.

@ghost
Copy link

ghost commented Oct 13, 2020

Checked on Azure - logs can be rotated, and they're pushed into ELK. Kibana is able to access those logs.

@mkyc mkyc removed the size/XS label Oct 23, 2020
@przemyslavic przemyslavic unassigned ghost Oct 29, 2020
@ar3ndt ar3ndt self-assigned this Oct 31, 2020
@mkyc mkyc modified the milestones: S20201105, S20201119 Nov 5, 2020
@ar3ndt
Copy link
Contributor

ar3ndt commented Nov 9, 2020

PR #1823

ar3ndt added a commit that referenced this issue Nov 13, 2020
* add logrotate config for pgbouncer and filebeat input
to-bar added a commit that referenced this issue Nov 13, 2020
to-bar added a commit that referenced this issue Nov 13, 2020
@to-bar
Copy link
Contributor

to-bar commented Nov 13, 2020

Some suggestions after reverting the PR.

RHEL

  1. We have rotation configured out of the box (provided by rpm package), the config file is: /etc/logrotate.d/pgbouncer. I think we can keep it as is without making it configurable.
  2. The log file path is different than on Ubuntu, i.e /var/log/pgbouncer/pgbouncer.log. It's not handled by filebeat, so we need add it to filebeat.yml.j2 as it was in the PR.

Ubuntu
Option 1.
We could reuse RHEL's config file (provided by rpm package) but this would require:

  • Change logfile in /etc/pgbouncer/pgbouncer.ini to use the same location as on RHEL.
  • Change 'pidfile' in the same file.
  • Create /var/log/pgbouncer directory if needed.
  • Check whether pgbouncer user should be created (since it's present in the config file).

Option 2. (easier to implement)
Use RHEL's config file as base for separate (in Epiphany sources) adjusted to Ubuntu specific configuration.

Both
I don't think we need multi-line support in Filebeat but checked only on Ubuntu and haven't found any multi-line entries.

The logrotate config should not be concatenated to /etc/logrotate.d/postgresql but stored in separate file /etc/logrotate.d/pgbouncer.

@ar3ndt
Copy link
Contributor

ar3ndt commented Nov 17, 2020

new PR created

@mkyc mkyc modified the milestones: S20201119, S20201203 Nov 19, 2020
rafzei pushed a commit to rafzei/epiphany that referenced this issue Nov 26, 2020
… (hitachienergy#1823)

* add logrotate config for pgbouncer and filebeat input
@mkyc mkyc modified the milestones: S20201203, S20201217 Dec 4, 2020
toszo pushed a commit to toszo/epiphany that referenced this issue Dec 5, 2020
… (hitachienergy#1823)

* add logrotate config for pgbouncer and filebeat input
@przemyslavic przemyslavic self-assigned this Dec 7, 2020
@przemyslavic
Copy link
Collaborator

I found an issue with duplicate log entries for PgBouncer on Ubuntu. This is because in the filebeat configuration for PostgreSQL the path /var/log/postgresql/*.log* was specified first, and then /var/log/postgresql/pgbouncer.log* for PgBouncer, and the second path is included in the first, which leads to multiplication.

cat /etc/filebeat/filebeat.yml

# -------------------------- PostgreSQL input --------------------------

# Filebeat postgresql module doesn't support custom log_line_prefix (without patching), see https://discuss.elastic.co/t/filebeats-with-postgresql-module-custom-log-line-prefix/204457
# Dedicated configuration to handle log messages spanning multiple lines.

- type: log
  enabled: true
  paths:
    - /var/log/postgresql/*.log*
  exclude_files: [".gz$"]
  multiline:
    pattern: '^\d{4}-\d{2}-\d{2} '
    negate: True
    match: after

- type: log
  enabled: true
  paths:
    - /var/log/postgresql/pgbouncer.log*
  exclude_files: [".gz$"]

image.png

@to-bar
Copy link
Contributor

to-bar commented Dec 8, 2020

The issue with duplicate log entries for PgBouncer on Ubuntu fixed in PR #1896.

@ar3ndt
Copy link
Contributor

ar3ndt commented Dec 8, 2020

@przemyslavic Can we move this to test again?

@przemyslavic
Copy link
Collaborator

przemyslavic commented Dec 9, 2020

Fix tested.
✔️ Logs from PgBouncer are visible in Kibana.
✔️ Log rotation works as configured.
✔️ Filebeat configuration adjusted to avoid log duplication.

@mkyc mkyc closed this as completed Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants