The discussion revolves around accessing the Discourse database, particularly in a Docker setup. Users seek ways to view and edit the database, with suggestions including using the Data Explorer Plugin for a safer, GUI-like experience. For direct access via the command line, the recommended approach is to enter the container using ./launcher enter app, switch to the discourse user, and then use psql discourse to connect to the database. The correct command to run PostgreSQL commands as the postgres user is sudo -u postgres psql discourse. Users are reminded that commands in psql must end with a semicolon, and that \dt lists tables, while \d [table] shows table structure. A detailed guide is provided by neounix for beginners, emphasizing the importance of testing on a staging environment before making changes to production. profcaju also asks about connecting via external SQL clients like PSequel, and DScryber inquires about using the Data Explorer plugin to list accessible databases.
This is probably a stupid question but how can I access the database?
Is there something equivalent to phpadmin (or another GUI) that I can use to view and edit the database of discourse? If not, then what is the best way to access/view/edit it?
هل يمكنك شرح هذه العملية؟ أنا مبتدئ في مجال الحاويات، وأود أن أبدأ في تجربة قاعدة بيانات PostgreSQL الخاصة بي بدلاً من أن تكون الحاوية بالنسبة لي صندوقًا أسود كبيرًا
بافتراض أنك تعمل في وضع الحاوية المفردة الافتراضي (OOTB) ضمن الإعداد القياسي المدعوم:
cd /var/discourse
./launcher enter app
su discourse
psql discourse
الآن، إذا كان كل شيء يعمل بشكل صحيح، فأنت داخل قاعدة البيانات كمستخدم discourse ومتصل بقاعدة بيانات discourse وجاهز لإصدار أوامر PostgreSQL و SQL.
ثم، إذا أردت سرد جميع الجداول في قاعدة البيانات، يمكنك استخدام الأمر التالي:
\dt
أما إذا أردت سرد جميع الجداول التي تحتوي على كلمة “setting”، يمكنك استخدام:
\dt *setting*
إذا وجدت جدولًا يثير اهتمامك، مثل جدول المستخدمين، يمكنك فحص هيكل الجدول كالتالي:
\d users
إذا رغبت (على سبيل المثال، وليس هذا مثالًا فعالًا) في فحص أول 10 مستخدمين (مرتبة حسب المعرف تنازليًا، فقط 10)، يمكنك ببساطة استخدام:
SELECT * FROM users ORDER BY id desc LIMIT 10;
بشكل عام، لقد فهمت الفكرة. إذا كنت جيدًا في SQL، فإن الأمر سيكون سهلًا مثل كعكة.
سيوصي الجميع هنا بالتجربة على بيئة تجريبية (حيث إذا كسرت شيئًا يمكنك ببساطة إعادة البناء والبدء من جديد) واستمتع!
لا تجرب على نظام إنتاجي به مستخدمون حقيقيون إلا إذا كنت مرتاحًا جدًا مع هذه التقنية (ربما تكون قد أتقنت الأساسيات على الأقل)، ودائمًا قم بنسخ احتياطي كامل أولاً
بخلاف استخدام Docker، الذي لست على دراية به (ولا أريد إفساد قاعدة البيانات)، هل هناك أوامر SQL يمكنني تشغيلها عبر إضافة مستكشف البيانات لإظهار أسماء قواعد البيانات التي يمكنني الوصول إليها في Discourse؟