From 38e2dd7a63ffe9885621c001ee5b8ce6f105eebb Mon Sep 17 00:00:00 2001 From: Christophe Siraut Date: Wed, 22 Nov 2017 17:38:33 +0100 Subject: [PATCH] when dropping schemas, start with dropping tables to avoid reaching maximum lock per transaction (closes: #20190) --- wcs_olap/feeder.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wcs_olap/feeder.py b/wcs_olap/feeder.py index c39bf40..da58076 100644 --- a/wcs_olap/feeder.py +++ b/wcs_olap/feeder.py @@ -272,10 +272,16 @@ class WcsOlapFeeder(object): self.logger.debug('SQL: %s VARSLIST: %s', sql, varslist) self.cur.executemany(sql, varslist) + def drop_schema(self, schema): + self.logger.debug('dropping schema %s', schema) + self.ex('''SELECT 'DROP TABLE "' || tablename || '" CASCADE;' + FROM pg_tables WHERE schemaname = '%s';''' % schema) + self.ex('DROP SCHEMA IF EXISTS %s CASCADE' % schema) + tables = list(self.cur.fetchall()): + def do_schema(self): self.ex('SET search_path = public') - self.logger.debug('dropping schema %s', self.schema + '_temp') - self.ex('DROP SCHEMA IF EXISTS {schema_temp} CASCADE') + self.drop_schema(self.schema + '_temp') self.logger.debug('creating schema %s', self.schema) self.ex('CREATE SCHEMA {schema_temp}') self.ex('SET search_path = {schema_temp},public') @@ -451,7 +457,7 @@ CREATE TABLE public.dates AS (SELECT if self.do_feed: if not self.fake: self.logger.debug('dropping schema %s', self.schema) - self.ex('DROP SCHEMA IF EXISTS {schema} CASCADE') + self.drop_schema(self.schema) self.logger.debug('dropping schema %s to %s', self.schema + '_temp', self.schema) self.ex('ALTER SCHEMA {schema_temp} RENAME TO {schema}') -- 2.11.0