↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Configuration Parameters

max_stack_depth

Specifies the maximum safe depth of the server's execution stack. The ideal setting for this parameter is the actual stack size limit enforced by the kernel (as set by ulimit -s or local equivalent), less a safety margin of a megabyte or so. The safety margin is needed because the stack depth is not checked in every routine in the server, but only in key potentially-recursive routines. If this value is specified without units, it is taken as kilobytes. The default setting is two megabytes (2MB), which is conservatively small and unlikely to risk crashes. However, it might be too small to allow execution of complex functions. Only superusers and users with the appropriate SET privilege can change this setting. Setting max_stack_depth higher than the actual kernel limit will mean that a runaway recursive function can crash an individual backend process. On platforms where PostgreSQL can determine the kernel limit, the server will not allow this variable to be set to an unsafe value. However, not all platforms provide the information, so caution is recommended in selecting a value.

English manual coverage begins with PostgreSQL 7.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

boot val
100
category
Resource Usage / Memory
context
superuser
documented
true
enumvals
Unknown
extra desc
Unknown
lang
en
max val
2147483647
metadata version
18
min val
100
name
max_stack_depth
short desc
Sets the maximum stack depth, in kilobytes.
source
pg-settings-source-snapshot
unit
kB
vartype
integer

Definition PG 18

Specifies the maximum safe depth of the server's execution stack. The ideal setting for this parameter is the actual stack size limit enforced by the kernel (as set by ulimit -s or local equivalent), less a safety margin of a megabyte or so. The safety margin is needed because the stack depth is not checked in every routine in the server, but only in key potentially-recursive routines. If this value is specified without units, it is taken as kilobytes. The default setting is two megabytes (2MB), which is conservatively small and unlikely to risk crashes. However, it might be too small to allow execution of complex functions. Only superusers and users with the appropriate SET privilege can change this setting. Setting max_stack_depth higher than the actual kernel limit will mean that a runaway recursive function can crash an individual backend process. On platforms where PostgreSQL can determine the kernel limit, the server will not allow this variable to be set to an unsafe value. However, not all platforms provide the information, so caution is recommended in selecting a value.

Compare versions

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:5656e0497e423f77dbb219c3fdc64a74b6ed5b450a718fb0d7d12852d9ade214

Text language: en · wiki-repair-20261023:5656e0497e423f77dbb219c3fdc64a74b6ed5b450a718fb0d7d12852d9ade214