Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c16029

Browse files
committed
Adjust HINT for stack depth limit to mention checking the underlying
platform limit, rather than just blindly raising max_stack_depth. Also, tweak the code to work properly if someone sets max_stack_depth to more than 2Gb, which guc.c will allow on a 64-bit machine.
1 parent cc1d55b commit 1c16029

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/backend/tcop/postgres.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.510 2006/10/04 00:29:58 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.511 2006/10/07 16:43:28 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -91,7 +91,7 @@ int PostAuthDelay = 0;
9191
*/
9292

9393
/* max_stack_depth converted to bytes for speed of checking */
94-
static int max_stack_depth_bytes = 2048 * 1024;
94+
static long max_stack_depth_bytes = 2048 * 1024L;
9595

9696
/*
9797
* Stack base pointer -- initialized by PostgresMain. This is not static
@@ -2498,16 +2498,12 @@ void
24982498
check_stack_depth(void)
24992499
{
25002500
char stack_top_loc;
2501-
int stack_depth;
2501+
long stack_depth;
25022502

25032503
/*
25042504
* Compute distance from PostgresMain's local variables to my own
2505-
*
2506-
* Note: in theory stack_depth should be ptrdiff_t or some such, but since
2507-
* the whole point of this code is to bound the value to something much
2508-
* less than integer-sized, int should work fine.
25092505
*/
2510-
stack_depth = (int) (stack_base_ptr - &stack_top_loc);
2506+
stack_depth = (long) (stack_base_ptr - &stack_top_loc);
25112507

25122508
/*
25132509
* Take abs value, since stacks grow up on some machines, down on others
@@ -2529,7 +2525,8 @@ check_stack_depth(void)
25292525
ereport(ERROR,
25302526
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
25312527
errmsg("stack depth limit exceeded"),
2532-
errhint("Increase the configuration parameter \"max_stack_depth\".")));
2528+
errhint("Increase the configuration parameter \"max_stack_depth\", "
2529+
"after ensuring the platform's stack depth limit is adequate.")));
25332530
}
25342531
}
25352532

@@ -2539,7 +2536,7 @@ assign_max_stack_depth(int newval, bool doit, GucSource source)
25392536
{
25402537
/* Range check was already handled by guc.c */
25412538
if (doit)
2542-
max_stack_depth_bytes = newval * 1024;
2539+
max_stack_depth_bytes = newval * 1024L;
25432540
return true;
25442541
}
25452542

0 commit comments

Comments
 (0)