Skip to content

Conversation

@ziggie1984
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @ziggie1984, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the default maximum connection settings for both PostgreSQL and SQLite databases across the application. The changes aim to improve database resource management and stability by setting more appropriate default limits, particularly considering the specific characteristics of each database system, such as SQLite's single-writer model, and updating test configurations to match these new defaults.

Highlights

  • Reduced PostgreSQL Max Connections: The default maximum connections for PostgreSQL databases have been lowered from 50 (or 25 in some contexts) to 10. This aims to optimize resource usage and prevent potential overload, ensuring better stability under various loads.
  • Optimized SQLite Max Connections: The default maximum connections for SQLite databases have been set to 2. This is a deliberate choice to accommodate SQLite's single-writer constraint while still allowing for concurrent reads, thereby minimizing write contention and improving performance.
  • PostgreSQL Test Configuration Enhancements: Test fixtures for PostgreSQL now initialize sqlbase with 10 connections per database and include a new max_pred_locks_per_transaction setting of 256 for both embedded and Dockerized instances, enhancing test environment consistency and behavior.
  • Configuration File Update: The sample-lnd.conf file has been updated to reflect the new default PostgreSQL maximum connection value, providing accurate guidance for users configuring their database settings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adjusts the default maximum database connections for SQL backends, which is a sensible change to optimize resource usage and prevent contention issues. The changes are consistent across the codebase. I've included a few suggestions to refactor duplicated constants for better maintainability.

Comment on lines +10 to +22
// defaultMaxConnsPostgres is the number of permitted active and idle
// connections. We want to limit this so it isn't unlimited. We use the
// same value for the number of idle connections as, this can speed up
// queries given a new connection doesn't need to be established each
// time.
defaultMaxConns = 25
defaultMaxConnsPostgres = 10

// defaultMaxConnsSqlite is the number of permitted active and idle
// connections. We want to limit this to 2 because SQLite allows for
// concurrent reads however writers are limited to 1 so we select 2 here
// to allow for concurrent reads but keep the number of connections low
// to avoid write contention.
defaultMaxConnsSqlite = 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid duplicating these default values in the lncfg package, consider exporting these constants (e.g., DefaultMaxConnsPostgres, DefaultMaxConnsSqlite). The lncfg package can then reference them directly, ensuring consistency and making future changes easier. This change should be propagated to sqldb/postgres.go and sqldb/sqlite.go as well.

Suggested change
// defaultMaxConnsPostgres is the number of permitted active and idle
// connections. We want to limit this so it isn't unlimited. We use the
// same value for the number of idle connections as, this can speed up
// queries given a new connection doesn't need to be established each
// time.
defaultMaxConns = 25
defaultMaxConnsPostgres = 10
// defaultMaxConnsSqlite is the number of permitted active and idle
// connections. We want to limit this to 2 because SQLite allows for
// concurrent reads however writers are limited to 1 so we select 2 here
// to allow for concurrent reads but keep the number of connections low
// to avoid write contention.
defaultMaxConnsSqlite = 2
// DefaultMaxConnsPostgres is the number of permitted active and idle
// connections. We want to limit this so it isn't unlimited. We use the
// same value for the number of idle connections as, this can speed up
// queries given a new connection doesn't need to be established each
// time.
DefaultMaxConnsPostgres = 10
// DefaultMaxConnsSqlite is the number of permitted active and idle
// connections. We want to limit this to 2 because SQLite allows for
// concurrent reads however writers are limited to 1 so we select 2 here
// to allow for concurrent reads but keep the number of connections low
// to avoid write contention.
DefaultMaxConnsSqlite = 2

}

maxConns := defaultMaxConns
maxConns := defaultMaxConnsPostgres

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To be consistent with exporting the default values from sqldb/config.go, this should use the exported constant.

Suggested change
maxConns := defaultMaxConnsPostgres
maxConns := DefaultMaxConnsPostgres


db.SetMaxOpenConns(defaultMaxConns)
db.SetMaxIdleConns(defaultMaxConns)
maxConns := defaultMaxConnsSqlite

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To be consistent with exporting the default values from sqldb/config.go, this should use the exported constant.

Suggested change
maxConns := defaultMaxConnsSqlite
maxConns := DefaultMaxConnsSqlite

Comment on lines +42 to 43
defaultPostgresMaxConnections = 10
defaultSqliteMaxConnections = 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid duplication and ensure consistency, these default values should be sourced from the sqldb package where they are also defined.

Suggested change
defaultPostgresMaxConnections = 10
defaultSqliteMaxConnections = 2
defaultPostgresMaxConnections = sqldb.DefaultMaxConnsPostgres
defaultSqliteMaxConnections = sqldb.DefaultMaxConnsSqlite

@ziggie1984 ziggie1984 changed the title multi: change sql db default max connection defaults multi: change sql db default max connection Dec 5, 2025
@ziggie1984 ziggie1984 changed the title multi: change sql db default max connection multi: change sql db default max connections Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant