From f2c522ce7a04c7043d9a8394d96cef025c8d28aa Mon Sep 17 00:00:00 2001 From: Arjun Rao Date: Thu, 8 May 2025 11:00:56 +1000 Subject: [PATCH 1/4] Allow max_connections to be configured in postgres --- config.ini.example | 1 + lightrag/kg/postgres_impl.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config.ini.example b/config.ini.example index 5ff7cfbb..c6edcb60 100644 --- a/config.ini.example +++ b/config.ini.example @@ -20,3 +20,4 @@ user = your_username password = your_password database = your_database workspace = default # 可选,默认为default +max_connections = 12 \ No newline at end of file diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index cb302e8c..c71bc867 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -54,7 +54,7 @@ class PostgreSQLDB: self.password = config.get("password", None) self.database = config.get("database", "postgres") self.workspace = config.get("workspace", "default") - self.max = 12 + self.max = config.get("max_connections", 12) self.increment = 1 self.pool: Pool | None = None @@ -250,6 +250,10 @@ class ClientManager: "POSTGRES_WORKSPACE", config.get("postgres", "workspace", fallback="default"), ), + "max_connections": os.environ.get( + "POSTGRES_MAX_CONNECTIONS", + config.get("postgres", "max_connections", fallback=12), + ), } @classmethod From 6ebd76d5da03fbe86b04efbc8c7183a7aefc003c Mon Sep 17 00:00:00 2001 From: Arjun Rao Date: Fri, 9 May 2025 04:22:46 +1000 Subject: [PATCH 2/4] bugfix: convert config val to int --- lightrag/kg/postgres_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index c71bc867..e2612dc6 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -54,7 +54,7 @@ class PostgreSQLDB: self.password = config.get("password", None) self.database = config.get("database", "postgres") self.workspace = config.get("workspace", "default") - self.max = config.get("max_connections", 12) + self.max = int(config.get("max_connections", 12)) self.increment = 1 self.pool: Pool | None = None From c0f9e78949f1e949555e80f9901569378282481f Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 9 May 2025 14:17:11 +0800 Subject: [PATCH 3/4] Fix linting --- config.ini.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.ini.example b/config.ini.example index c6edcb60..63d9c2c0 100644 --- a/config.ini.example +++ b/config.ini.example @@ -20,4 +20,4 @@ user = your_username password = your_password database = your_database workspace = default # 可选,默认为default -max_connections = 12 \ No newline at end of file +max_connections = 12 From 9d0f09a183ed8a86277d97a0a97f011a226a7636 Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 9 May 2025 14:19:42 +0800 Subject: [PATCH 4/4] Update env sample file --- env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/env.example b/env.example index cb6b8e28..d16b5e8a 100644 --- a/env.example +++ b/env.example @@ -131,6 +131,7 @@ POSTGRES_PORT=5432 POSTGRES_USER=your_username POSTGRES_PASSWORD='your_password' POSTGRES_DATABASE=your_database +POSTGRES_MAX_CONNECTIONS=12 ### separating all data from difference Lightrag instances(deprecating) # POSTGRES_WORKSPACE=default