Thuta Learning
ရှာဖွေရန်
AdvancedData & Databasesbeginner

Connections၊ Pooling နှင့် Server Security

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Connections၊ Pooling နှင့် Server Security concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ SQL/command ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် အသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

PostgreSQL connection တစ်ခုစီက server resources သုံးလို့ application instance တစ်ခုစီ pool အကြီးကြီးဖွင့်ရင် `max_connections` အမြန်ပြည့်ပါတယ်။ Total pool budget ကို app instances၊ workers၊ admin နဲ့ failover headroom အလိုက်တွက်ရပါတယ်။ Network allowlist၊ TLS certificate verification၊ SCRAM password နှင့် least privilege role တို့ကိုအတူသုံးပါ။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

API pool ကို small maximum၊ acquire timeout၊ statement timeout နှင့် idle-in-transaction timeout ဖြင့်ထားမယ်။ PgBouncer လို external pooler သုံးလျှင် transaction pooling နဲ့ session-level features compatibility ကိုစစ်ရပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

text
Connection budget example
-------------------------
Database safe budget:        100
Reserved admin/failover:     -20
Background workers:          -10
Available to app:             70
7 app instances → max 10 connections per instance

Session safety:
statement_timeout = 5s
lock_timeout = 2s
idle_in_transaction_session_timeout = 30s
You should see
Application scale နဲ့ကိုက်ညီသော connection budget နှင့် timeout policy ရမည်။

၅ မိနစ် စမ်းကြည့်

App instances 12 ခု၊ worker 4 ခုနှင့် database budget 120 ရှိလျှင် admin headroom ပါ pool plan တွက်ပါ။

သတိလေးတစ်ချက်

Connection error တွေ့တိုင်း `max_connections` တိုးခြင်းက memory pressure နှင့် contention ကိုပိုဆိုးစေနိုင်ပါတယ်။

PostgreSQL — Client AuthenticationPostgreSQL Global Development Group

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Connection error တွေ့တိုင်း `max_connections` တိုးခြင်းက memory pressure နှင့် contention ကိုပိုဆိုးစေနိုင်ပါတယ်။
  • နမူနာ code ကို production data ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test database နှင့် recoverable backup ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

App instances 12 ခု၊ worker 4 ခုနှင့် database budget 120 ရှိလျှင် admin headroom ပါ pool plan တွက်ပါ။

You'll know it worked when: Application scale နဲ့ကိုက်ညီသော connection budget နှင့် timeout policy ရမည်။

Connections၊ Pooling နှင့် Server Security | Thuta Learning