Skip to content

Conversation

staticlibs
Copy link
Collaborator

This is a backport of the PR #238 to v1.3-ossivalis stable branch.

Currently when the last connection to a DB instance is closed, this DB instance is destroyed.

This is not a big problem with file DBs, where subsequent connection from the same process can just re-open the file (though some state, like attached DBs is lost), but this is a problem with tagged in-memory DBs (jdbc:duckdb:memory:tag1 URLs), where all DB state is lost when the DB is closed.

This does not apply to untagged :memory: DBs, which are private to a single connection.

This change adds new connection property jdbc_pin_db (boolean, false by default), when it is enabled, then the DB is pinned and is kept alive in-memory even after the last connection to it is closed.

DuckDBDriver.releaseDB(url) method is added to allow client code to release such DBs.

DBs that are left pinned are released automatically on JVM shutdown.

Testing: new test added.

This is a backport of the PR duckdb#238 to `v1.3-ossivalis` stable branch.

Currently when the last connection to a DB instance is closed, this DB
instance is destroyed.

This is not a big problem with file DBs, where subsequent connection
from the same process can just re-open the file (though some state,
like attached DBs is lost), but this is a problem with tagged in-memory
DBs (`jdbc:duckdb:memory:tag1` URLs), where all DB state is lost when
the DB is closed.

This does not apply to untagged `:memory:` DBs, which are private to a
single connection.

This change adds new connection property `jdbc_pin_db` (boolean,
`false` by default), when it is enabled, then the DB is pinned and is
kept alive in-memory even after the last connection to it is closed.

`DuckDBDriver.releaseDB(url)` method is added to allow client code to
release such DBs.

DBs that are left pinned are released automatically on JVM shutdown.

Testing: new test added.
@staticlibs staticlibs merged commit 471dd86 into duckdb:v1.3-ossivalis Jun 16, 2025
@staticlibs staticlibs deleted the persist_db_13 branch June 16, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant