Suche senden
Hochladen
postgreSQLを魔改造して 緊急対応した話
•
Als PPTX, PDF herunterladen
•
0 gefällt mir
•
321 views
asa 999
Folgen
時間がない時に他人が作ったプログラムを緊急対応したという、ツラミ的なお話。
Weniger lesen
Mehr lesen
Ingenieurwesen
Melden
Teilen
Melden
Teilen
1 von 13
Jetzt herunterladen
Empfohlen
PostgreSQL失敗談
PostgreSQL失敗談
Takashi Meguro
楽しい血圧の話
楽しい血圧の話
asa 999
Writexlsxについて
Writexlsxについて
asa 999
B3発表
B3発表
asa 999
Writeexcelについて
Writeexcelについて
asa 999
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
Empfohlen
PostgreSQL失敗談
PostgreSQL失敗談
Takashi Meguro
楽しい血圧の話
楽しい血圧の話
asa 999
Writexlsxについて
Writexlsxについて
asa 999
B3発表
B3発表
asa 999
Writeexcelについて
Writeexcelについて
asa 999
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
Weitere ähnliche Inhalte
Empfohlen
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
Empfohlen
(20)
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
ChatGPT webinar slides
ChatGPT webinar slides
postgreSQLを魔改造して 緊急対応した話
1.
postgreSQLを魔改造して 緊急対応した話 こういう案件もあるよ、っていうだけの話
2.
書いた人 使ってる言語:だいたいbashとpython、oracleとpostgreSQL 好きなエディタ:サクラエディタ 最近のトピック:頭から血が出て入院した 最近のトレンド:slackの個人timelineで毎日使えない豆知識を披露 最近気になるもの:ヘルゲート 地獄の門 原題:Houndz
from Hell(2011)
3.
注意:Caution 本件は割と時間のない中、無理やりやった対応になります。 なので基本的には参考になりません。 正しいコーディング < 実行期限に間に合わせる という状況のもとやった対応になるので、真似しないでください。 多分偉い人に怒られます。
4.
状況 bash+postgreSQLで動いてるプログラムに、条件が1行追加された。 これを実現しようとするとかなりでかいテーブルを見る必要があり、 SQLを一応効率化したけど、56回動くプログラムだったので、1日中に終わらな くて突き抜けて翌日に突入し、他プログラムにも迷惑をかけた。
5.
状況2 遅いと思って後からログを見たら、一部のスクリプトがエラーになっていて正常 なデータを獲得できていなかった。 ERROR: canceling statement
due to conflict with recovery ただし、bash+postgreSQLの構成でこのエラーはエラー終了せず、正常終了して いるように見える。鬼畜ステルスエラー。 selectがデカすぎて、色々あってpostgreSQLが途中で諦めることが原因。 とにかくクリティカルなレポートなので急ぎ修正+再実行が急務。
6.
現状のプログラムと制約 ・およそ600行くらいのプログラム(行数としては小さい) ・SQLを動的に作りまくるタイプ(とにかく読みづらい) ・現状の1回の実行は数分〜30分程度 ただし一部の実行が2時間以上かかりエラー ←こいつをどうにかしたい ・QAをする人の事も考えて修正は最小限にしたい(小手先でどうにかしたい) ・タイムリミットはおよそQAと実行を含め24時間 ・数ヶ月後には今のロジック自体が必要なくなる(安心してね)
7.
SQLの現状 解析してみると、同じSQLをselect句が違う形で7回実行している。 SQLの効率化はある程度できており、indexやヒント句でどうにかなりそうもない。 というか自分がpostgreSQLに詳しくないので、そんなに効率化できない。 インドの魔法(select句内select)はすでに使っている。 ↑まあこれがpostgreSQLで早いかは、あんまりちゃんと検証してない oracleじゃないので中間テーブルを作りまくる作戦が使えない(環境的に)
8.
じゃあoracleでいいじゃん postgreSQLのSQLを細かく分割し、joinを減らすほうが格段に早い→join負荷 必要部分の各テーブルは精々数百行程度→繋げるデータ自体は小さい すでに別データの部分は一旦oracleにデータ出力してる場所がある→実績あり
9.
よし、oracleだ ←この時点で夜3時なんで考えるのをやめた
10.
でっけえSQLは大体そのままで、oracle化 現状 改善後 でっけえSQL 7回呼ぶ、基礎部分が 終わってるので早い 基礎部分を実行 中間テーブルを全て作成 コピー 7回呼ぶ コピー
11.
実行結果 現状:selectがデカすぎて2時間くらいかけてエラーで正常終了しない 改善後:多いデータの場合も、だいたい数分くらいで終わるようになった 良い点1:殆ど流用なので100行くらいの追加変更で済んだ。 良い点2:ロジック自体変更してないので、実行までにQAも間に合った。
12.
まとめ 時間制約のキツイ、かなり特殊な案件だったので、無理やり対応しましたが、 本来であればpython+pandasにする案件だったと思います。 みんなも作るときに、SQL動的作成は出来るだけ辞めて、基礎部分と データ利用部にちゃんと分けましょう。 まあ緊急措置ですがとりあえず動いたのでよし。あとDB自体を変えてるから、 ロジックが一緒でも割り算とか小数点とかの挙動が違うケースがあるので、 100%同一保証にはならない点も注意。
13.
余談 あと、古いプログラムに念の為 set -e
を入れたら超大量に関係ないところの エラーが出まくったので、レガシーレポートを触るときには根気が必要。 しかもset -e 入れても、パイプのエラーの措置(set -eu -o pipefail)を入れても postgreSQLのエラーはpsqlがエラーでも正常終了するので関係なかった。 後から知ったけど、psqlでON_ERROR_STOPをするとエラーストップ できるらしい。 そして、ヘルゲート地獄の門はおすすめ、みんなで1時間を捨てよう。
Jetzt herunterladen