def pgb_run (self, seconds=60, concurrency=25, filename=None, background=False): # run pgbench -T 10 to populate db with some data cmd = [PGBENCH, '-T', '%d' % seconds, '-c', '%d' % concurrency] + self.database.get_db_cmdline_args() if filename: cmd += ['-f', filename] if background: run_in_background(cmd) else: run_cmd(cmd)
def modify_db_for_replication(self): "add pk's, foreign keys, partitions, ..." # add support for moddatetime triggers from contrib cmd = ['psql'] + self.database.get_db_cmdline_args() + ['-f', '/usr/share/postgresql/8.4/contrib/moddatetime.sql'] # print cmd run_cmd(cmd) # modify db and commit with open('/tmp/prepare_pgbenchdb_for_londiste.sql', 'w') as f: f.write(pgbencdb_mods) howto("create file /tmp/prepare_pgbenchdb_for_londiste.sql with the following ...\n----\n%s\n----\n" % pgbencdb_mods) howto(". . . and then execute it") cmd = ['psql'] + self.database.get_db_cmdline_args() + ['-f', '/tmp/prepare_pgbenchdb_for_londiste.sql'] run_cmd(cmd)
def create_node(self): cmd = [LONDISTE, self.inifile, 'create-'+self.node_type, self.node_name] + self.connect_string.split() if self.node_type in ['branch', 'leaf']: cmd += ['--provider=%s' % self.provider_connect_string] retcode, out, err = run_cmd (cmd) if retcode: raise Exception, 'create failed %s ' % ' '.join(cmd)
def status(self): "prints replication status" cmd = [LONDISTE, self.inifile, 'status'] retcode, stdout, stderr = run_cmd(cmd) if retcode: print stderr raise Exception, 'status failed: %s.' % ' '.join(cmd) print stdout
def compare_tables(self): "compares tables between provider and subscriber" cmd = [LONDISTE, self.inifile, 'compare'] retcode, stdout, stderr = run_cmd(cmd) if retcode: print stderr raise Exception, 'compare failed: %s.' % ' '.join(cmd) print stdout, stderr
def stop(self): "stops the replay process" # TODO - should check for existing pidfile try: cmd = [LONDISTE, '-d', self.inifile, '--stop'] retcode, out, err = run_cmd (cmd) if retcode: raise Exception, 'stop failed: %s.' % ' '.join(cmd) except: pass
def stop(self): "stops pgqd" pidfile = '%s/pid/pgqd.pid' % self.basedir try: pid = open(pidfile).read().strip() cmd = ['kill', pid] retcode, out, err = run_cmd(cmd) except: pass # ok to not have a pidfile in partially set up cluster
def execute(self, sql, name=None): if not name: name = '/tmp/%04d%02d%02dt%02d%02d%02d.ddl' % time.localtime(time.time())[:6] with open(name, 'w') as f: f.write(sql) cmd = [LONDISTE, self.inifile, 'execute', name] retcode, stdout, stderr = run_cmd(cmd) if retcode: print stderr raise Exception, 'execute failed: %s.' % ' '.join(cmd) print stdout
def install_ticker(self): "installs pgq on master" run_cmd([PGQADM, self.ticker_ini, 'install'])
def check_data(self): run_cmd([LONDISTE, self.provider_ini, 'compare'])
def add_tables_on_subscriber(self, tablelist): run_cmd([LONDISTE, self.subscriber_ini, 'subscriber', 'add'] + tablelist)
def add_tables_on_provider(self, tablelist): # print [LONDISTE, self.provider_ini, 'provider', 'add'] + tablelist run_cmd([LONDISTE, self.provider_ini, 'provider', 'add'] + tablelist)
def stop_londiste_replay(self): run_cmd([LONDISTE, self.subscriber_ini, '--stop'])
def install_londiste_on_provider(self): run_cmd([LONDISTE, self.provider_ini, 'provider', 'install'])
def stop_ticker(self): "stops ticker on provider" run_cmd([PGQADM, self.ticker_ini, '--stop'])
def start(self): "starts pgqd" cmd = [PGQD, '-d', self.inifile] # print 'pgqd.start()', cmd retcode, out, err = run_cmd(cmd)
def start_ticker(self): "starts ticker on provider" # print "start_ticker() ::",[PGQADM, self.ticker_ini, 'ticker', '-d'] run_cmd([PGQADM, self.ticker_ini, 'ticker', '-d'])
def start(self): cmd = [LONDISTE, '-d', self.inifile, 'replay'] # print '%s.start()' % self.database.dbname, cmd retcode, out, err = run_cmd (cmd) if retcode: raise Exception, 'start failed %s ' % ' '.join(cmd)
def pgb_init_db(self): "just run 'pgbench -i -s'" # run pgbench -i -s %(self.scale)s cmd = [PGBENCH, '-i', '-s', str(self.scale), '-F', '80'] + self.database.get_db_cmdline_args() run_cmd(cmd)
def start_londiste_replay(self): run_cmd([LONDISTE, self.subscriber_ini, 'replay', '-d'])
def install_londiste_on_subscriber(self): run_cmd([LONDISTE, self.subscriber_ini, 'subscriber', 'install'])
def add_tables(self, tablelist=[], flags=['--all']): "adds tables to replication, by default adds all user tables" cmd = [LONDISTE, self.inifile, 'add-table'] + tablelist + flags retcode, out, err = run_cmd(cmd) if retcode: raise Exception, 'add_tables failed: %s.' % ' '.join(cmd)