Search code examples
postgresqlreindex

PostgreSQL - REINDEX still working even after two hours


I have started REINDEX on my PostgreSQL database. It can be visible in GUI that it processed a number of tables, and then stop responding. It looks like it is still working, even after two hours. The GUI is not responsive and its last row says: "NOTICE: table public.res_request_history" was reindexed."

Can I safely stop REINDEX? What can I do to actually make REINDEX work?

Thanks.


Solution

  • Yes, you can use pg_cancel_backend(pid). PID you can find executing 'select pg_stat_activity()'.

    For example:

    --Will display running queries and corresponding pid
    SELECT query, pid FROM pg_stat_activity;
    --You can then cancel one of them by calling this method with its pid
    SELECT pg_cancel_backend(<pid>);