TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to Corrupt an SQLite Database File

225 点作者 segfaultbuserr大约 3 年前

13 条评论

zvrba大约 3 年前
I read this as a damnation of POSIX filesystem semantics. File descriptors getting reused, insane locking semantics on close, allowing you to delete an open file and providing no means to prevent it, fork causing problems, unspecified behavior of sync() (is it barrier or &quot;full&quot; sync).<p>Though: Multiple copies of SQLite linked into the same application. Weird and rare scenario, but why not keep the global list of open sqlite files in a global shared memory segment?
评论 #31214647 未加载
评论 #31214611 未加载
评论 #31215649 未加载
评论 #31216168 未加载
评论 #31214568 未加载
评论 #31232462 未加载
评论 #31215358 未加载
评论 #31214567 未加载
andix大约 3 年前
That one is easier as you think: 2.2.1. Multiple copies of SQLite linked into the same application<p>I used two different C# libraries to access the same database. And under the hood, they both used a different SQLite library, with different native SQLite builds (of the same version though).<p>Took me some time to figure out…
评论 #31216282 未加载
zabzonk大约 3 年前
Really, the only way to prevent corruption of a SQL (or any other kind of) database is to have a server process manage all accesses to the database storage. And even then....<p>SQLite is great, but I would not use it in a multi-machine, multi-processing environment.
评论 #31215193 未加载
评论 #31215210 未加载
andai大约 3 年前
Doesn&#x27;t point 1.2 (backing up the file in the middle of a transaction) contradict the part above about how SQLite is resistant to power failures and simply rolls back the incomplete transaction? You&#x27;d just end up with a db outdated by 1 transaction, which is fine for a backup anyway.
评论 #31217884 未加载
评论 #31232603 未加载
vlovich123大约 3 年前
Does Linux yet have a config option to randomize the file descriptor number it hands out? So many times have I been bitten by silent use after close of these FDs.
评论 #31217679 未加载
nrjames大约 3 年前
During some low-impact exploratory work on my local machine recently, I launched a Jupyter Lab notebook that connected to a SQLite db that was in a directory MS One Drive had claimed. The sync processes had nuked the db within five minutes. I was able to recreate the db easily, from csv files. Important lesson learned!
评论 #31218644 未加载
TekMol大约 3 年前
&quot;Backup or restore while a transaction is active&quot;<p>Is it possible to turn off transactions alltogether in SQLite? So they function like a MyIsam table in MySql or a Aria table in MariaDB?<p>I have crunched many billions of queries over the last years in MySql and then MariaDB. I like MariaDB because it offers tables that are way faster due to no transaction overhead.<p>I know this goes against the popular opinion to use transactional tables for everything. But depending on the task at hand, the performance gain can be very well worth turning transactions off.<p>I consider trying SQLite. But if you cannot switch off transactions, performance will probably not be up to par.
评论 #31214805 未加载
评论 #31214715 未加载
评论 #31214694 未加载
评论 #31214712 未加载
评论 #31217623 未加载
martincmartin大约 3 年前
<i>&quot;Unfortunately, most consumer-grade mass storage devices lie about syncing. Disk drives will report that content is safely on persistent media as soon as it reaches the track buffer and before actually being written to oxide. This makes the disk drives seem to operate faster (which is vitally important to the manufacturer so that they can show good benchmark numbers in trade magazines).&quot;</i><p>Is this also true of SSDs?
评论 #31216466 未加载
评论 #31220059 未加载
评论 #31216439 未加载
评论 #31217492 未加载
评论 #31216671 未加载
davepeck大约 3 年前
I recently saw SQLite used (and written to) in a Docker container, with the database file on a mounted volume.<p>That made me nervous!<p>I don&#x27;t know enough about how Docker implements volumes under the hood to know how likely (or not) it is to break filesystem behavior that SQLite depends on for its transactional guarantees.<p>Perhaps someone here does?
评论 #31216074 未加载
评论 #31216191 未加载
评论 #31222364 未加载
评论 #31217364 未加载
thrower123大约 3 年前
Accidentally check it into git on a multi-developer team...
layer8大约 3 年前
Do I understand correctly that “<i>2.2.1. Multiple copies of SQLite linked into the same application</i>” is only a problem if more than one copy accesses the same database file?
div3rs3大约 3 年前
An Es Kew El or A Seakewl Lite
评论 #31216344 未加载
评论 #31219855 未加载
评论 #31215605 未加载
评论 #31215209 未加载
评论 #31216849 未加载
评论 #31232655 未加载
test123afds34大约 3 年前
interesting!