Enable core dumps on Ubuntu, Debian, and Rocky Linux

Core dumps are often used to diagnose or debug errors in Linux or UNIX programs. Core dumps can serve as useful debugging aids for sysadmins to find out why an application or any other program crashed.
This article provides some baselines on enabling core dumps on the main Linux distributions and on making a core dump of a process.

A core dump is a file containing a process’s address space (memory) when the process terminates unexpectedly. Core dumps may be produced on-demand (such as by a debugger), or automatically upon termination. Support engineers may ask for a core dump after a PostgreSQL crash to understand the state of PostgreSQL during the failure.

Enabling core dump production changes between the distributions.

Below are the instructions for:

  • Ubuntu 16/18/20
  • Debian 9/10
  • Rocky 8/9

Ubuntu 16.04 (Xenial) 18.04 (Bionic) 20.04 (Focal)

Since all of them have systemd enabled as system and sessions manager, the following is the procedure to enable core dumps:

Systemd will not use /etc/security/limits.conf, the limits will be defined in the service unit or in the global systemd configuration.

First, create the directory in which the core dumps will be stored and change kernel.core_pattern to store the dumps in the said directory:

# mkdir -p /var/coredumps

You can choose a different location to store the core dumps, as long as you find a partition with enough free space.
Moreover, keep in mind that the users running the postmaster service (i.e., postgres and/or enterprisedb) will have to be able to write their core dumps in that directory:

# chmod a+w /var/coredumps

# sysctl kernel.core_pattern=/var/coredumps/core-%e-%p

kernel.core_pattern setting can be persisted across reboots:

# echo 'kernel.core_pattern=/var/coredumps/core-%e-%p' >> /etc/sysctl.conf

Then, you can override the PostgreSQL service unit to define the core limit or, alternatively, specify a global default limit for all the services.

  1. To set the limit only for the PostgreSQL service, run
  # systemctl edit postgresql-15.service

and paste the following snippet:


Then reload the service configuration:

  # systemctl daemon-reload
  1. To change the global default you can edit /etc/systemd/system.conf setting

and then restarting systemd

  # systemctl daemon-reexec

Restart PostgreSQL:

# systemctl stop postgresql-15
# systemctl start postgresql-15

At this point, the core dumps should be enabled correctly and you can proceed with the installation of the gdb tool and the debug packages.

On Ubuntu 18.04:

# apt-get install gdb postgresql-15-dbgsym

whereas on Ubuntu 16.04 the name of the debug package is slightly different:

# apt-get install gdb postgresql-15-dbg

Replace the path to a core dump file such as below:

gdb /usr/lib/postgresql/15/bin/postgres /var/coredumps/core-postgres-42317

You can see that core-postgres-42317 is the core dump produced? Finally, you can get a backtrace, running:

(gdb) bt full

in the gdb console.

Debian 9 (Stretch) and 10 (Buster)

To enable core dumps on Debian Stretch and on Debian Buster you can follow the same procedure we described for Ubuntu 18.04. The debug package names are the same as well.

RHEL or Rocky Linux

On RHEL/Rocky Linux 8.x, core file creation is disabled by default. To enable the core file generation, follow the following commands:

  • Identify the system’s current limit using the ulimit -c or ulimit -a command. 0 indicates that core file generation is disabled.
  • Create the directory to store the core dump <refer to the commands above>
  • Use the following command to persist the kernel.core_pattern setting across reboots:
echo 'kernel.core_pattern=/var/coredumps/core-%e-%p' >> /etc/sysctl.conf

Enable core dumps in /etc/security/limits.conf to allow a user to create core files. Each line describes a limit for a user in the following form:

<domain>  <type>  <item>  <value>
   *       soft    core    unlimited

The * enables core dump size to be unlimited.

Edit the core limit in the service file – /etc/systemd/system/postgres.service


Reload the service configurations to make sure the changes take effect:

# systemctl daemon-reload
# systemctl stop postgresql-15
# systemctl start postgresql-15

Now that the core dumps are enabled, install the gdb tool and debug packages for your Operating system:

# yum install gdb
# debuginfo-install postgresql11-server
Happy Debugging!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>