Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库被锁定[BUG] 简洁阐述问题 / Concise description of the issue #4044

Open
LanShanPi opened this issue May 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@LanShanPi
Copy link

无论是创建新的数据库,还是向已经创建的数据库中添加文件,都会出现这个错误:kb_api.py[line:47] - ERROR: OperationalError: 创建知识库出错: (sqlite3.OperationalError) database is locked

@LanShanPi LanShanPi added the bug Something isn't working label May 20, 2024
@hetaoist
Copy link

hetaoist commented Jun 12, 2024

遇到同样的问题,偶尔出现,日志如下:

2024-06-12T09:46:22.166700+0800 @@@text_splitter: RecursiveCharacterTextSplitter, language_type: java
2024-06-12 09:46:27.732 | ERROR    | server.knowledge_base.kb_service.base:add_doc:142 - OperationalError | add_doc error info: (sqlite3.OperationalError) database is locked
(Background on this error at: https://sqlalche.me/e/20/e3q8)
2024-06-12T09:46:27.732054+0800 OperationalError | add_doc error info: (sqlite3.OperationalError) database is locked
(Background on this error at: https://sqlalche.me/e/20/e3q8)

更新一下,也许可以参考:https://stackoverflow.com/questions/2740806/python-sqlite-database-is-locked 解决,如下:
server/knowledge_base/migrate.py

    try:
        # con = sql.connect(sqlite_path)
        # 尝试增加等待时间解决bug: (sqlite3.OperationalError) database is locked
        con = sql.connect(sqlite_path, timeout=10)
        con.row_factory = sql.Row
        cur = con.cursor()
        tables = [x["name"] for x in cur.execute("select name from sqlite_master where type='table'").fetchall()]
        for model in models:
            table = model.local_table.fullname
            if table not in tables:
                continue
            print(f"processing table: {table}")
            with session_scope() as session:
                for row in cur.execute(f"select * from {table}").fetchall():
                    data = {k: row[k] for k in row.keys() if k in model.columns}
                    if "create_time" in data:
                        data["create_time"] = parse(data["create_time"])
                    pprint(data)
                    session.add(model.class_(**data))
        con.close()
        return True
    except Exception as e:
        print(f"无法读取备份数据库:{sqlite_path}。错误信息:{e}")
        return False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants