1.数据集下载
TPC-H数据集: https://github.com/gregrahn/tpch-kit
2.解压安装
unzip tpch-kit-master.zip
cd tpch-kit-master/dbgen/
make -f Makefile
通过上面命令,生成两个文件,分别是dbgen、qgen。分别用于产生数据和查询。
3.生成数据
##进入dbgen目录
cd tpch-kit-master/dbgen/
##生成8个tbl文件,生成以后修改八个文件的可执行权限,将这八个tbl文件放入创建好的文件目录tbl下(注意1表示1G数据量,0.1表示100M数据量)。
./dbgen -s 1 -fchmod 777 tbl/*.tbl
或者单独生成每个表的数据(生成数据文件目前只能在dbgen目录中)
./dbgen -vf -s 0.01 -T r | tee -a region.tbl
./dbgen -vf -s 0.01 -T n | tee -a nation.tbl
./dbgen -vf -s 0.01 -T c | tee -a customer.tbl
./dbgen -vf -s 0.01 -T L | tee -a lineitem.tbl
./dbgen -vf -s 0.01 -T O | tee -a orders.tbl
./dbgen -vf -s 0.01 -T P | tee -a part.tbl
./dbgen -vf -s 0.01 -T S | tee -a partsupp.tbl
./dbgen -vf -s 0.01 -T s | tee -a supplier.tbl
##将生成的数据转移到/data/tpchdata
mv *.tbl /data/tpchdata ;
4.创建数据库和表
su - postgres
##连接数据库
psql -h 192.168.80.131 -U postgres
##创建数据
create database tpch
##进入数据库
\c tpch
##创建表 (建表语句在dbgen下面的dss.ddl)
CREATE TABLE NATION (
N_NATIONKEY INTEGER NOT NULL,
N_NAME CHAR(25) NOT NULL,
N_REGIONKEY INTEGER NOT NULL,
N_COMMENT VARCHAR(152));
CREATE TABLE REGION (
R_REGIONKEY INTEGER NOT NULL,
R_NAME CHAR(25) NOT NULL,
R_COMMENT VARCHAR(152));
CREATE TABLE PART (
P_PARTKEY INTEGER NOT NULL,
P_NAME VARCHAR(55) NOT NULL,
P_MFGR CHAR(25) NOT NULL,
P_BRAND CHAR(10) NOT NULL,
P_TYPE VARCHAR(25) NOT NULL,
P_SIZE INTEGER NOT NULL,
P_CONTAINER CHAR(10) NOT NULL,
P_RETAILPRICE DECIMAL(15,2) NOT NULL,
P_COMMENT VARCHAR(23) NOT NULL );
CREATE TABLE SUPPLIER (
S_SUPPKEY INTEGER NOT NULL,
S_NAME CHAR(25) NOT NULL,
S_ADDRESS VARCHAR(40) NOT NULL,
S_NATIONKEY INTEGER NOT NULL,
S_PHONE CHAR(15) NOT NULL,
S_ACCTBAL DECIMAL(15,2) NOT NULL,
S_COMMENT VARCHAR(101) NOT NULL);
CREATE TABLE PARTSUPP (
PS_PARTKEY INTEGER NOT NULL,
PS_SUPPKEY INTEGER NOT NULL,
PS_AVAILQTY INTEGER NOT NULL,
PS_SUPPLYCOST DECIMAL(15,2) NOT NULL,
PS_COMMENT VARCHAR(199) NOT NULL );
CREATE TABLE CUSTOMER (
C_CUSTKEY INTEGER NOT NULL,
C_NAME VARCHAR(25) NOT NULL,
C_ADDRESS VARCHAR(40) NOT NULL,
C_NATIONKEY INTEGER NOT NULL,
C_PHONE CHAR(15) NOT NULL,
C_ACCTBAL DECIMAL(15,2) NOT NULL,
C_MKTSEGMENT CHAR(10) NOT NULL,
C_COMMENT VARCHAR(117) NOT NULL);
CREATE TABLE ORDERS (
O_ORDERKEY INTEGER NOT NULL,
O_CUSTKEY INTEGER NOT NULL,
O_ORDERSTATUS CHAR(1) NOT NULL,
O_TOTALPRICE DECIMAL(15,2) NOT NULL,
O_ORDERDATE DATE NOT NULL,
O_ORDERPRIORITY CHAR(15) NOT NULL,
O_CLERK CHAR(15) NOT NULL,
O_SHIPPRIORITY INTEGER NOT NULL,
O_COMMENT VARCHAR(79) NOT NULL);
CREATE TABLE LINEITEM (
L_ORDERKEY INTEGER NOT NULL,
L_PARTKEY INTEGER NOT NULL,
L_SUPPKEY INTEGER NOT NULL,
L_LINENUMBER INTEGER NOT NULL,
L_QUANTITY DECIMAL(15,2) NOT NULL,
L_EXTENDEDPRICE DECIMAL(15,2) NOT NULL,
L_DISCOUNT DECIMAL(15,2) NOT NULL,
L_TAX DECIMAL(15,2) NOT NULL,
L_RETURNFLAG CHAR(1) NOT NULL,
L_LINESTATUS CHAR(1) NOT NULL,
L_SHIPDATE DATE NOT NULL,
L_COMMITDATE DATE NOT NULL,
L_RECEIPTDATE DATE NOT NULL,
L_SHIPINSTRUCT CHAR(25) NOT NULL,
L_SHIPMODE CHAR(10) NOT NULL,
L_COMMENT VARCHAR(44) NOT NULL);
5.导入数据
COPY region FROM '/data/tpchdata/region.tbl' DELIMITER '|' CSV HEADER;
COPY nation FROM '/data/tpchdata/nation.tbl' DELIMITER '|' CSV HEADER;
COPY customer FROM '/data/tpchdata/customer.tbl' DELIMITER '|' CSV HEADER;
COPY lineitem FROM '/data/tpchdata/lineitem.tbl' DELIMITER '|' CSV HEADER;
COPY orders FROM '/data/tpchdata/orders.tbl' DELIMITER '|' CSV HEADER;
COPY part FROM '/data/tpchdata/part.tbl' DELIMITER '|' CSV HEADER;
COPY partsupp FROM '/data/tpchdata/partsupp.tbl' DELIMITER '|' CSV HEADER;
COPY supplier FROM '/data/tpchdata/supplier.tbl' DELIMITER '|' CSV HEADER;
标签:PostgreSQL,dbgen,15,CHAR,数据表,tbl,TPCH,INTEGER,NULL From: https://www.cnblogs.com/yeyuzhuanjia/p/17931209.html