psql နဲ့ Databases၊ Roles၊ Schemas နဲ့ Tables စစ်ခြင်း

PostgreSQL 19.0

ချိတ်ဆက်ပြီးရင် ဒီ command တွေကို psql ထဲမှာ ရိုက်ပါ။ Backslash နဲ့ စတဲ့ command တွေကို psql client က ကိုင်တွယ်ပြီး Enter နှိပ်ရုံနဲ့ run တယ်။ SELECT လို SQL statement တွေကိုတော့ server ဆီပို့ပြီး အဆုံးမှာ semicolon ထည့်ပါတယ်။

ဒီစာမျက်နှာမှာ

ဘယ် Server၊ ဘယ် Database ကို ချိတ်ထားလဲ

လက်ရှိ database၊ role နဲ့ ချိတ်ထားတဲ့ address သို့မဟုတ် socket ကို ပြပေးတယ်။

\conninfo

Database စာရင်းကြည့်ခြင်း

ဒီ server ပေါ်က database စာရင်းကို ပြတယ်။ learning_db ဆောက်ပြီးရင် စာရင်းမှာ ပါမပါ ကြည့်ပါ။ ကိုယ့် psql နဲ့ server version၊ locale settings အလိုက် column နဲ့ တန်ဖိုးတွေ ကွာနိုင်တယ်။

\l
Name
learning_db လို database နာမည်ပါ။
Owner
Database ကို ပိုင်ဆိုင်တဲ့ role ပါ။
Encoding
စာလုံးတွေ သိမ်းတဲ့ encoding ပါ။ UTF8 နဲ့ မြန်မာစာ သိမ်းလို့ရတယ်။
Locale Provider
စာသားဆိုင်ရာ locale စည်းမျဉ်းတွေကို ဘယ်ကယူလဲ ပြတယ်။ libc က OS၊ icu က ICU library၊ builtin က PostgreSQL ရဲ့ ကိုယ်ပိုင်စနစ်ပါ။
Collate
စာသားတွေကို ယှဉ်တာနဲ့ အစဉ်လိုက်စီတာအတွက် locale setting ပါ။
Ctype
စာလုံးအမျိုးအစား ခွဲတာနဲ့ အကြီးအသေး ပြောင်းတာအတွက် locale setting ပါ။
Locale
ICU လို ဒီ field သုံးတဲ့ provider ရဲ့ locale identifier ပါ။ libc သုံးရင် လွတ်နေနိုင်တယ်။
ICU Rules
သီးသန့်သတ်မှတ်ထားရင် ICU စာစီစည်းမျဉ်းတွေကို ပြတယ်။
Access privileges
Role တွေအတွက် CONNECT၊ CREATE လို database ခွင့်ပြုချက်တွေကို ပြတယ်။ ကွက်လပ်ဆိုရင် မူလ default ခွင့်ပြုချက်တွေ သက်ရောက်နေနိုင်တယ်။

Database အရေအတွက် ရေတွက်ခြင်း

ဒီ SQL query က ချိတ်ထားတဲ့ server ပေါ်မှာ template databases တွေပါ အပါအဝင် database စာရင်းကို ရေတွက်တယ်။

SELECT count(*) AS database_count FROM pg_database;

Role စာရင်းကြည့်ခြင်း

Role name column မှာ role နာမည်တွေ ပါတယ်။ Attributes column က role တစ်ခုချင်းရဲ့ အထူးလုပ်ပိုင်ခွင့်တွေကို အကျဉ်းပြတယ်။ ပုံမှန် local setup မှာ postgres administrator အတွက် အောက်က attributes တွေ မြင်ရနိုင်တယ်။ ဒီ role တစ်ခုတည်း စစ်ဖို့ \du postgres ကို သုံးပါ။

\du
Superuser
Login လုပ်ခွင့်စစ်တာကလွဲပြီး database permission စစ်ဆေးမှုတွေကို ကျော်နိုင်တယ်။
Create role
Role အသစ် ဆောက်နိုင်ပြီး ကိုယ်စီမံခွင့်ရှိတဲ့ roles တွေကို စီမံနိုင်တယ်။
Create DB
Database အသစ် ဆောက်နိုင်တယ်။
Replication
Login နဲ့ connection rules က ခွင့်ပြုရင် streaming replication စတင်နိုင်တယ်။
Bypass RLS
Row တစ်ကြောင်းချင်းအလိုက် access ကန့်သတ်နိုင်တဲ့ Row-Level Security policies တွေကို ကျော်နိုင်တယ်။
LOGIN / Cannot login
Connection rules က ခွင့်ပြုရင် LOGIN ပါတဲ့ role နဲ့ ဝင်လို့ရတယ်။ LOGIN မပါတဲ့ role ကို ခွင့်ပြုချက်တွေ အုပ်စုဖွဲ့ဖို့ သုံးလို့ရတယ်။

စမ်းကြည့်ရင် ဘာဖြစ်မလဲ နမူနာ row — postgres | Superuser, Create role, Create DB, Replication, Bypass RLS

Schema စာရင်းကြည့်ခြင်း

လက်ရှိ database ထဲက schema တွေကို ပြတယ်။ Schema က table လို database objects တွေကို နာမည်ခွဲပြီး စီပေးတဲ့နေရာပါ။ ဥပမာတွေမှာ ပုံမှန် public schema ကို သုံးမယ်။

\dn

Tables စာရင်းကြည့်ခြင်း

လက်ရှိ schema search path ကနေ မြင်ရတဲ့ tables ကို ပြတယ်။ public ထဲက table တွေကို သီးသန့်ကြည့်ဖို့ \dt public.* လို့ ရိုက်ပါ။ Database အသစ်ဆို ပြစရာ table မရှိသေးတာ ဖြစ်နိုင်တယ်။

\dt

Table ရဲ့ Columns နဲ့ Constraints စစ်ခြင်း

Setup မှာ courses ဆောက်ပြီးရင် ဒီ command က columns၊ data types၊ defaults နဲ့ constraints တွေကို ပြတယ်။ တခြား table ကြည့်ချင်ရင် courses နေရာမှာ အဲဒီနာမည်ကို ထည့်ပါ။

\d courses

ချိတ်ထားတဲ့ Server Version စစ်ခြင်း

SQL function version() က server version ကို ပြတယ်။ OS terminal မှာ ရိုက်တဲ့ psql --version က client version ကို ပြတာပါ။

SELECT version();

Help ကြည့်ခြင်းနဲ့ psql ကနေ ထွက်ခြင်း

တစ်ကြောင်းချင်း run ကြည့်ပါ။ \q က OS terminal ကို ပြန်ပို့လို့ နောက်ဆုံးမှ သုံးပါ။ Output ကို pager နဲ့ ပြနေတယ်ဆို q တစ်လုံးတည်း နှိပ်ရင် pager ပိတ်ပြီး psql ထဲမှာ ဆက်ရှိနေမယ်။

\?
\h SELECT
\q
\?
psql ရဲ့ Backslash commands စာရင်းကို ပြတယ်။
\h SELECT
SQL SELECT ရဲ့ ရေးပုံရေးနည်းကို ပြတယ်။
\q
psql ကို ပိတ်ပြီး terminal ဆီ ပြန်သွားတယ်။

တရားဝင် ကိုးကားချက်များ