# How to close orphaned Postgre connections?

**URL:** <https://forum.xojo.com/t/how-to-close-orphaned-postgre-connections/83671>\
**Category:** Databases\
**Created:** [December 21, 2024, 1:12am UTC](https://forum.xojo.com/t/how-to-close-orphaned-postgre-connections/83671 "2024-12-21T01:12:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Seyfarth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@Tim\_Seyfarth](https://forum.xojo.com/u/Tim_Seyfarth)\
**Post date:** [December 21, 2024, 1:12am UTC](https://forum.xojo.com/t/how-to-close-orphaned-postgre-connections/83671/1 "2024-12-21T01:12:42Z")

</div>

Hello,

I have a problem where occasionally an app does not close its connection to PostgreSQL. I am trying to track down where and why this is happening, but in the meantime it is messing with the operation of other apps since at times, the connection count can get quite high and therefore no new connections are available.

While tracking down the real problem, I wanted to see if the main part of the app can check for orphaned, this part I know how to do, and then closed any connections that should not be open.

I would prefer to use the application\_name field but could use the PID if absolutely necessary.

I presume this would have to be a SQL command, or something else but I do not have any idea what it would be.

Any recommends on this please?  
Tim

---

<div class="post-metadata">

**Author:** ![Daniel\_Hüttenberger](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/82dd89/32.png) [@Daniel\_Hüttenberger](https://forum.xojo.com/u/Daniel_H%C3%BCttenberger)\
**Post date:** [December 22, 2024, 3:58am UTC](https://forum.xojo.com/t/how-to-close-orphaned-postgre-connections/83671/2 "2024-12-22T03:58:52Z")

</div>

Look at this post at stack overflow. Perhaps it helps.

> <https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection>

---

<div class="post-metadata">

**Author:** ![Greg\_O](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o/32/22785_2.png) [@Greg\_O](https://forum.xojo.com/u/Greg_O)\
**Post date:** [December 22, 2024, 4:16am UTC](https://forum.xojo.com/t/how-to-close-orphaned-postgre-connections/83671/3 "2024-12-22T04:16:31Z")

</div>

Tim, does your app use prepared statements? There was a bug recently where they wouldn’t get released when used in the ExecuteSQL and SelectSQL modes.

---

<div class="post-metadata">

**Author:** ![Tim\_Seyfarth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@Tim\_Seyfarth](https://forum.xojo.com/u/Tim_Seyfarth)\
**Post date:** [December 23, 2024, 11:57pm UTC](https://forum.xojo.com/t/how-to-close-orphaned-postgre-connections/83671/4 "2024-12-23T23:57:35Z")

</div>

Hi Greg,

No prepared statements…

Thanks,  
Tim
