{"id":19458505,"url":"https://github.com/postgrespro/pg_backtrace","last_synced_at":"2026-03-17T22:32:24.177Z","repository":{"id":69542803,"uuid":"157236548","full_name":"postgrespro/pg_backtrace","owner":"postgrespro","description":"Show backtrace for errors and signals","archived":false,"fork":false,"pushed_at":"2022-07-20T09:37:45.000Z","size":9,"stargazers_count":19,"open_issues_count":1,"forks_count":5,"subscribers_count":30,"default_branch":"master","last_synced_at":"2026-03-13T06:53:56.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/postgrespro.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-12T15:42:24.000Z","updated_at":"2025-04-07T04:32:42.000Z","dependencies_parsed_at":"2023-04-19T17:47:03.149Z","dependency_job_id":null,"html_url":"https://github.com/postgrespro/pg_backtrace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/postgrespro/pg_backtrace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_backtrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_backtrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_backtrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_backtrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postgrespro","download_url":"https://codeload.github.com/postgrespro/pg_backtrace/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_backtrace/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30633332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T17:27:23.048Z","updated_at":"2026-03-17T22:32:24.137Z","avatar_url":"https://github.com/postgrespro.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"This PostgreSQL extension can be used to get more information\nabout PostgreSQL backend execution when no debugger is available.\nIt allows to dump stack trace when error is reported or exception is caught.\nSo there three used cases of using this extension:\n\n1. Find out the source of error. pg_backtrace extension provides\n\"pg_backtrace.level\" GUC which selects error level for which backtrace information\nis attached. Default value is ERROR. So once this extension is initialized,\nall errors will include backtrace information which is dumped both in log\nfile and delivered to the client:\n\npostgres=# select count(*)/0.0 from pg_class;\nERROR:  division by zero\nCONTEXT:  \tpostgres: knizhnik postgres [local] SELECT(numeric_div+0xbc) [0x7c5ebc]\n\tpostgres: knizhnik postgres [local] SELECT() [0x5fe4e2]\n\tpostgres: knizhnik postgres [local] SELECT() [0x610730]\n\tpostgres: knizhnik postgres [local] SELECT() [0x6115ca]\n\tpostgres: knizhnik postgres [local] SELECT(standard_ExecutorRun+0x15a) [0x60193a]\n\tpostgres: knizhnik postgres [local] SELECT() [0x74168c]\n\tpostgres: knizhnik postgres [local] SELECT(PortalRun+0x29e) [0x742a7e]\n\tpostgres: knizhnik postgres [local] SELECT() [0x73e922]\n\tpostgres: knizhnik postgres [local] SELECT(PostgresMain+0x1189) [0x73fde9]\n\tpostgres: knizhnik postgres [local] SELECT() [0x47d5e0]\n\tpostgres: knizhnik postgres [local] SELECT(PostmasterMain+0xd28) [0x6d0448]\n\tpostgres: knizhnik postgres [local] SELECT(main+0x421) [0x47e511]\n\t/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f6361a13830]\n\tpostgres: knizhnik postgres [local] SELECT(_start+0x29) [0x47e589]\n\n2. Determine current state of backend (assume that there is some long running query\nand you do not know where it spends most of time). It is possible to send SIGINT signal\nto backend and it print current stack in logfile:\n\n2018-11-12 18:24:12.222 MSK [24457] LOG:  Caught signal 2\n2018-11-12 18:24:12.222 MSK [24457] CONTEXT:  \t/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7f63624e3390]\n\t\t/lib/x86_64-linux-gnu/libc.so.6(epoll_wait+0x13) [0x7f6361afa9f3]\n\t\tpostgres: knizhnik postgres [local] SELECT(WaitEventSetWait+0xbe) [0x71e4de]\n\t\tpostgres: knizhnik postgres [local] SELECT(WaitLatchOrSocket+0x8b) [0x71e93b]\n\t\tpostgres: knizhnik postgres [local] SELECT(pg_sleep+0x98) [0x7babd8]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x5fe4e2]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x6266a8]\n\t\tpostgres: knizhnik postgres [local] SELECT(standard_ExecutorRun+0x15a) [0x60193a]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x74168c]\n\t\tpostgres: knizhnik postgres [local] SELECT(PortalRun+0x29e) [0x742a7e]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x73e922]\n\t\tpostgres: knizhnik postgres [local] SELECT(PostgresMain+0x1189) [0x73fde9]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x47d5e0]\n\t\tpostgres: knizhnik postgres [local] SELECT(PostmasterMain+0xd28) [0x6d0448]\n\t\tpostgres: knizhnik postgres [local] SELECT(main+0x421) [0x47e511]\n\t\t/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f6361a13830]\n\t\tpostgres: knizhnik postgres [local] SELECT(_start+0x29) [0x47e589]\n\n3. Get stack trace for SIGSEGV or SIGBUS signals\n(if dumping cores is disabled for some reasons):\n\n2018-11-12 18:25:52.636 MSK [24518] LOG:  Caught signal 11\n2018-11-12 18:25:52.636 MSK [24518] CONTEXT:  \t/home/knizhnik/postgresql/dist/lib/pg_backtrace.so(+0xe37) [0x7f6358838e37]\n\t\t/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7f63624e3390]\n\t\t/home/knizhnik/postgresql/dist/lib/pg_backtrace.so(pg_backtrace_sigsegv+0) [0x7f6358838fb0]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x5fe474]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x6266a8]\n\t\tpostgres: knizhnik postgres [local] SELECT(standard_ExecutorRun+0x15a) [0x60193a]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x74168c]\n\t\tpostgres: knizhnik postgres [local] SELECT(PortalRun+0x29e) [0x742a7e]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x73e922]\n\t\tpostgres: knizhnik postgres [local] SELECT(PostgresMain+0x1189) [0x73fde9]\n\t\tpostgres: knizhnik postgres [local] SELECT() [0x47d5e0]\n\t\tpostgres: knizhnik postgres [local] SELECT(PostmasterMain+0xd28) [0x6d0448]\n\t\tpostgres: knizhnik postgres [local] SELECT(main+0x421) [0x47e511]\n\t\t/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f6361a13830]\n\t\tpostgres: knizhnik postgres [local] SELECT(_start+0x29) [0x47e589]\n\n\n------------------------------------------------\n\nAs far as Postgres extension is loaded and initialized on first access to\nits functions, it is necessary to call pg_backtrace_init() function to\nbe able to use this extension. This function function actually does nothing\nand _PG_init() registers signal handlers for SIGSEGV, SIGBUS and SIGINT and\nexecutor run hook which setups exception context.\n\nThis extension is using backtrace function which is available at most Unixes.\nAs it was mentioned in backtrace documentation:\n\n    The symbol names may be unavailable without the use of special linker options.\n\tFor systems using the GNU linker, it is necessary to use the -rdynamic\n    linker option.  Note that names of \"static\" functions are not exposed,\n\tand won't be available in the backtrace.\n\nPostgres is built without -rdynamic option. This is why not all function addresses\nin the stack trace above are resolved. It is possible to use GDB (at development\nhost with correspondent postgres binaries) or Linux addr2line utility to\nget resolve function addresses:\n\n    $ addr2line -e ~/postgresql/dist/bin/postgres -a 0x5fe4e2\n    0x00000000005fe4e2\n    execExprInterp.c:?\n\n\n------------------------------------------------\n\nUsage:\n\ncreate extension pg_backtrace;\nselect pg_backtrace_init();\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fpg_backtrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostgrespro%2Fpg_backtrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fpg_backtrace/lists"}