'How to change PostgreSQL 12 crash dump location path?

We are using Postgres 12 (TimescaleDB) and managing it through Patroni.

There was some unexpected issue that happened and crash dump written in the default location /var/crash/_usr_lib_postgresql_12_bin_postgres.111.crash, and this, in turn, caused a root disk full.

I looked around so many ways how to change this location but couldn't succeed.

Would you please someone help with this? Thanks in advance



Solution 1:[1]

First of all postgresql must be configured with e.g. in /etc/postgresql/12/main/pg_ctl.conf:

pg_ctl_options = '--core-files'

if you remove the -c/--core-file flag no core dump will be produced (not good for issue diagnosis).

By default postgres writes core dump to data directory path.

Check you current kernel.core_pattern configuration:

$ sysctl kernel.core_pattern
kernel.core_pattern = core

You can specify multiple variables that gets substituted:

  • %p - pid
  • %% - output one '%'
  • %u - uid
  • %g - gid
  • %s - signal number
  • %t - UNIX time of dump
  • %h - hostname
  • %e - executable filename

It's good idea to include at least %p (pid) in the path, in order to distinguish between consequent crashes.

sysctl -w kernel.core_pattern='/tmp/core.%e.%p'

in order to persist the change after reboot add the config e.g. to /etc/sysctl.conf:

kernel.core_pattern=/tmp/core.%e.%p

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tombart