diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-12-17 12:08:39 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-12-17 12:08:42 -0500 |
commit | c91963da1302e8dd490bde115f3956f7d2f1258d (patch) | |
tree | bd1f6e3c4319e2efd4382ceb59e9e44486033470 /src/include/miscadmin.h | |
parent | 957ba9ff14066782a42ebb974913b2fc616c99e1 (diff) | |
download | postgresql-c91963da1302e8dd490bde115f3956f7d2f1258d.tar.gz postgresql-c91963da1302e8dd490bde115f3956f7d2f1258d.zip |
Set the stack_base_ptr in main(), not in random other places.
Previously we did this in PostmasterMain() and InitPostmasterChild(),
which meant that stack depth checking was disabled in non-postmaster
server processes, for instance in single-user mode. That seems like
a fairly bad idea, since there's no a-priori restriction on the
complexity of queries we will run in single-user mode. Moreover, this
led to not having quite the same stack depth limit in all processes,
which likely has no real-world effect but it offends my inner neatnik.
Setting the depth in main() guarantees that check_stack_depth() is
armed and has a consistent interpretation of stack depth in all forms
of server processes.
While at it, move the code associated with checking the stack depth
out of tcop/postgres.c (which was never a great home for it) into
a new file src/backend/utils/misc/stack_depth.c.
Discussion: https://postgr.es/m/2081982.1734393311@sss.pgh.pa.us
Diffstat (limited to 'src/include/miscadmin.h')
-rw-r--r-- | src/include/miscadmin.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 42a2b38cac9..3f97fcef800 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -288,7 +288,12 @@ extern PGDLLIMPORT int VacuumCostBalance; extern PGDLLIMPORT bool VacuumCostActive; -/* in tcop/postgres.c */ +/* in utils/misc/stack_depth.c */ + +extern PGDLLIMPORT int max_stack_depth; + +/* Required daylight between max_stack_depth and the kernel limit, in bytes */ +#define STACK_DEPTH_SLOP (512 * 1024L) typedef char *pg_stack_base_t; @@ -296,6 +301,7 @@ extern pg_stack_base_t set_stack_base(void); extern void restore_stack_base(pg_stack_base_t base); extern void check_stack_depth(void); extern bool stack_is_too_deep(void); +extern long get_stack_depth_rlimit(void); /* in tcop/utility.c */ extern void PreventCommandIfReadOnly(const char *cmdname); |