Graphite SQLite3 DatabaseError:数据库已锁定

Graphite SQLite3 DatabaseError:数据库已锁定

在 CentOS 6.4 上使用 Apache mod_wsgi 通过库存 graphite-web rpm 进行 Graphite 的初始安装和设置时,我得到了以下信息“数据库错误:数据库已被锁定“ 信息:

mod_wsgi (pid=9009): Target WSGI script '/usr/share/graphite/graphite-web.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=9009): Exception occurred processing WSGI script '/usr/share/graphite/graphite-web.wsgi'.
Traceback (most recent call last):
  File "/usr/share/graphite/graphite-web.wsgi", line 16, in <module>
    import graphite.metrics.search
  File "/usr/lib/python2.6/site-packages/graphite/metrics/search.py", line 6, in <module>
    from graphite.storage import is_pattern, match_entries
  File "/usr/lib/python2.6/site-packages/graphite/storage.py", line 7, in <module>
    from graphite.remote_storage import RemoteStore
  File "/usr/lib/python2.6/site-packages/graphite/remote_storage.py", line 8, in <module>
    from graphite.util import unpickle
  File "/usr/lib/python2.6/site-packages/graphite/util.py", line 82, in <module>
    defaultProfile.save()
  File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 553, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 1436, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 791, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: database is locked

我已经验证了数据库文件(“/var/lib/graphite-web/graphite.db“)可通过阿帕奇拥有httpd过程。

另外,我尝试重新启动httpd碳缓存提及的流程github 上的这个帖子

的列表lsof显示以下内容:

# lsof | grep graphite.db
httpd      9006    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9007    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9008    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9008    apache   22u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9009    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9009    apache   22u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9010    apache   17ur     REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9010    apache   18u      REG              253,2      512     526174 /var/lib/graphite-web/graphite.db-journal
httpd      9010    apache   24ur     REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9011    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9012    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db
httpd      9013    apache   17u      REG              253,2    69632     526186 /var/lib/graphite-web/graphite.db

在我看来,这一定与httpd,但我没有得到任何进展。

答案1

我继续尝试,发现重新启动 httpd神奇地工作了。

但是,我之前尝试通过 httpd 重启修复错误的十几次尝试都失败了,这一点仍不清楚。我以为这可能是启动 apache+mod_wsgi 和过早访问 graphite-web 页面之间的竞争条件,但在后续重启中,我无法重现锁定。在各种状态下(apache 正在运行、apache 关闭、数据库由 root 拥有等)的进一步尝试均未重现错误。事实上,在这个阶段,我可以删除 graphite.db,使用“syncdb”重新初始化,并成功查看网页,而无需重启 httpd。graphite-web 页面在所有情况下都运行良好。

如果你遇到这个问题,我的建议是:

  1. 关闭httpd或apache进程。
  2. 删除“graphite.db”文件。
  3. 重新运行 syncdb 进程作为“apache”用户(或拥有 httpd 进程的用户)。
  4. 启动httpd进程。
  5. 等待 60 秒以上再访问网页,然后尝试。

这可能相当于“挥舞死鸡”,但这就是我摆脱困境的方法。欢迎在这里发布你的经验。

相关内容