MCPcopy Create free account
hub / github.com/PostHog/duckgres / openBaseDB

Function openBaseDB

server/server.go:839–866  ·  view source on GitHub ↗

openBaseDB creates and configures a DuckDB connection with threads, memory limit, temp directory, extensions, and cache_httpfs settings. This shared setup is used by both regular and passthrough connections. When DataDir is set, the database is file-backed at / .duckdb. DuckDB mem

(cfg Config, username string)

Source from the content-addressed store, hash-verified

837 entry.refs++
838 return entry.db, nil
839 }
840
841 var db *sql.DB
842 var err error
843 if passthrough {
844 db, err = CreatePassthroughDBConnection(s.cfg, s.duckLakeSem, username, processStartTime, processVersion)
845 } else {
846 db, err = CreateDBConnection(s.cfg, s.duckLakeSem, username, processStartTime, processVersion)
847 }
848 if err != nil {
849 return nil, err
850 }
851
852 // openBaseDB sets MaxOpenConns(1) for single-session use; override for shared pool.
853 db.SetMaxOpenConns(0) // unlimited
854 db.SetMaxIdleConns(4)
855
856 stopRefresh := StartCredentialRefresh(db, s.cfg.DuckLake)
857
858 s.fileDBs[username] = &fileDBEntry{
859 db: db,
860 refs: 1,
861 stopRefresh: stopRefresh,
862 }
863 return db, nil
864}
865
866// releaseFileDB decrements the ref count for a user's shared DB.
867// When the last reference is released, the DB is closed and removed from the pool.
868func (s *Server) releaseFileDB(username string) {
869 s.fileDBsMu.Lock()

Calls 4

DuckDBDSNFunction · 0.85
ConfigureMainDBFunction · 0.85
CloseMethod · 0.65
OpenMethod · 0.45