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

Database.prepare without .finalize results in left-over wal file #2537

Closed
betamos opened this issue Apr 3, 2023 · 3 comments · Fixed by #10262
Closed

Database.prepare without .finalize results in left-over wal file #2537

betamos opened this issue Apr 3, 2023 · 3 comments · Fixed by #10262
Labels
bug Something isn't working bun:sqlite Something to do with bun:sqlite

Comments

@betamos
Copy link

betamos commented Apr 3, 2023

What version of Bun is running?

0.5.8

What platform is your computer?

Linux 5.15.0-69-generic x86_64 x86_64

What steps can reproduce the bug?

Run this bun program at least twice:

import { Database } from "bun:sqlite";
const db = new Database("dirty.sqlite", { create:true })
const prep = db.prepare(`SELECT "hello"`)
db.exec("pragma journal_mode = wal")

// NOTE: If this line is uncommented, the `shm` and `wal` files are removed on exit
// prep.finalize()

db.close()

What is the expected behavior?

Normally, the shm and wal files are cleaned up on close. I suppose that's what's expected, but.. if manual finalize is required then it should probably be documented.

What do you see instead?

$ ls | grep dirty
dirty.sqlite
dirty.sqlite-shm
dirty.sqlite-wal

Additional information

No response

@betamos betamos added the bug Something isn't working label Apr 3, 2023
@Electroid Electroid added the bun:sqlite Something to do with bun:sqlite label Apr 3, 2023
@kunokareal
Copy link
Contributor

it looks like calling .finalize() on prep doesn't work if there happened any writes:

import { Database } from 'bun:sqlite'

const db = new Database('test.db')
db.exec('PRAGMA journal_mode = WAL')

// or simply db.exec('CREATE TABLE test (id INTEGER PRIMARY KEY)')
const prep = db.prepare('CREATE TABLE test (id INTEGER PRIMARY KEY)')
prep.run()
prep.finalize()

db.close()
❱ bun test.js
❱ ls test.db*                                                            
test.db     test.db-shm test.db-wal

and in the code in the op, the .finalize() call doesn't seem to matter either anymore, btw.
has something changed in the last year?

@doroved
Copy link

doroved commented Apr 13, 2024

and in the code in the op, the .finalize() call doesn't seem to matter either anymore, btw.
has something changed in the last year?

I too have encountered this problem and wal_checkpoint doesn't help.

process.on('SIGINT', (code) => {
  db.exec('PRAGMA wal_checkpoint(TRUNCATE);')
  db.close()
  process.exit(1)
})

@doroved
Copy link

doroved commented Apr 13, 2024

It might be worth checking this information out
image

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

Successfully merging a pull request may close this issue.

4 participants