config+sqldb: make native SQL query config options configurable
What changed, and why it matters
This commit simply exposes two internal database tuning knobs—batch size and pagination size—for SQLite and Postgres as user-configurable options. It does not change any security behavior, fix a bug, or alter access controls. It is a routine configuration enhancement.
No security action required. Review as normal feature/configuration code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds QueryConfig embedding to SqliteConfig and PostgresConfig, wires those values into DefaultDB(), exposes them in sample-lnd.conf, and updates the native SQL test builder to use the configured queryConfig instead of sqldb.DefaultQueryConfig(). The default values remain MaxBatchSize=250 and MaxPageSize=10000 for both backends. No logic changes affect authentication, authorization, cryptography, network exposure, or data integrity.
Changed components
lncfg/db.gosqldb/config.gosqldb/paginate.gosample-lnd.confconfig_test_native_sql.goInspect captured patch +34 / −6
diff --git a/config_test_native_sql.go b/config_test_native_sql.go
index 92e8353..8ee51d4 100644
--- a/config_test_native_sql.go
+++ b/config_test_native_sql.go
@@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/kvdb"
+ "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/sqldb"
"github.com/lightningnetwork/lnd/sqldb/sqlc"
)
@@ -30,10 +31,15 @@ func (d *DefaultDatabaseBuilder) getGraphStore(baseDB *sqldb.BaseDB,
},
)
+ queryConfig := d.cfg.DB.Sqlite.QueryConfig
+ if d.cfg.DB.Backend == lncfg.PostgresBackend {
+ queryConfig = d.cfg.DB.Postgres.QueryConfig
+ }
+
return graphdb.NewSQLStore(
&graphdb.SQLStoreConfig{
ChainHash: *d.cfg.ActiveNetParams.GenesisHash,
- QueryCfg: sqldb.DefaultQueryConfig(),
+ QueryCfg: &queryConfig,
},
graphExecutor, opts...,
)
diff --git a/lncfg/db.go b/lncfg/db.go
index 3da1f4d..388d518 100644
--- a/lncfg/db.go
+++ b/lncfg/db.go
@@ -115,10 +115,18 @@ func DefaultDB() *DB {
},
Postgres: &sqldb.PostgresConfig{
MaxConnections: defaultPostgresMaxConnections,
+ QueryConfig: sqldb.QueryConfig{
+ MaxBatchSize: 250,
+ MaxPageSize: 10000,
+ },
},
Sqlite: &sqldb.SqliteConfig{
MaxConnections: defaultSqliteMaxConnections,
BusyTimeout: defaultSqliteBusyTimeout,
+ QueryConfig: sqldb.QueryConfig{
+ MaxBatchSize: 250,
+ MaxPageSize: 10000,
+ },
},
UseNativeSQL: false,
SkipNativeSQLMigration: false,
diff --git a/sample-lnd.conf b/sample-lnd.conf
index cba4021..22ffc39 100644
--- a/sample-lnd.conf
+++ b/sample-lnd.conf
@@ -1601,6 +1601,12 @@
; Whether to skip executing schema migrations.
; db.postgres.skipmigrations=false
+; The maximum number of elements to use in a native-SQL batch query IN clause.
+; db.postgres.query.max-batch-size=5000
+
+; The maximum number of records to fetch at a time in a paginated query during
+; native-SQL calls.
+; db.postgres.query.max-page-size=10500
[sqlite]
@@ -1617,6 +1623,13 @@
; The maximum amount of time to wait to execute a query if the db is locked.
; db.sqlite.busytimeout=5s
+; The maximum number of elements to use in a native-SQL batch query IN clause.
+; db.sqlite.query.max-batch-size=250
+
+; The maximum number of records to fetch at a time in a paginated query during
+; native-SQL calls.
+; db.sqlite.query.max-page-size=100
+
; Raw pragma option pairs to be used when opening the sqlite db. The flag
; can be specified multiple times to set multiple options.
; Default:
diff --git a/sqldb/config.go b/sqldb/config.go
index 24e58b4..c5f49a9 100644
--- a/sqldb/config.go
+++ b/sqldb/config.go
@@ -28,6 +28,7 @@ type SqliteConfig struct {
MaxConnections int `long:"maxconnections" description:"The maximum number of open connections to the database. Set to zero for unlimited."`
PragmaOptions []string `long:"pragmaoptions" description:"A list of pragma options to set on a database connection. For example, 'auto_vacuum=incremental'. Note that the flag must be specified multiple times if multiple options are to be set."`
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
+ QueryConfig `group:"query" namespace:"query"`
}
// PostgresConfig holds the postgres database configuration.
@@ -38,6 +39,7 @@ type PostgresConfig struct {
Timeout time.Duration `long:"timeout" description:"Database connection timeout. Set to zero to disable."`
MaxConnections int `long:"maxconnections" description:"The maximum number of open connections to the database. Set to zero for unlimited."`
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
+ QueryConfig `group:"query" namespace:"query"`
}
func (p *PostgresConfig) Validate() error {
diff --git a/sqldb/paginate.go b/sqldb/paginate.go
index 2a51218..d810325 100644
--- a/sqldb/paginate.go
+++ b/sqldb/paginate.go
@@ -6,20 +6,19 @@ import (
)
// QueryConfig holds configuration values for SQL queries.
+//
+//nolint:ll
type QueryConfig struct {
// MaxBatchSize is the maximum number of items included in a batch
// query IN clauses list.
- MaxBatchSize int
+ MaxBatchSize int `long:"max-batch-size" description:"The maximum number of items to include in a batch query IN clause. This is used for queries that fetch results based on a list of identifiers."`
// MaxPageSize is the maximum number of items returned in a single page
// of results. This is used for paginated queries.
- MaxPageSize int32
+ MaxPageSize int32 `long:"max-page-size" description:"The maximum number of items to return in a single page of results. This is used for paginated queries."`
}
// DefaultQueryConfig returns a default configuration for SQL queries.
-//
-// TODO(elle): make configurable & have different defaults for SQLite and
-// Postgres.
func DefaultQueryConfig() *QueryConfig {
return &QueryConfig{
MaxBatchSize: 250,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.