記一次python操作mongodb錯誤的經歷


首先,看一下mongodb錯誤日志

2020-10-20T19:25:35.349+0800 E STORAGE  [conn1310] WiredTiger error (1) [1603193135:349907][3052:0x7f413cc4d700], file:index-1-2989994858051104788.wt, WT_SESSION.open_cursor: __posix_open_file, 715: /mnt/data/mongo/index-1-2989994858051104788.wt: handle-open: open: Operation not permitted Raw: [1603193135:349907][3052:0x7f413cc4d700], file:index-1-2989994858051104788.wt, WT_SESSION.open_cursor: __posix_open_file, 715: /mnt/data/mongo/index-1-2989994858051104788.wt: handle-open: open: Operation not permitted
2020-10-20T19:25:35.349+0800 E STORAGE  [conn1310] Failed to open a WiredTiger cursor: table:index-1-2989994858051104788
2020-10-20T19:25:35.349+0800 E STORAGE  [conn1310] This may be due to data corruption. Please read the documentation for starting MongoDB with --repair here: http://dochub.mongodb.org/core/repair
2020-10-20T19:25:35.349+0800 F -        [conn1310] Fatal Assertion 50882 at src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp 143

測試環境沒有問題,開發環境沒有問題,但生產就是會報以上錯誤,並且導致數據庫服務也停止了,剛開始以為是因為存儲數據量過大引起的,但后來進行了python接口訪問速率限制,仍然不行。

查看日志后發現主要是WiredTiger權限不足導致的,於是用chmod -R 777 WiredTiger提升WiredTiger權限,提升權限后仍然報錯。

繼續看mongodb文件夾中的數據庫文件 index-1-2989994858051104788,發現該文件的用戶組和用戶均為root,於是想起來可能原因是因為數據庫中的某些表索引是通過root用戶連接mongodb手動創建的

-rwxrwxrwx 1 root root  529M Oct 20 18:45 index-0-2989994858051104788.wt
-rwxrwxrwx 1 mongod mongod  543M Oct 21 13:48 index-0--6116263748539842893.wt
-rwxrwxrwx 1 mongod mongod  4.0G Oct 21 13:48 index-0-6559876251215556882.wt
-rwxrwxrwx 1 mongod mongod   16K Dec  7  2019 index-0-9055286318983588419.wt

解決辦法來了,修改索引文件的所有者

sudo chown mongod:mongod index-0-2989994858051104788.wt

網上很多人說的,通過刪除mongod.lock,WiredTiger,journal及pid文件的方法也試過,都未解決,最后發現錯誤往往都是自己的一些不規范的操作造成的。

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM