max_stack_depth not changed even stack changed in limits.conf
This solution works on Fedora Linux, but should work on Ubuntu as well.  The issue is, that in addition to replacing initd, systemd aims to take over security functions that were traditionally handled by things like /etc/security/limits.conf.  (There are other areas where it interferes as well).  When systemd starts PostgreSQL, it ignores /etc/security/limits.conf, and applies its own default limits.  To change them, do the following:

mkdir /etc/systemd/system/postgresql.service.d
cat &gt; /etc/systemd/system/postgresql.service.d/postgresql.conf &lt;&lt; XYZZY
[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
LimitSTACK=infinity
XYZZY

systemctl daemon-reload


This method also has the added benefit that will not interfere with default changes to service unit files, should they be updated upstream, but will permanently maintain your settings override.  This helpful post lists the other limits that may be set through systemd configuration.  

I should note that, at first, I tried to set the limit to 131072, but when I attempted to start PostgreSQL, I got this error:

DETAIL:  "max_stack_depth" must not exceed -384kB.


Changing it to infinity allowed PostgreSQL to start.