Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:18:02+00:00 2026-06-06T22:18:02+00:00

I’m using Heroku with the Crane Postgres option and I was running a query

  • 0

I’m using Heroku with the Crane Postgres option and I was running a query on the database from my local machine when my local machine crashed. If I run

select * from pg_stat_activity

one of the entries has

<IDLE> in transaction

in the current_query_text column.

As a result, I can’t drop the table that was being written to by the query that was terminated. I have tried using pg_cancel_backend(N) and it returns True but nothing seems to happen.

How can I terminate this process so that I can drop the table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:18:03+00:00Added an answer on June 6, 2026 at 10:18 pm

    This is a general PostgreSQL answer, and not specific to Heroku


    Possibly easiest quickfix

    The simple-stupid answer to this question may be … just restart postgresql!

    Here is another way of quickly killing all long-lasting "idle in transaction":

    SELECT pg_terminate_backend(pid) from pg_stat_activity
    WHERE state in ('<IDLE> in transaction', 'idle in transaction')
      AND now()-xact_start>interval '1 minute';
    

    More complicated quickfix

    Find the PID by running this sql*):

    SELECT now()-xact_start as trans_time, pid, query from pg_stat_activity
      WHERE state != 'idle' ORDER BY xact_start;
    

    You’ll find the pid in the first (left) column, and the first (top) row is likely to be the query you’d like to terminate. Use select * to get more information about the queries. I’ll assume the pid is 1234 below.

    You may cancel a query through SQL (i.e. without shell access) as long as it’s yours*) or you have super user access:

    select pg_cancel_backend(1234);
    

    That’s a "friendly" request to cancel the 1234-query, and with some luck it will disappear after a while. If required, the following is more of a "hard terminate" command which could cause it to cancel more quickly:

    select pg_terminate_backend(1234);
    

    If you have shell access and root or postgres permissions you can also do it from the shell. To "cancel" one can do:

    kill -INT 1234
    

    and to "terminate", simply:

    kill 1234
    

    DO NOT:

    kill -9 1234
    

    … that will often result in the the whole postgres server going down in flames, then you may as well restart postgres. Postgres is pretty robust, so the data won’t be corrupted, but I’d recommend against using "kill -9" in any case 🙂

    Permanent fix – dealing with the root cause

    A long-lasting "idle in transaction" often means that the transaction was not terminated with a "commit" or a "rollback", meaning that the application is buggy or not properly designed to work with transactional databases – so to properly fix this issue, it’s needed to ensure the application always does a commit or a rollback after running queries, even read-only queries (it’s also possible to enable auto-commit).

    Long-lasting "idle in transaction" should be avoided, as it may (dependent on your usage pattern) cause major performance problems.


    Footnotes: The query may need mending on very old or future versions of PostgreSQL, and on very old versions of PostgreSQL only superuser can cancel queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.