أحاول ترحيل خادمي إلى مضيف جديد، لذا قمت بتنزيل ملف نسخة احتياطية، وقمت بتحميله إلى المضيف الجديد. قمت بتثبيت نسخة جديدة من discourse، واتبعت التعليمات للقيام بذلك من سطر الأوامر:
للأسف، يفشل الأمر discourse restore databasename مع:
ALTER TABLE
ALTER TABLE
ALTER TABLE
ERROR: could not create unique index "posts_search_pkey"
DETAIL: Key (post_id)=(36946) is duplicated.
EXCEPTION: psql failed: DETAIL: Key (post_id)=(36946) is duplicated.
/var/www/discourse/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:51:in `run'
script/discourse:149:in `restore'
يبدو أن هناك خطأ ما في ملف قاعدة البيانات؟ هل يمكن لأحد أن يعطيني بعض التوجيهات حول كيفية إصلاح هذا الخطأ؟ لا يزال لدي وصول إلى الخادم الأصلي، والذي يبدو أنه يعمل بشكل جيد.
هل هناك بعض أوامر sql أو شيء يمكنني تشغيله لتحليل (وإصلاح؟) قاعدة البيانات قبل تنزيل نسخة احتياطية؟
./launcher enter app
su - postges
psql discourse
select id from post_search_data were post_id>86918 and post_id<86921;
--- عندما تحصل على المعرف ----
delete from post_search_data where id=ID_FROM_LAST_QUERY
قد يكون هناك المزيد.
ربما يمكن لشخص آخر تقديم المزيد من المساعدة، ولكن هذا هو كل ما أعتقد أنني أستطيع فعله دون تسجيل الدخول إلى الخادم الخاص بك. إذا كنت بحاجة إلى المزيد من المساعدة، يمكنك النشر في Marketplace أو الاتصال بي مباشرة.
أو ربما من الآمن مسحه وتركه يُعاد إنشاؤه، لكنني لست متأكدًا تمامًا من ذلك.
discourse=# reindex index concurrently "posts_search_pkey";
ERROR: could not create unique index "posts_search_pkey_ccnew2"
DETAIL: Key (post_id)=(116038) is duplicated.
discourse=# delete from post_search_data
where post_id = 116038;
DELETE 2
discourse=# delete from post_search_data
where post_id = 116038;
DELETE 0
discourse=# reindex index concurrently "posts_search_pkey";
ERROR: could not create unique index "posts_search_pkey_ccnew3"
DETAIL: Key (post_id)=(9336) is duplicated.
discourse=# delete from post_search_data
where post_id = 9336;
DELETE 1
.
.
.
.
discourse=# reindex index concurrently "posts_search_pkey";
REINDEX
بمجرد أن بدا كل شيء على ما يرام، قمت بعمل نسخة احتياطية كاملة واستعدتها على خادم جديد دون مشاكل.
أقدر وقت الجميع. أحب ديسكورس!
درس مستفاد: تحقق من النسخ الاحتياطية من حين لآخر للتأكد من أنها جيدة أحتفظ بنسخ احتياطية يومية، ثم أحتفظ بـ “لقطات” شهرية أيضًا. أقدم نسخة احتياطية لم تكن تحتوي على قاعدة بيانات تالفة كانت عمرها 4 أشهر