From 9d4e45eb9a3f847f00f3b09d85d7b7ed46529ba9 Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Fri, 25 Mar 2011 16:11:46 +0100 Subject: [PATCH] Provide a way to set Pg's work_mem from dak. Signed-off-by: Torsten Werner --- daklib/contents.py | 4 ++-- daklib/dbconn.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/daklib/contents.py b/daklib/contents.py index f3077aab..449fb88e 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -285,7 +285,7 @@ def binary_helper(suite_id, arch_id, overridetype_id, component_id = None): This function is called in a new subprocess and multiprocessing wants a top level function. ''' - session = DBConn().session() + session = DBConn().session(work_mem = 1000) suite = Suite.get(suite_id, session) architecture = Architecture.get(arch_id, session) overridetype = OverrideType.get(overridetype_id, session) @@ -304,7 +304,7 @@ def source_helper(suite_id, component_id): This function is called in a new subprocess and multiprocessing wants a top level function. ''' - session = DBConn().session() + session = DBConn().session(work_mem = 1000) suite = Suite.get(suite_id, session) component = Component.get(component_id, session) log_message = [suite.suite_name, 'source', component.component_name] diff --git a/daklib/dbconn.py b/daklib/dbconn.py index ae5a9e0d..9c25f670 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -3591,12 +3591,21 @@ class DBConn(object): self.__setupmappers() self.pid = os.getpid() - def session(self): + def session(self, work_mem = 0): + ''' + Returns a new session object. If a work_mem parameter is provided a new + transaction is started and the work_mem parameter is set for this + transaction. The work_mem parameter is measured in MB. A default value + will be used if the parameter is not set. + ''' # reinitialize DBConn in new processes if self.pid != os.getpid(): clear_mappers() self.__createconn() - return self.db_smaker() + session = self.db_smaker() + if work_mem > 0: + session.execute("SET LOCAL work_mem TO '%d MB'" % work_mem) + return session __all__.append('DBConn') -- 2.39.5