Fix gdb command.  Ok to use "thread apply all bt full".
Do not assume db is run by OS user "postgres".
Bug fix: typo in SQL script.
File is generated, but keep it consistent with the generating script.
Add explicit calls to capture semaphore array states and stack traces.  This breaks the script unless user has passwordless sudo.