(self, bin_dir, data_dir, findRestartPoint)
Collect last checkpoint information from pg_controldata output
Collect last checkpoint information from pg_controldata output
Collect last checkpoint information from pg_controldata output
def __init__(self, bin_dir, data_dir, findRestartPoint):
        """Collect last checkpoint information from pg_controldata output"""
        self.xlogid = None
        self.xrecoff = None
        self.timeline = None
        self.wal_size = None
        self.wal_name = None
        self.cluster_state = None
        self.is_shutdown = False
        self.pg_version = 0
        self.is_valid = False

        try:
            pg_controldata = os.path.join(bin_dir, "pg_controldata")
            pipe = subprocess.Popen([ pg_controldata, data_dir ], stdout=subprocess.PIPE)
        except OSError:
            # don't complain if we cannot execute it
            return

        matches = 0
        for line in pipe.stdout.readlines():
            if findRestartPoint:
                m = re.match("^Latest checkpoint's REDO location:\s+([0-9A-F]+)/([0-9A-F]+)", line)
            else:
                m = re.match("^Latest checkpoint location:\s+([0-9A-F]+)/([0-9A-F]+)", line)
            if m:
                matches += 1
                self.xlogid = int(m.group(1), 16)
                self.xrecoff = int(m.group(2), 16)
            m = re.match("^Latest checkpoint's TimeLineID:\s+(\d+)", line)
            if m:
                matches += 1
                self.timeline = int(m.group(1))
            m = re.match("^Bytes per WAL segment:\s+(\d+)", line)
            if m:
                matches += 1
                self.wal_size = int(m.group(1))
            m = re.match("^pg_control version number:\s+(\d+)", line)
            if m:
                matches += 1
                self.pg_version = int(m.group(1))
            m = re.match("^Database cluster state:\s+(.*$)", line)
            if m:
                matches += 1
                self.cluster_state = m.group(1)
                self.is_shutdown = (self.cluster_state == "shut down")

        # ran successfully and we got our needed matches
        if pipe.wait() == 0 and matches == 5:
            self.wal_name = "%08X%08X%08X" % \
                (self.timeline, self.xlogid, self.xrecoff / self.wal_size)
            self.is_valid = True
def __init__ ( self , bin_dir , data_dir , findRestartPoint ) : self . xlogid = None self . xrecoff = None self . timeline = None self . wal_size = None self . wal_name = None self . cluster_state = None self . is_shutdown = False self . pg_version = 0 self . is_valid = False try : pg_controldata = os . path . join ( bin_dir , "pg_controldata" ) pipe = subprocess . Popen ( [ pg_controldata , data_dir ] , stdout = subprocess . PIPE ) except OSError : # don't complain if we cannot execute it return matches = 0 for line in pipe . stdout . readlines ( ) : if findRestartPoint : m = re . match ( "^Latest checkpoint's REDO location:\s+([0-9A-F]+)/([0-9A-F]+)" , line ) else : m = re . match ( "^Latest checkpoint location:\s+([0-9A-F]+)/([0-9A-F]+)" , line ) if m : matches += 1 self . xlogid = int ( m . group ( 1 ) , 16 ) self . xrecoff = int ( m . group ( 2 ) , 16 ) m = re . match ( "^Latest checkpoint's TimeLineID:\s+(\d+)" , line ) if m : matches += 1 self . timeline = int ( m . group ( 1 ) ) m = re . match ( "^Bytes per WAL segment:\s+(\d+)" , line ) if m : matches += 1 self . wal_size = int ( m . group ( 1 ) ) m = re . match ( "^pg_control version number:\s+(\d+)" , line ) if m : matches += 1 self . pg_version = int ( m . group ( 1 ) ) m = re . match ( "^Database cluster state:\s+(.*$)" , line ) if m : matches += 1 self . cluster_state = m . group ( 1 ) self . is_shutdown = ( self . cluster_state == "shut down" ) # ran successfully and we got our needed matches if pipe . wait ( ) == 0 and matches == 5 : self . wal_name = "%08X%08X%08X" % ( self . timeline , self . xlogid , self . xrecoff / self . wal_size ) self . is_valid = True