Skip to content

Instantly share code, notes, and snippets.

@pypt
Created July 6, 2016 01:06
Show Gist options
  • Save pypt/f2c3791606f0954ef35a707842f43f31 to your computer and use it in GitHub Desktop.
Save pypt/f2c3791606f0954ef35a707842f43f31 to your computer and use it in GitHub Desktop.
PostgreSQL deadlock
ERROR: deadlock detected
DETAIL: Process 2440 waits for ShareLock on transaction 521934; blocked by process 2438.
Process 2438 waits for ShareLock on transaction 521935; blocked by process 2440.
Process 2440: WITH new_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id) AS (VALUES
-- New sentences to potentially insert
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Springbrook twins Andrew, Aaron Robinson headed for prep year at Putnam Science Academy', 0, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'If you spent time in gyms around Montgomery County during the past few high school basketball seasons, you
probably heard their names.', 1, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Everyone in Montgomery County knows “the Robinson twins,” who starred for Springbrook over the past few sea
sons.', 2, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Known for versatile athleticism and smooth shooting touches, they’ve been two of the most prominent faces o
n one of the county’s perennial contenders.', 3, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Springbrook’s Andrew (right)
Process 2438: WITH new_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id) AS (VALUES
-- New sentences to potentially insert
(FALSE, 'en', 5, '2014-05-01 12:41:39'::timestamp, 'Stonewall Jackson DL Tim Settle earns The Opening invite despite wardrobe mishap', 0, 958),
(FALSE, 'en', 5, '2014-05-01 12:41:39'::timestamp, 'Stonewall Jackson All-Met Tim Settle earns The Opening invite, talks recruiting (Ricky Carioti/The Washingt
on Post).', 1, 958),
(FALSE, 'en', 5, '2014-05-01 12:41:39'::timestamp, 'Stonewall Jackson defensive tackle Tim Settle has long been on college coaches’ radars with a rare mix of s
peed and power that is rarely seen on the high school level.', 2, 958),
(FALSE, 'en', 5, '2014-05-01 12:41:39'::timestamp, 'His skills earned him an invite to the Nike Football Training Camp (NFTC) last season, but he left without
an invite to ESPN-televised The Opening combine in Beaverton, Ore.', 3, 958),
(FALSE, 'en', 5, '2014-05-01 12:41:
HINT: See server log for query details.
CONTEXT: while locking tuple (6839,28) in relation "story_sentences"
STATEMENT: WITH new_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id) AS (VALUES
-- New sentences to potentially insert
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Springbrook twins Andrew, Aaron Robinson headed for prep year at Putnam Science Academy', 0, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'If you spent time in gyms around Montgomery County during the past few high school basketball seasons, you probably heard their names.', 1, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Everyone in Montgomery County knows “the Robinson twins,” who starred for Springbrook over the past few seasons.', 2, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Known for versatile athleticism and smooth shooting touches, they’ve been two of the most prominent faces on one of the county’s perennial contenders.', 3, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Springbrook’s Andrew (right) and Aaron Robinson are hoping to land Division I basketball scholarships to the same school (Photo courtesy of Andrew Robinson)', 4, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'At some points in the past few seasons, Andrew’s name might have come up more often — like after he finished his junior season averaging 17.5 points per game, Montgomery County’s top non-senior scorer.', 5, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Sometimes, like when he heated up beyond the arc in the midst of the Blue Devils’ 2014 state tournament run, Aaron’s name carried buzz.', 6, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'But rarely would you hear one Robinson’s name without the other’s, and Andrew and Aaron wouldn’t mind keeping it that way.', 7, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Andrew had nine Division I offers coming into his senior season and Aaron was thinking Division II or prep school to improve his stock, but they decided last week to attend Putnam Science Academy (Conn.) next year in the hopes of earning more Division I options and — potentially — staying together at the college level.', 8, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“We definitely do want to try to go to the same school, which is one of the reasons we decided to go with a prep year,” Andrew said.', 9, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“But it depends on the situation.', 10, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'If it’s a good fit for both of us, we definitely want to do that and go to the same school.', 11, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'But if it’s not a good fit for each of us, we’ll go to separate schools.', 12, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'We want both of us to have a good college experience, so it’s all about the fit really.”', 13, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Aaron averaged 11 points per game this season for the state semifinalist Blue Devils, showing knock-down potential from three — most memorably when he hit five threes in Springbrook’s region final win over Dulaney.', 14, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Though he showed Division I potential at times in his junior and senior seasons, Aaron emerged later than Andrew.', 15, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'For that reason, with a Division I-ready 6-4 frame and that potentially deadly shooting touch, Aaron considered prep school to reintroduce himself to college coaches.', 16, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“I really liked the fact that the league that they play in is so competitive, the fact that they prepare players so well and send so many guys to Division I,” said Aaron, who was considering Division II options as well.', 17, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“I was talking to a lot of the players, and they all told me ‘if you come here, you’re going to get better and have a chance for a lot of exposure.’', 18, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'For me, as a kid, the goal was always to play Division I basketball, so to hear the coaches say if I come there, I’ll have a really good chance of playing Division I, I was really happy to hear that and have another opportunity to get better and chase all those dreams I had as a kid.”', 19, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Andrew wasn’t even considering prep school until Aaron returned from his visit to Putnam, readying instead to choose from one of his mid-major suitors or hope for offers from a few late arrivals to his recruiting.', 20, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“When he came back from his visit, the Putnam coach texted me,” said Andrew, who averaged 17 points per game this season.', 21, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“At first, I wasn’t really on board because I was considering going to college, but the more and more I learned about prep school — the fact that they’re ranked top five in the nation and send a lot of their kids to Division I schools — it really started to sway my decision.', 22, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'I started to think about it more and more, the opportunity to play with my brother one more year and give it one more shot at recruiting, that was really the deciding factor for me.”', 23, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Andrew added that the schools that had already offered him – Delaware, Drexel, Towson, Siena, Marshall, Robert Morris, Binghamton, LIU Brooklyn and UMBC — said they’d still recruit him through his prep year, meaning he’d “have nothing to lose,” from taking the extra year of development.', 24, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'He added that higher profile basketball schools like Dayton and Providence had recently expressed interest, so the opportunity to bolster his resume and move from mid-major prospect to potential power conference recruit while preparing for the college game was one he couldn’t pass up.', 25, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“I want to become more of a scorer, a one-on-one scorer,” Andrew said.', 26, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“I also have to improve on my defense and quickness.', 27, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'In college, I’ll be playing a guard, so I have to work on my quickness and my defense so I can defend shooting guards and point guards.”', 28, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Aaron has similar goals for his year at Putnam, in addition to pinging the radar of Division I scouts.', 29, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“I want to be able to improve on my ball-handling and my mid-range game,” Aaron said.', 30, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '“I’m a shooter, so I want to be able to create my own shot off the dribble, score from outside, inside, mid-range.', 31, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'And also get stronger to be more ready for college.”', 32, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'NUMBER CRUNCH: 4', 33, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Aaron Robinson hit four or more threes in a game four times in 2013-2014.', 34, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'WHAT TO WATCH FOR:', 35, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'This week’s Post rankings for baseball, softball, soccer and lacrosse, which will be online this afternoon.', 36, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'BREAKFAST LINKS:', 37, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '– In what had become the WCAC’s regular season boys’ lacrosse title game, Alabama-bound football star Richie Petitbon led No. 2 Gonzaga to an 8-7 win over No. 4 DeMatha Tuesday afternoon', 38, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '– Soaked and slipping, the No. 3 Briar Woods girls’ soccer team gave No. 2 Tuscarora its first loss of the season Tuesday night', 39, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '– The D.C. sports scene mourned the loss of longtime coach Kenneth “Buddy” Burkhead last week', 40, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '– DeMatha used a last-minute sub to spark a Stags win in the 4 x 100 relay at the Penn Relays last weekend', 41, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '– Maryland recruits Jared Nickens and Melo Trimble stood out in last weekend’s Capital Classic', 42, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, '– Everyone knows concussions are a problem in football and other high-impact contact sports, but did you know girls’ soccer has just as big a problem ?', 43, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'PHOTOS OF THE DAY:', 44, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Check out the scene from the drenched girls’ soccer showdown between No. 3 Briar Woods and No. 2 Tuscarora.', 45, 960)
),
duplicate_sentences AS (
-- Either a list of duplicate sentences already found in the table
-- or an empty list if deduplication is disabled
UPDATE story_sentences
SET is_dup = 't',
disable_triggers = 't'
FROM new_sentences
WHERE half_md5(story_sentences.sentence) = half_md5(new_sentences.sentence)
AND week_start_date( story_sentences.publish_date::date )
= week_start_date( new_sentences.publish_date::date )
AND story_sentences.media_id = new_sentences.media_id
RETURNING story_sentences.sentence
)
INSERT INTO story_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id)
SELECT disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id
FROM new_sentences
WHERE sentence NOT IN (
-- Skip the ones for which we've just set is_dup = 't'
SELECT sentence
FROM duplicate_sentences
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment