Projet

Général

Profil

0001-when-dropping-schemas-start-with-dropping-tables-to-.patch

Christophe Siraut, 22 novembre 2017 17:42

Télécharger (1,92 ko)

Voir les différences:

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(-)
wcs_olap/feeder.py
272 272
        self.logger.debug('SQL: %s VARSLIST: %s', sql, varslist)
273 273
        self.cur.executemany(sql, varslist)
274 274

  
275
    def drop_schema(self, schema):
276
        self.logger.debug('dropping schema %s', schema)
277
        self.ex('''SELECT 'DROP TABLE "' || tablename || '" CASCADE;'
278
                   FROM  pg_tables WHERE schemaname = '%s';''' % schema)
279
        self.ex('DROP SCHEMA IF EXISTS %s CASCADE' % schema)
280
        tables = list(self.cur.fetchall()):
281

  
275 282
    def do_schema(self):
276 283
        self.ex('SET search_path = public')
277
        self.logger.debug('dropping schema %s', self.schema + '_temp')
278
        self.ex('DROP SCHEMA IF EXISTS {schema_temp} CASCADE')
284
        self.drop_schema(self.schema + '_temp')
279 285
        self.logger.debug('creating schema %s', self.schema)
280 286
        self.ex('CREATE SCHEMA {schema_temp}')
281 287
        self.ex('SET search_path = {schema_temp},public')
......
451 457
            if self.do_feed:
452 458
                if not self.fake:
453 459
                    self.logger.debug('dropping schema %s', self.schema)
454
                    self.ex('DROP SCHEMA IF EXISTS {schema} CASCADE')
460
                    self.drop_schema(self.schema)
455 461
                    self.logger.debug('dropping schema %s to %s', self.schema + '_temp', self.schema)
456 462
                    self.ex('ALTER SCHEMA {schema_temp} RENAME TO {schema}')
457 463

  
458
-