Commit 010be26a authored by Andreas Tille's avatar Andreas Tille
Browse files

New upstream version 22.0

parent 4fa74776
Loading
Loading
Loading
Loading
+0 −1097

File deleted.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -5,9 +5,9 @@ cd /d %~dp0
REM command line options:
REM quiet

SET VER=21
SET PREV_VER=20
SET LASTVERSIONSTODROP=19
SET VER=22
SET PREV_VER=21
SET LASTVERSIONSTODROP=20
SET QUIET=%1

SET PYTHONPATH="%PYTHONPATH%;../../"
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ update_db-v17_v18.conf
update_db-v18_v19.conf
update_db-v19_v20.conf
update_db-v20_v21.conf
update_db-v21_v22.conf
$config files$

interactive = no
+3 −3
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@
# - command line options:
#   - "quiet"

VERSIONS_TO_DROP="2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"
PREV_VER="20"
VER="21"
VERSIONS_TO_DROP="2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
PREV_VER="21"
VER="22"
QUIET="$1"


+60 −14
Original line number Diff line number Diff line
@@ -652,6 +652,10 @@ class database:
			_log.error(u'cannot REINDEX cloned target database')
			return False

		if not self.revalidate_constraints():
			_log.error(u'cannot VALIDATE CONSTRAINTs in cloned target database')
			return False

		tmp = cfg_get(self.section, 'superuser schema')
		if tmp is not None:
			if not _import_schema(group=self.section, schema_opt='superuser schema', conn=self.conn):
@@ -732,12 +736,14 @@ class database:
		curs.close()
		self.conn.commit()

		# we need inheritance or else things will fail miserably
		# we need inheritance or else things will fail miserably but:
		# default now ON and PG10.0 hardwired to ON
		# so remove database specific setting
		curs = self.conn.cursor()
		try:
			curs.execute("alter database %s set sql_inheritance to DEFAULT" % self.name)
		except:
			_log.exception(u'PG 10 hardwired for sql_inheritance')
			_log.exception('PostgreSQL 10 onwards: <sql_inheritance> hardwired')
		curs.close()
		self.conn.commit()

@@ -798,6 +804,7 @@ class database:

		_log.info(u"Database [%s] does not exist." % self.name)
		return None

	#--------------------------------------------------------------
	def __create_db(self):

@@ -821,14 +828,11 @@ class database:
				print_msg("==> dropping pre-existing target database [%s] ..." % self.name)
				_log.info(u'trying to drop target database')
				cmd = 'DROP DATABASE "%s"' % self.name
				_log.debug(u'committing existing connection before setting autocommit')
				# DROP DATABASE must be run outside transactions
				self.conn.commit()
				_log.debug(u'setting autocommit to TRUE')
				self.conn.autocommit = True
				self.conn.readonly = False
				self.conn.set_session(readonly = False, autocommit = True)
				cursor = self.conn.cursor()
				try:
					cursor.execute(u'SET default_transaction_read_only TO OFF')
					_log.debug(u'running SQL: %s', cmd)
					cursor.execute(cmd)
				except:
@@ -875,13 +879,11 @@ class database:

		# create database by cloning
		print_msg("==> cloning [%s] (%s) as target database [%s] ..." % (self.template_db, size, self.name))
		# create DB must be run outside transactions
		# CREATE DATABASE must be run outside transactions
		self.conn.commit()
		self.conn.autocommit = True
		self.conn.readonly = False
		self.conn.set_session(readonly = False, autocommit = True)
		cursor = self.conn.cursor()
		try:
			cursor.execute(u'SET default_transaction_read_only TO OFF')
			cursor.execute(create_db_cmd)
		except:
			_log.exception(u">>>[%s]<<< failed" % create_db_cmd)
@@ -1155,10 +1157,10 @@ class database:
		_log.info(u'this may potentially take "quite a long time" depending on how much data there is in the database')
		_log.info(u'you may want to monitor the PostgreSQL log for signs of progress')

		# REINDEX must be run outside transactions
		self.conn.commit()
		self.conn.set_session(readonly = False, autocommit = True)
		curs_outer = self.conn.cursor()
		curs_outer.execute(u'SET default_transaction_read_only TO OFF')
		cmd = 'REINDEX (VERBOSE) DATABASE %s' % self.name
		try:
			curs_outer.execute(cmd)
@@ -1182,6 +1184,52 @@ class database:

		return True

	#--------------------------------------------------------------
	def revalidate_constraints(self):

		print_msg("==> revalidating constraints in target database (can take a while) ...")

		do_revalidate = cfg_get(self.section, 'revalidate')
		if do_revalidate is None:
			do_revalidate = True		# default: do it
		else:
			do_revalidate = (int(do_revalidate) == 1)
		if not do_revalidate:
			_log.warning('skipping VALIDATE CONSTRAINT')
			print_msg("    ... skipped")
			return True

		_log.info(u'reVALIDATing CONSTRAINTs in cloned target database so upgrade does not fail due to broken data')
		_log.info(u'this may potentially take "quite a long time" depending on how much data there is in the database')
		_log.info(u'you may want to monitor the PostgreSQL log for signs of progress')

		curs = self.conn.cursor()
		cmd = u"""do $$
			DECLARE
				r record;
			BEGIN
				FOR r IN (
					select con.connamespace, nsp.nspname, con.conname, con.conrelid, rel.relname
					from pg_constraint con
						join pg_namespace nsp on nsp.oid = con.connamespace
						join pg_class rel on rel.oid = con.conrelid
					where contype in ('c','f')
				) LOOP
					RAISE NOTICE 'validating [%] on [%.%]', r.conname, r.nspname, r.relname;
					EXECUTE 'UPDATE pg_constraint SET convalidated=false WHERE conname=$1 AND connamespace=$2 AND conrelid=$3' USING r.conname, r.connamespace, r.conrelid;
					EXECUTE 'ALTER TABLE ' || r.nspname || '.' || r.relname || ' VALIDATE CONSTRAINT "' || r.conname || '"';
				END LOOP;
			END
		$$;"""
		try:
			curs.execute(cmd)
		except:
			_log.exception(u">>>[VALIDATE CONSTRAINT]<<< failed")
			return False
		finally:
			curs.close()
		return True

	#--------------------------------------------------------------
	def transfer_users(self):
		print_msg("==> transferring users ...")
@@ -1806,8 +1854,6 @@ finally:
			_log.warning(u'%s', conn)
			_log.warning(u'closing connection')
			conn.close()
		del conn
	del conn_ref_count

_log.info(u'after main, before sys.exit(0)')

Loading