Merged
Conversation
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
added a commit
to staticlibs/duckdb-java
that referenced
this pull request
Jun 16, 2025
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
added a commit
that referenced
this pull request
Jun 16, 2025
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 was referenced Jun 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:tag1URLs), 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,falseby 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.
edit: added shutdown hook note.