简体   繁体   English

使用检查点时 sqlite3 未知数据库模式?

[英]sqlite3 unknown database schema when using a checkpoint?

I am getting:我正进入(状态:

sqlite3.OperationalError: unknown database schema sqlite3.OperationalError:未知的数据库架构

conn = sqlite3.connect('tick.db', detect_types=sqlite3.PARSE_DECLTYPES, timeout=20,isolation_level=None)
# conn1 = sqlite3.connect('nifty_tick.db', detect_types=sqlite3.PARSE_DECLTYPES, timeout=20,isolation_level=None)

c = conn.cursor()
# c1 = conn1.cursor()

c.execute('PRAGMA journal_mode=wal')

def tick_entry1(inst,timestamp,ltp, bid, ask):
    if inst == 12335874:
        c.execute('INSERT INTO niftyfut (timestamp, close, bid, ask) VALUES (?,?,?,?)',
                  (timestamp, ltp, bid, ask))

def on_ticks(ws, ticks):
    global c, conn
    for t in ticks:
        if t['instrument_token'] == 12335874:
            timestamp = t['timestamp']
            ltp = t['last_price']
            inst = t['instrument_token']

            try:
                tick_entry1(inst,timestamp,ltp)
            except:
                # print('problem with db')
                pass
    c.execute('PRAGMA schema.wal_checkpoint(FULL);')

I have tried:我努力了:

c.execute('PRAGMA schema.wal_checkpoint(FULL);')

and

c.execute('PRAGMA schema.wal_checkpoint(FULL)')

Edit编辑

I just tried:我刚试过:

c.execute('PRAGMA wal_checkpoint(FULL)')

It seems to work.它似乎工作。 Now wondering if the following should be executed at the start.:现在想知道是否应该在开始时执行以下操作:

c.execute("PRAGMA wal_autocheckpoint = 0")

The message is saying that no database has a schema named schema.该消息是说没有数据库具有名为 schema 的模式。

In the documentation the schema is italic, which indicates that it is symbolic rather than an actual value and would be replaced with an appropriate value, the value is used to distinguish between attached databases.在文档中,模式是斜体的,表示它是符号而不是实际值,并且将被替换为适当的值,该值用于区分附加的数据库。

eg if you used例如,如果您使用

ATTACH DATABASE the_database_path AS database2 /*<<<<<<<<<< THE SCHEMA is database2 */; 

then you could use那么你可以使用

PRAGMA database2.wal_checkpoint(FULL); 

to checkpoint the attached database.检查附加的数据库。

The initial database's schema is main but isn't required as it's the default if no schema is supplied.初始数据库的模式是主要的,但不是必需的,因为如果没有提供模式,它是默认值。

Hence why c.execute('PRAGMA wal_checkpoint(FULL)') worked (as would c.execute('PRAGMA main.wal_checkpoint(FULL)') ).因此,为什么c.execute('PRAGMA wal_checkpoint(FULL)')有效(就像c.execute('PRAGMA main.wal_checkpoint(FULL)') )。 ie the are effectively the same.即实际上是相同的。

If you use c.execute("PRAGMA wal_autocheckpoint = 0") then you will have to manage all the checkpointing as auto-checkpointing will be turned off (note that closing all the database connections checkpoints).如果您使用c.execute("PRAGMA wal_autocheckpoint = 0")那么您将必须管理所有检查点,因为自动检查点将被关闭(注意关闭所有数据库连接检查点)。

You may wish to consider:-您不妨考虑:-

Disabling the automatic checkpoint mechanism.禁用自动检查点机制。 In its default configuration, SQLite will checkpoint the WAL file at the conclusion of any transaction when the WAL file is more than 1000 pages long.在其默认配置中,当 WAL 文件超过 1000 页时,SQLite 将在任何事务结束时检查 WAL 文件。 However, compile-time and run-time options exist that can disable or defer this automatic checkpoint.但是,存在可以禁用或延迟此自动检查点的编译时和运行时选项。 If an application disables the automatic checkpoint, then there is nothing to prevent the WAL file from growing excessively.如果应用程序禁用了自动检查点,则没有什么可以阻止 WAL 文件过度增长。 Write-Ahead Logging - 6. Avoiding Excessively Large WAL Files预写式日志记录 - 6. 避免过大的 WAL 文件

I'd suggest not using PRAGMA wal_autocheckpoint = 0 autocheckpointing does not hinder forced checkpointing, other than if a forced checkpoint happens after an auto checkpoint (and all pages are written) and nothing has been updated then it will do nothing (gracefully), otherwise more pages would be written to the database file.我建议不要使用PRAGMA wal_autocheckpoint = 0自动检查点不会妨碍强制检查点,除非强制检查点发生在自动检查点之后(并且所有页面都被写入)并且没有任何更新,那么它将什么都不做(优雅地),否则更多页面将写入数据库文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM