Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

database - PostgreSQL query won't finish on StandBY server

We have a Primary-Stanby setup on PostgreSQL 12.1. A DELETE query is run on the primary server (which takes time but finishes completely) however the same query does not finish (and runs like forever):

DELETE FROM EVENTS
WHERE Event_Type_ID != 2
AND last_update_time <= '2020-11-04'
AND Event_ID NOT IN ( SELECT DISTINCT Event_ID FROM Event_Association )
AND Event_ID NOT IN ( SELECT DISTINCT Event_ID FROM EVENTS WHERE Last_Update_Time > '2020-11-14');

The execution plan is as follows (replacing delete with select query for the same): https://explain.depesz.com/s/GZp7

There is a INDEX created on EVENTS.Event_ID and Event_Association.Event_ID however the delete query still won't finish on the standby server. The EVENTS table has more than 2 million rows and the Event_Association table has more than 300,000 rows.

Can someone help me resolve this issue?

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...