class PGBench: "class for interacting with pgbench utility" def __init__(self, scale, db=None, dbname=None, host=None, port=None, user=None, passwd=None): self.scale = scale if db: self.database = db else: self.database = PGDatabase(dbname, host, port, user, passwd) 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 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) # run pgbench -T 10 to populate db with some more data # self.pgb_run(10,16) 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 preparedb(self): "prepare db for replication" self.pgb_init_db() self.modify_db_for_replication() def capture_unmodified_schema(self): "read and save result of 'pg_dump -s'"