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

Add logrotate for PostgreSQL #915

Merged
merged 4 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG-0.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- PostgreSQL: PGBouncer implementation [#854](https://github.com/epiphany-platform/epiphany/issues/854)
- PostgreSQL: pgAudit extension for audit logging [#905](https://github.com/epiphany-platform/epiphany/pull/905)
- PostgreSQL: Send logs to Elasticsearch
- PostgreSQL: Add logrotate configuration [#915](https://github.com/epiphany-platform/epiphany/pull/915)

### Fixed

- Open Distro for Elasticsearch: Task 'Install Elasticsearch package' fails [#906](https://github.com/epiphany-platform/epiphany/issues/906)

## [0.5.1] 2020-01-23

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ filebeat.inputs:
enabled: true
paths:
- /var/log/postgresql/*.log*
exclude_files: [".gz$"]
multiline:
pattern: '^\d{4}-\d{2}-\d{2} '
negate: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@
or change_postgresql_epiphany_conf
or change_postgresql_conf

- name: Configure logrotate
block:
- name: Remove logrotate configuration provided by 'postgresql-common' package
file:
path: /etc/logrotate.d/postgresql-common
state: absent
when: ansible_os_family == 'Debian'
- name: Create logrotate configuration file
template:
src: logrotate.conf.j2
dest: /etc/logrotate.d/postgresql
owner: root
group: root
mode: 0644
when:
- specification.logrotate.config is defined

- name: Set up replication
include_tasks: replication-{{ ansible_os_family }}.yml
# 'specification.replication.enable' is for backward compatibility
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# {{ ansible_managed }}

{{ specification.logrotate.config }}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ specification:
parameters:
- name: log_directory
value: "'/var/log/postgresql'"
comment: to have standard location for Filebeat
comment: to have standard location for Filebeat and logrotate
- name: log_filename
value: "'postgresql.log'"
comment: to use logrotate with common configuration
additional_components:
pgbouncer:
enabled: no
Expand All @@ -54,3 +57,28 @@ specification:
pgaudit.log_relation: 'on # separate log entry for each relation' # default is 'off'
pgaudit.log_statement_once: 'off' # same as default
pgaudit.log_parameter: 'on' # default is 'off'
logrotate:
# Configuration partly based on /etc/logrotate.d/postgresql-common provided by 'postgresql-common' package from Ubuntu repo.
# PostgreSQL from Ubuntu repo:
# By default 'logging_collector' is disabled, so 'log_directory' parameter is ignored.
# Default log path is /var/log/postgresql/postgresql-$version-$cluster.log.
# PostgreSQL from SCL repo (RHEL):
# By default 'logging_collector' is enabled and there is up to 7 files named 'daily' (e.g. postgresql-Wed.log)
# and thus they can be overwritten by built-in log facility to provide rotation.
# To have similar configuration for both distros (with logrotate), 'log_filename' parameter is modified.
config: |-
/var/log/postgresql/postgresql*.log {
maxsize 10M
daily
rotate 6
copytruncate
# delaycompress is for Filebeat
delaycompress
compress
notifempty
missingok
su root root
nomail
# to have multiple unique filenames per day when dateext option is set
dateformat -%Y%m%d-%s
}