-
Notifications
You must be signed in to change notification settings - Fork 18
feat: rotate the internal PostgreSQL logs #312
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ source "$(dirname $(realpath $0))/env" | |
|
|
||
| if [ x"$1" == "xstop" ]; then | ||
| echo -n Stopping PostgreSQL... | ||
| sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -l "${DATA_DIR}/logfile" -o "-p ${PG_PORT}" stop | ||
| sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -o "-p ${PG_PORT}" stop | ||
| exit 0 | ||
| fi | ||
|
|
||
|
|
@@ -47,8 +47,19 @@ if [ ! -d "$DATA_DIR/base" ]; then | |
| sudo -u postgres ${PG_BIN}/initdb -D "$DATA_DIR" -E UTF8 | ||
| fi | ||
|
|
||
| # Rotate the internal PostgreSQL logs with the built-in logging collector: one | ||
| # file per weekday (postgresql-Mon.log ... postgresql-Sun.log) under | ||
| # "$DATA_DIR/log". The collector overwrites a weekday file only on time-based | ||
| # rotation, not on startup, so a frequently-restarted container would otherwise | ||
| # append to last week's same-named file. Before starting, drop the pre-rotation | ||
| # single logfile and any weekday log at least six days old (find -mtime +5), so | ||
| # last week's file is always gone before its name is reused. See #303. | ||
| rm -f "${DATA_DIR}/logfile" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be cleaner to put this in a repair step |
||
| find "${DATA_DIR}/log" -maxdepth 1 -type f -name 'postgresql-*.log' -mtime +5 -delete 2>/dev/null || true | ||
| PG_LOG_OPTS="-c logging_collector=on -c log_directory=log -c log_filename=postgresql-%a.log -c log_rotation_age=1d -c log_rotation_size=0 -c log_truncate_on_rotation=on" | ||
|
|
||
|
Comment on lines
+50
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wdyt of having the log rotation based on file size instead of the current day of the week? It would mean we have a fixed estimate to how large the logs can grow, and also have logs going back much further than a week. logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_file_mode = 0640
log_rotation_size = 50MB
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, maybe it makes sense to keep all the args in one place, in the |
||
| echo "Starting PostgreSQL..." | ||
| sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -l "${DATA_DIR}/logfile" -o "-p ${PG_PORT}" start | ||
| sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -o "-p ${PG_PORT} ${PG_LOG_OPTS}" start | ||
|
|
||
| echo "Waiting for PostgreSQL to start..." | ||
| until sudo -u postgres ${PG_SQL} -c "SELECT 1" > /dev/null 2>&1; do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be dropped