Windows版本下的参数max_stack_depth(简体)
更新:2007-05-08
對映章節:
內容:
前几天一位朋友跟我讨论max_stack_depth在windows下的调整,调查到一点东西,整理一下共享给大家。
因为着重讲max_stack_depth在windows的问题,所以没有翻译参数说明:
max_stack_depth (integer)
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 such as expression evaluation. The default setting is two megabytes (2MB), which is conservatively small and unlikely to risk crashes. However, it may be too small to allow execution of complex functions. Only superusers 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, it will not let you set this variable to an unsafe value. However, not all platforms provide the information, so caution is recommended in selecting a value.
它是在8.0中引入的,摘自8.0的release note:
Server configuration parameter max_expr_depth parameter has been replaced with max_stack_depth which measures the physical stack size rather than the expression nesting depth. This helps prevent session termination due to stack overflow caused by recursive functions.
8.2中的调整:
On platforms that have getrlimit(RLIMIT_STACK), use it to ensure that max_stack_depth is not set to an unsafe value. This commit also provides configure-time checking for
现在遇到的问题是,在8.1 For Windows能够正常运行的程序,在8.2下由于max_stack_depth的限制变得无法正常值运行。
由于这个校验的存在,Windows平台
问题就在这里,似乎只是个移植问题。
解决办法就是修改源代码
postgres.c的函数assign_max_stack_depth中
将
long stack_rlimit = get_stack_depth_rlimit();
改为:
#if defined(WIN32) || defined(__CYGWIN__)
long stack_rlimit = 10*1024*1024; //10M
#else
long stack_rlimit = get_stack_depth_rlimit();
#endif
然后重新编译即可
编译请参考:
Compiling PostgreSQL On Native Win32 FAQ
Installing PostgreSQL on Windows Using Cygwin FAQ
本方法没有经过测试,仅供参考,对此本人不承担任何责任。
沒有留言:
張貼留言