feeder: drop old schema sequentially (#42322)

This commit is contained in:
Serghei Mihai 2020-04-30 12:13:09 +02:00
parent 31540a886f
commit c68304bf96
1 changed files with 5 additions and 4 deletions

View File

@ -316,19 +316,19 @@ class WcsOlapFeeder(object):
def do_schema(self):
self.ex('SET search_path = public')
self.logger.debug('dropping schema %s', self.schema + '_temp')
self.drop_tables_sequencially()
self.drop_tables_sequencially(self.schema + '_temp')
self.ex('DROP SCHEMA IF EXISTS {schema_temp} CASCADE')
self.logger.debug('creating schema %s', self.schema)
self.ex('CREATE SCHEMA {schema_temp}')
self.ex('SET search_path = {schema_temp},public')
def drop_tables_sequencially(self):
def drop_tables_sequencially(self, schema):
"""
Drop tables one by one in order to avoid reaching max_locks_per_transaction
"""
self.ex("SELECT tablename FROM pg_tables WHERE schemaname = '{schema_temp}'")
self.ex("SELECT tablename FROM pg_tables WHERE schemaname = '%s'" % schema)
for table in self.cur.fetchall():
tablename = '%s%s.%s' % (self.schema, '_temp', table[0])
tablename = '%s.%s' % (schema, table[0])
self.ex('DROP TABLE IF EXISTS %s CASCADE;' % tablename)
def do_dates_table(self):
@ -568,6 +568,7 @@ CREATE TABLE public.dates AS (SELECT
if self.do_feed:
if not self.fake:
self.logger.debug('dropping schema %s', self.schema)
self.drop_tables_sequencially(self.schema)
self.ex('DROP SCHEMA IF EXISTS {schema} CASCADE')
self.logger.debug('dropping schema %s to %s', self.schema + '_temp', self.schema)
self.ex('ALTER SCHEMA {schema_temp} RENAME TO {schema}')