Skip to content

Commit d39d96f

Browse files
authored
Merge pull request #309 from somratdutta/patch-1
Refactor `postgresql/benchmark.sh` to Wrap COPY FREEZE in a Transaction Block
2 parents 7745d26 + d7ff433 commit d39d96f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

postgresql/benchmark.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ chmod 777 ~ hits.tsv
1010

1111
sudo -u postgres psql -t -c 'CREATE DATABASE test'
1212
sudo -u postgres psql test -t < create.sql
13-
sudo -u postgres psql test -t -c '\timing' -c "\\copy hits FROM 'hits.tsv' with freeze"
13+
14+
# Load data: wrap TRUNCATE and \copy FREEZE in a single transaction
15+
# If we dont' do this, Postgres will throw an error:
16+
# "ERROR: cannot perform COPY FREEZE because the table was not created or truncated in the current subtransaction"
17+
# (i.e. Postgres requires that the table be either created or truncated in the current subtransaction)
18+
sudo -u postgres psql test <<'EOF'
19+
BEGIN;
20+
TRUNCATE TABLE hits;
21+
\copy hits FROM 'hits.tsv' with freeze;
22+
COMMIT;
23+
EOF
1424

1525
sudo -u postgres psql test -t -c 'VACUUM ANALYZE hits'
1626

0 commit comments

Comments
 (0)