#!/usr/bin/python import psycopg2 from os import environ from time import sleep def main() : conn = psycopg2.connect(database=environ['PGDATABASE']) rows = 0 count = 10000 max_rows = 1000000 while rows < max_rows : with conn.cursor() as cur : cur.executemany('INSERT INTO t (foo) VALUES (1)', range(count)) rows += count print(rows) conn.commit() sleep(120) # This is present only to provide the tester to examine the memory usage of the srver process before closing the connection. conn.close() if __name__ == '__main__' : exit(main())