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