PostgreSQL 더미 데이터 대량 작성용 벤치 마크 도구 pgbench 사용법

PostgreSQL

벤치 마크 도구 pgbench는 PostgreSQL 서버 인스톨러에 동봉되어 있기 때문에 함께 설치됩니다. 설치에 대해서는 다음 글을 참조하십시오.

Windows Server 2019에서 PostgreSQL 13.5-1 Windows x64 버전 설치하기(인스톨러 사용)
Windows Server 2012 R2에 PostgreSQL 14 Windows x64 버전 설치하기(zip archive 사용)
Linux7 CentOS7에서 PostgreSQL 12 설치하기
Linux PostgreSQL version13설치하기
Linux8 CentOS8에서 PostgreSQL 12 설치하기

명령형식

pgbench [옵션] dbname

옵션설명
-i다음의 4개의 테이블을 작성합니다.
pgbench_accounts
pgbench_branches
pgbench_history
pgbench_tellers
이미 존재한다면 drop하고 다시 작성합니다.
-s다음 테이블의 행수를 옵션으로 지정한 배율로 적산합니다.
pgbench_branches 1개의 행
pgbench_tellers 10개의 행
pgbench_accounts 100,000개의 행
pgbench_history 0개의 행
예를 들어 [-s 100]은 pgbench_accounts 테이블에
10,000,000개의 행을 생성하는 것을 의미합니다.
기본 배율은 1입니다. -i 옵션과 함께 사용합니다.
-U데이터베이스 로그인 사용자 이름
-h데이터베이스 서버 호스트 이름
-d디버깅 출력을 표시합니다.

사용 예시

다음과 같이 pgbench 명령으로 동일한 SQL 명령의 순서를 여러 번 실행합니다.

C:\>pgbench -i -s 3 -U postgres -d
Password:********
dropping old tables...
NOTICE:  table "pgbench_accounts" does not exist, skipping
NOTICE:  table "pgbench_branches" does not exist, skipping
NOTICE:  table "pgbench_history" does not exist, skipping
NOTICE:  table "pgbench_tellers" does not exist, skipping
creating tables...
generating data (client-side)...
300000 of 300000 tuples (100%) done (elapsed 1.17 s, remaining 0.00 s)
vacuuming...
creating primary keys...
done in 1.93 s (drop tables 0.03 s, create tables 0.07 s, client-side generate 1.33 s, vacuum 0.20 s, primary keys 0.29 s).

위 명령으로 작성된 데이터를 다음과 같이 확인할 수 있습니다.

C:\>psql -U postgres
postgres 사용자의 암호:********
psql (13.5)
도움말을 보려면 "help"를 입력하십시오.

postgres=# select count(*) from pgbench_accounts;
 count
--------
 300000
(1개 행)

postgres=# select count(*) from pgbench_branches;
 count
-------
     3
(1개 행)

postgres=# select count(*) from pgbench_tellers;
 count
-------
    30
(1개 행)

postgres=# select count(*) from pgbench_history;
 count
-------
     0
(1개 행)

postgres=#
제목과 URL을 복사했습니다