44 lines
1.4 KiB
Python
Executable File
44 lines
1.4 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import argparse
|
|
import random
|
|
import time
|
|
|
|
import psycopg2
|
|
|
|
ap = argparse.ArgumentParser()
|
|
|
|
ap.add_argument("--dbname", default="")
|
|
ap.add_argument("--rows", type=int, default=int(1E6))
|
|
ap.add_argument("--updates-per-transaction", type=int, default=1)
|
|
ap.add_argument("--transactions-per-sample", type=int, default=1)
|
|
ap.add_argument("--sleep-between-transactions", type=float, default=1.0)
|
|
args = ap.parse_args()
|
|
|
|
db = psycopg2.connect("dbname='%s'" % (args.dbname, ))
|
|
csr = db.cursor()
|
|
csr.execute("drop table if exists tmp_update_bloat")
|
|
csr.execute("create table tmp_update_bloat(id serial primary key, t text)")
|
|
for i in range(args.rows):
|
|
t = "%s.%d" % ("a" * random.randrange(4, 64), i)
|
|
csr.execute("insert into tmp_update_bloat(t) values(%s)", (t,))
|
|
db.commit()
|
|
|
|
n_updates = 0
|
|
n_transactions = 0
|
|
while True:
|
|
csr.execute("select pg_total_relation_size('tmp_update_bloat')")
|
|
size = csr.fetchone()[0]
|
|
print(n_transactions, n_updates, size)
|
|
for i in range(args.transactions_per_sample):
|
|
for j in range(args.updates_per_transaction):
|
|
id = random.randrange(args.rows) + 1
|
|
t = "%s.%d" % ("b" * random.randrange(4, 64), n_updates)
|
|
csr.execute("update tmp_update_bloat set t = %s where id = %s", (t, id,))
|
|
n_updates += 1
|
|
db.commit()
|
|
n_transactions += 1
|
|
time.sleep(args.sleep_between_transactions)
|
|
|
|
|