Index: src/backend/tcop/postgres.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/tcop/postgres.c,v retrieving revision 1.466 diff -c -r1.466 postgres.c *** src/backend/tcop/postgres.c 15 Oct 2005 02:49:27 -0000 1.466 --- src/backend/tcop/postgres.c 28 Oct 2005 07:45:13 -0000 *************** *** 29,34 **** --- 29,37 ---- #ifdef HAVE_GETOPT_H #include #endif + #ifndef WIN32 + #include + #endif #include "access/printtup.h" #include "access/xlog.h" *************** *** 2273,2278 **** --- 2276,2342 ---- } } + #ifndef WIN32 + /* + * EnableCoreDump: Try to enable core dumps for this backend + * + * Sometimes you're trying to have users extract a backtrace from a core + * dump but the system has disabled them by default. This function attempts + * to enable them and displays a warning if it isn't possible. + * + * Intended use: -C on the postgres command line, thus to clients via PGOPTIONS + */ + + static void + EnableCoreDump() + { + struct rlimit limits; + + if( getrlimit( RLIMIT_CORE, &limits ) == -1 ) + { + ereport(NOTICE, + (errmsg("Unable to retrieve core limit: %m"))); + return; + } + + if( limits.rlim_max == 0 ) + { + ereport(NOTICE, + (errmsg("Core dumps hard disabled by admin"))); + return; + } + + if( limits.rlim_cur == limits.rlim_max ) + { + if( limits.rlim_cur == RLIM_INFINITY ) + ereport(NOTICE, + (errmsg("Core dumps already enabled by admin (unlimited)"))); + else + ereport(NOTICE, + (errmsg("Core dumps already enabled by admin (%u KB)", ((unsigned int)limits.rlim_cur)/1024 ))); + return; + } + + limits.rlim_cur = limits.rlim_max; + + if( setrlimit( RLIMIT_CORE, &limits ) == -1 ) + { + ereport(NOTICE, + (errmsg("Unable to change core limit: %m"))); + return; + } + + if( limits.rlim_cur == RLIM_INFINITY ) + ereport(NOTICE, + (errmsg("Core limit successfully changed to (unlimited)"))); + else + ereport(NOTICE, + (errmsg("Core limit successfully changed to (%u KB)", ((unsigned int)limits.rlim_cur)/1024 ))); + return; + } + + #endif /* WIN32 */ + /* GUC assign hook to update max_stack_depth_bytes from max_stack_depth */ bool assign_max_stack_depth(int newval, bool doit, GucSource source) *************** *** 2469,2475 **** ctx = PGC_POSTMASTER; gucsource = PGC_S_ARGV; /* initial switches came from command line */ ! while ((flag = getopt(argc, argv, "A:B:c:D:d:Eef:FiNOPo:p:S:st:v:W:-:")) != -1) { switch (flag) { --- 2533,2539 ---- ctx = PGC_POSTMASTER; gucsource = PGC_S_ARGV; /* initial switches came from command line */ ! while ((flag = getopt(argc, argv, "A:B:Cc:D:d:Eef:FiNOPo:p:S:st:v:W:-:")) != -1) { switch (flag) { *************** *** 2490,2495 **** --- 2554,2570 ---- */ SetConfigOption("shared_buffers", optarg, ctx, gucsource); break; + + case 'C': + /* Enable coredumps if possible */ + #ifdef WIN32 + ereport(WARNING, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("core dumping not available on Win32"))); + #else + EnableCoreDump(); + #endif + break; case 'D': /* PGDATA or config directory */ if (secure)