Queries endlos

Hallo zusammen,

beim Aufspielen eines Dumps dauert das Ausführen mancher Befehle endlos wie der folgende Log-Ausschnitt zeigt. Die Tabellen sind nicht riesig bzw. die Tabelle videos_video hat sogar deutlich weniger Einträge als die Tabelle photos_photo. An was kann das liegen? Können beim Einspielen eines Dumps Deadlocks auftreten? Und welche Debugging Möglichkeiten gibt es?

    2017-06-06 10:16:45.458 CEST [19214]  LOG:  duration: 3970.598 ms  statement: select count(*) from photos_shapi;
    2017-06-06 10:24:00.338 CEST [17075] ERROR:  canceling autovacuum task
    2017-06-06 10:24:00.338 CEST [17075] CONTEXT:  automatic analyze of table "test.public.videos_video"
    2017-06-06 10:24:00.357 CEST [15827]  LOG:  duration: 1394280.361 ms  statement: ALTER TABLE ONLY videos_video ADD CONSTRAINT videos_video_pkey PRIMARY KEY (id);
    2017-06-06 10:26:18.530 CEST [15827]  LOG:  duration: 2248.930 ms  statement: CREATE INDEX photos_like_user_id ON photos_like USING btree (user_id);
    2017-06-06 12:49:39.232 CEST [16733] ERROR:  canceling autovacuum task
    2017-06-06 12:49:39.232 CEST [16733] CONTEXT:  automatic analyze of table "test.public.photos_photo"
    2017-06-06 12:49:41.166 CEST [15827]  LOG:  duration: 8602635.922 ms  statement: CREATE INDEX photos_photo_approved_by_id ON photos_photo USING btree (approved_by_id);
    2017-06-06 13:08:35.055 CEST [15827]  LOG:  duration: 190.807 ms  statement: ALTER TABLE ONLY accounts_favorite
      ADD CONSTRAINT accounts_favorite_folder_id_fkey FOREIGN KEY (folder_id) REFERENCES accounts_favoritefolder(id) DEFERRABLE INITIALLY DEFERRED;
    2017-06-06 16:15:41.457 CEST [23916] ERROR:  canceling autovacuum task
    2017-06-06 16:15:41.457 CEST [23916] CONTEXT:  automatic analyze of table "test.public.photos_photo"
    2017-06-06 16:15:46.294 CEST [15827]  LOG:  duration: 11231238.473 ms  statement: ALTER TABLE ONLY accounts_favorite
      ADD CONSTRAINT accounts_favorite_photo_id_fkey FOREIGN KEY (photo_id) REFERENCES photos_photo(id) DEFERRABLE INITIALLY DEFERRED;
    2017-06-06 16:15:54.298 CEST [15827]  LOG:  duration: 8004.464 ms  statement: ALTER TABLE ONLY accounts_favorite

Hat jemand ne Idee wie man vacuum Prozesse beenden kann?

select pid,state,query from pg_stat_activity order by query_start ASC;
  pid  | state  |                                                                query                                                                 
-------+--------+--------------------------------------------------------------------------------------------------------------------------------------
  4562 | active | autovacuum: ANALYZE public.photos_photo

und

select pg_terminate_backend(4562);

funktioniert leider nicht… Oder kann es sein, dass der autovaccum Prozess sofort wieder gestartet wird?

  1. Warum willst Du das beenden?
  2. Ja. Wenn eine Tabelle ‘reif’ für einen Autovacuum-Lauf ist, dann wird da recht zeitnah das wieder gestartet. Das dürfte dann auch einen andere PID haben.