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

psql Command Line အခြေခံ

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

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

  • 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 — psqlPostgreSQL 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 သုံးခုကိုရှာပါ။

You'll know it worked when: PostgreSQL 18.x version၊ `tutorial_platform` database နှင့် `postgres` user ကို မြင်ရမည်။

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