Skip to content

Instantly share code, notes, and snippets.

@ololobus
Last active February 5, 2024 02:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ololobus/973709aa333ec4f1bebe2facfbfab770 to your computer and use it in GitHub Desktop.
Save ololobus/973709aa333ec4f1bebe2facfbfab770 to your computer and use it in GitHub Desktop.
PostgreSQL pgbench schema
\set aid random(1, 100000 * :scale)
\set bid random(1, 1 * :scale)
\set tid random(1, 10 * :scale)
\set delta random(-5000, 5000)
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;
CREATE TABLE pgbench_history (
tid int,
bid int,
aid int,
delta int,
mtime timestamp,
filler char(22)
);
CREATE TABLE pgbench_tellers (
tid int NOT NULL,
bid int,
tbalance int,
filler char(84)
)
WITH (
fillfactor = 100
);
CREATE TABLE pgbench_accounts (
aid int NOT NULL,
bid int,
abalance int,
filler char(84)
)
WITH (
fillfactor = 100
);
CREATE TABLE pgbench_branches (
bid int NOT NULL,
bbalance int,
filler char(88)
)
WITH (
fillfactor = 100
);
ALTER TABLE pgbench_branches
ADD PRIMARY KEY (bid);
ALTER TABLE pgbench_tellers
ADD PRIMARY KEY (tid);
ALTER TABLE pgbench_accounts
ADD PRIMARY KEY (aid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment