[{"data":1,"prerenderedAt":347},["ShallowReactive",2],{"blog-ja-2026-03-01-tokyo-service-supabase":3},{"id":4,"title":5,"body":6,"category":328,"date":329,"description":330,"draft":331,"extension":332,"lang":333,"meta":334,"navigation":340,"path":341,"seo":342,"sitemap":343,"slug":344,"stem":345,"updated":329,"__hash__":346},"blog/blog/ja/2026-03-01-tokyo-service-supabase.md","Supabase Signup が失敗する：gen_random_bytes() does not exist",{"type":7,"value":8,"toc":314},"minimark",[9,14,18,29,32,42,46,52,56,59,62,65,68,72,79,90,93,97,102,157,161,206,210,219,222,231,235,238,249,252,260,264,270,281,289,293,296,310],[10,11,13],"h2",{"id":12},"問題現象","❗ 問題現象",[15,16,17],"p",{},"ユーザー登録（Signup）が失敗し、以下のエラーが発生します。",[19,20,26],"pre",{"className":21,"code":23,"language":24,"meta":25},[22],"language-text","function gen_random_bytes(integer) does not exist\nNo function matches the given name and argument types\ncurrent transaction is aborted, commands ignored until end of transaction block\n","text","",[27,28,23],"code",{"__ignoreMap":25},[15,30,31],{},"主な症状：",[33,34,35,39],"ul",{},[36,37,38],"li",{},"新規ユーザーを作成できない",[36,40,41],{},"Supabase Auth の Signup が継続的に失敗する",[10,43,45],{"id":44},"実行フロー","🔄 実行フロー",[19,47,50],{"className":48,"code":49,"language":24,"meta":25},[22],"Client Signup\n  ↓\nauth.users INSERT\n  ↓\nAFTER INSERT Trigger\n  ↓\ncreate_profile_for_new_user()\n  ↓\ngen_random_bytes()\n",[27,51,49],{"__ignoreMap":25},[10,53,55],{"id":54},"原因分析","🔍 原因分析",[15,57,58],{},"gen_random_bytes() は PostgreSQL の コア組み込み関数ではありません。\nこれは pgcrypto 拡張 により提供される関数です。\nSupabase 環境では、pgcrypto 関数は通常 extensions schema に配置されています：\nextensions.gen_random_bytes()",[15,60,61],{},"Supabase の Signup 処理では：\nauth.users → trigger → カスタム関数 が実行され、この関数は多くの場合 SECURITY DEFINER として動作します。",[15,63,64],{},"SECURITY DEFINER 関数では、 呼び出し元の search_path は継承されません。\n代わりに PostgreSQL は、 関数作成時に記録された search_path を使用します。",[15,66,67],{},"この search_path に extensions schema が含まれていない場合、\npgcrypto 拡張がインストール済みでも gen_random_bytes() を解決できません。\nこの問題は拡張未インストールではなく、 関数解決（function lookup）段階 で発生します。",[10,69,71],{"id":70},"根本原因root-cause","🎯 根本原因（Root Cause）",[15,73,74,75,78],{},"Supabase Auth Trigger は通常 SECURITY DEFINER で実行されます。",[76,77],"br",{},"\nこの場合：",[33,80,81,84,87],{},[36,82,83],{},"関数作成時の search_path が使用される",[36,85,86],{},"extensions などの非デフォルト schema が不可視になる",[36,88,89],{},"schema 未指定の関数呼び出しが失敗する",[15,91,92],{},"つまり問題は Supabase Auth ではなく、 SECURITY DEFINER\n実行環境における schema 可視性にあります。",[10,94,96],{"id":95},"解決方法","✅ 解決方法",[98,99,101],"h3",{"id":100},"schema-を明示する","schema を明示する",[19,103,107],{"className":104,"code":105,"language":106,"meta":25,"style":25},"language-sql shiki shiki-themes github-light github-light github-dark","extensions.gen_random_bytes(16)\n-- または\npgcrypto.gen_random_bytes(16)\n","sql",[27,108,109,134,141],{"__ignoreMap":25},[110,111,114,118,122,125,128,131],"span",{"class":112,"line":113},"line",1,[110,115,117],{"class":116},"sBjJW","extensions",[110,119,121],{"class":120},"sxrX7",".",[110,123,124],{"class":116},"gen_random_bytes",[110,126,127],{"class":120},"(",[110,129,130],{"class":116},"16",[110,132,133],{"class":120},")\n",[110,135,137],{"class":112,"line":136},2,[110,138,140],{"class":139},"sCsY4","-- または\n",[110,142,144,147,149,151,153,155],{"class":112,"line":143},3,[110,145,146],{"class":116},"pgcrypto",[110,148,121],{"class":120},[110,150,124],{"class":116},[110,152,127],{"class":120},[110,154,130],{"class":116},[110,156,133],{"class":120},[98,158,160],{"id":159},"関数内で-search_path-を設定する","関数内で search_path を設定する",[19,162,164],{"className":104,"code":163,"language":106,"meta":25,"style":25},"CREATE OR REPLACE FUNCTION ...\nSECURITY DEFINER\nSET search_path = public, extensions;\n",[27,165,166,184,192],{"__ignoreMap":25},[110,167,168,172,175,178,181],{"class":112,"line":113},[110,169,171],{"class":170},"s8jYJ","CREATE",[110,173,174],{"class":170}," OR",[110,176,177],{"class":170}," REPLACE",[110,179,180],{"class":170}," FUNCTION",[110,182,183],{"class":120}," ...\n",[110,185,186,189],{"class":112,"line":136},[110,187,188],{"class":170},"SECURITY",[110,190,191],{"class":120}," DEFINER\n",[110,193,194,197,200,203],{"class":112,"line":143},[110,195,196],{"class":170},"SET",[110,198,199],{"class":120}," search_path ",[110,201,202],{"class":170},"=",[110,204,205],{"class":120}," public, extensions;\n",[98,207,209],{"id":208},"代替案random","代替案：random()",[19,211,213],{"className":104,"code":212,"language":106,"meta":25,"style":25},"random()\n",[27,214,215],{"__ignoreMap":25},[110,216,217],{"class":112,"line":113},[110,218,212],{"class":120},[15,220,221],{},"⚠️ 注意：",[15,223,224,227,228,230],{},[27,225,226],{},"random()"," は暗号学的に安全な乱数ではありません。",[76,229],{},"\ntoken や識別子などのセキュリティ用途には使用しないでください。",[10,232,234],{"id":233},"️-ベストプラクティス","🛡️ ベストプラクティス",[15,236,237],{},"Auth Trigger では以下を避ける：",[33,239,240,243,246],{},[36,241,242],{},"拡張関数への依存",[36,244,245],{},"schema を跨ぐ呼び出し",[36,247,248],{},"複雑なビジネスロジック",[15,250,251],{},"Trigger は以下のみに限定する：",[33,253,254,257],{},[36,255,256],{},"シンプルな INSERT",[36,258,259],{},"最小限の初期データ生成",[10,261,263],{"id":262},"まとめ","📌 まとめ",[15,265,266,267,269],{},"gen_random_bytes() エラーは 関数が存在しないことを意味しません。",[76,268],{},"\n原因は：",[33,271,272,275,278],{},[36,273,274],{},"SECURITY DEFINER による実行環境の固定化",[36,276,277],{},"search_path に extensions schema が含まれない",[36,279,280],{},"pgcrypto 関数の解決失敗",[15,282,283,284,288],{},"これは ",[285,286,287],"strong",{},"PostgreSQL の schema 可視性問題であり、Supabase のバグではありません","。",[10,290,292],{"id":291},"適用ケース","📎 適用ケース",[15,294,295],{},"本記事は以下の場合に有効です：",[33,297,298,301,304,307],{},[36,299,300],{},"Supabase Auth Trigger エラー",[36,302,303],{},"PostgreSQL SECURITY DEFINER 問題",[36,305,306],{},"pgcrypto 関数が呼び出せない",[36,308,309],{},"Trigger 内で拡張関数が失敗する場合",[311,312,313],"style",{},"html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":25,"searchDepth":136,"depth":136,"links":315},[316,317,318,319,320,325,326,327],{"id":12,"depth":136,"text":13},{"id":44,"depth":136,"text":45},{"id":54,"depth":136,"text":55},{"id":70,"depth":136,"text":71},{"id":95,"depth":136,"text":96,"children":321},[322,323,324],{"id":100,"depth":143,"text":101},{"id":159,"depth":143,"text":160},{"id":208,"depth":143,"text":209},{"id":233,"depth":136,"text":234},{"id":262,"depth":136,"text":263},{"id":291,"depth":136,"text":292},"supabase","2026-03-01T00:00:00.000Z","Supabase Signup で発生する \n「gen_random_bytes() does not exist」エラーの本当の原因。 \nPostgreSQL の SECURITY DEFINER により固定された search_path が使用され、 \npgcrypto 関数へアクセスできなくなる問題を解説します。",false,"md","ja",{"tags":335},[328,336,337,146,338,339],"postgresql","trigger","security-definer","database-debug",true,"/blog/ja/2026-03-01-tokyo-service-supabase",{"title":5,"description":330},{"loc":341},null,"blog/ja/2026-03-01-tokyo-service-supabase","LSCLbBUEAr6_EIAve6wJHn9QjfUvYuHkvSzqWG5-oZg",1784966029638]