xiaohongshu
xiaohongshu
データベース接続管理の専門スキル。 サーバーレス環境での接続管理、Tursoの接続管理とEmbedded Replicas、 高負荷時の接続最適化を専門とします。 専門分野: - 接続管理設計: 環境に応じた最適な接続設定 - サーバーレス対応: TursoでのlibSQL接続管理とEmbedded Replicas - Drizzle ORM統合: DrizzleでのlibSQL接続設定 - 障害対策: 接続エラーハンドリングとリトライ - 監視: 接続状態の監視とアラート 使用タイミング: - 新規プロジェクトでDB接続を設定する時 - 接続設定のサイジングを決める時 - サーバーレ...
Full skill instructions
このスキルは、データベース接続管理の設計と実装に関する 知識を提供します。特にサーバーレス環境(Turso)での libSQL接続管理とEmbedded Replicasに焦点を当てています。
主要な価値:
対象ユーザー:
.claude/agents/dba-mgr.mdエージェントconnection-pooling/
├── SKILL.md # 本ファイル
├── resources/
│ ├── pool-sizing-guide.md # プールサイジング
│ ├── serverless-connections.md # サーバーレス接続
│ └── error-handling.md # エラーハンドリング
├── scripts/
│ └── check-connections.mjs # 接続状態確認
└── templates/
└── drizzle-config-template.ts # Drizzle設定テンプレート
# プールサイジング
cat .claude/skills/connection-pooling/resources/pool-sizing-guide.md
# サーバーレス接続
cat .claude/skills/connection-pooling/resources/serverless-connections.md
# エラーハンドリング
cat .claude/skills/connection-pooling/resources/error-handling.md
# 接続状態確認
node .claude/skills/connection-pooling/scripts/check-connections.mjs
状況: 新しいプロジェクトでDB接続を設定する
適用条件:
期待される成果: 最適な接続プール設定
状況: 「too many connections」などのエラーが発生
適用条件:
期待される成果: 安定した接続設定
状況: サーバーレス環境への移行で接続管理を見直す
適用条件:
期待される成果: サーバーレス対応の接続設定
目的: 接続要件を明確化する
ステップ:
環境の確認:
負荷の見積もり:
判断基準:
リソース: resources/serverless-connections.md
目的: 適切な接続設定を決定する
ステップ:
接続設定の実装:
// Turso接続設定
const config = {
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
};
Embedded Replicas設定:
const client = createClient({
url: "file:local.db", // ローカルレプリカ
syncUrl: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
syncInterval: 60, // 60秒ごとに同期
});
判断基準:
リソース: resources/pool-sizing-guide.md
目的: 接続エラーに対する回復力を確保する
ステップ:
リトライ戦略:
サーキットブレーカー:
判断基準:
リソース: resources/error-handling.md
目的: 接続状態を継続的に監視する
ステップ:
メトリクスの収集:
アラート設定:
判断基準:
アプリケーション
│
├── リクエスト1 ──→ [接続1]
├── リクエスト2 ──→ [接続2] ←── 接続プール
├── リクエスト3 ──→ [接続3] (再利用)
└── リクエスト4 ──→ [待機...]
│
▼
データベース
| モード | 説明 | 用途 |
|---|---|---|
| Session | 接続をセッション全体で保持 | 長いトランザクション |
| Transaction | トランザクション単位で割り当て | 一般的なWeb |
| Statement | ステートメント単位で割り当て | 高速なクエリ |
Lambda/Edge Function
│
├── コールドスタート → 新規接続
│ (オーバーヘッド)
├── ウォームスタート → 既存接続再利用
│ (高速)
└── スケールアウト → 接続爆発のリスク
(プーラーで制御)
適切な接続方式を選択する:
接続を適切にリリースする:
try {
const result = await client.execute("SELECT * FROM users");
return result;
} finally {
// libSQLクライアントは自動的に接続を管理
// Embedded Replicasの場合は定期的に同期
}
同期設定を最適化する:
const config = {
syncInterval: 60, // 同期間隔(秒)
syncOnWrite: true, // 書き込み時に同期
readYourWrites: true, // 自分の書き込みを即座に読み取り
};
接続のリーク:
不適切な同期設定:
Embedded Replicasの未活用:
症状: Embedded Replicasの同期が失敗
原因:
解決策:
// 同期状態の確認
const syncStatus = await client.sync();
console.log("Sync completed:", syncStatus);
// 手動で強制同期
await client.sync();
// 同期エラーのハンドリング
client.on("sync-error", (error) => {
console.error("Sync failed:", error);
// リトライロジック
});
症状: Tursoへの接続がタイムアウト
原因:
解決策:
// Embedded Replicasを使用してローカル接続
const client = createClient({
url: "file:local.db",
syncUrl: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
// リトライ戦略
const retryConfig = {
retries: 3,
factor: 2,
minTimeout: 1000,
maxTimeout: 5000,
};
症状: Lambda/Edgeの初回リクエストが遅い
原因:
解決策:
.claude/skills/query-performance-tuning/SKILL.md): クエリ最適化.claude/skills/backup-recovery/SKILL.md): バックアップ戦略| 指標 | 目標値 | 警告値 |
|---|---|---|
| 接続使用率 | < 80% | > 90% |
| 待機リクエスト | 0 | > 10 |
| 接続エラー率 | < 0.1% | > 1% |
| 平均接続時間 | < 100ms | > 500ms |
| バージョン | 日付 | 変更内容 |
|---|---|---|
| 1.0.0 | 2025-11-27 | 初版作成 - 接続プール管理 |
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience