Thuta Learning
PostgreSQL
BasicData & Databasesအခြေခံ

psql Command Line အခြေခံ

PostgreSQLသင်ခန်းစာ 4

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

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

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

`psql` က PostgreSQL ရဲ့ official interactive terminal ဖြစ်ပါတယ်။ SQL statement များကို semicolon နဲ့ဆုံးပြီး run ရသလို `\l`၊ `\dt`၊ `\d` စတဲ့ backslash meta-command များက client-side အကူအညီပေးပါတယ်။ Prompt ပြောင်းသွားရင် quote သို့ parenthesis မပိတ်သေးတာ ဖြစ်နိုင်ပြီး `\r` နဲ့ input buffer ရှင်းနိုင်ပါတယ်။

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

Container ထဲက `psql` ကိုသုံးပြီး `tutorial_platform` သို့ဝင်ပါ။ Server version၊ current database နဲ့ current user ကို query လုပ်ပြီး `\conninfo` ဖြင့် connection ကိုစစ်ပါ။ Lesson များအတွင်း SQL ဖိုင်ကို `\i filename.sql` ဖြင့် run နိုင်ပါတယ်။

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

bash
docker exec -it pg-tutorial psql -U postgres -d tutorial_platform

SELECT version();
SELECT current_database(), current_user;
\conninfo
\dt
\q
You should see
PostgreSQL 18.x version၊ `tutorial_platform` database နှင့် `postgres` user ကို မြင်ရမည်။

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

`\?` ဖြင့် meta-command help ကိုဖွင့်ပြီး database၊ table နှင့် function list command သုံးခုကိုရှာပါ။

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

`\dt;` လို့ semicolon မထည့်ပါနှင့်—meta-command က SQL statement မဟုတ်ပါ။

PostgreSQL — psql — PostgreSQL Global Development Group

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

  • `\dt;` လို့ semicolon မထည့်ပါနှင့်—meta-command က SQL statement မဟုတ်ပါ။
  • နမူနာ code ကို production data ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test database နှင့် recoverable backup ပေါ်တွင် အရင်အတည်ပြုပါ။

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

`\?` ဖြင့် meta-command help ကိုဖွင့်ပြီး database၊ table နှင့် function list command သုံးခုကိုရှာပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: PostgreSQL 18.x version၊ `tutorial_platform` database နှင့် `postgres` user ကို မြင်ရမည်။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

psql Command Line အခြေခံ | Thuta Learning