当前位置:   article > 正文

【openGauss2.1.0 TPC-H数据导入】_tpch下载

tpch下载

openGauss2.1.0 TPC-C数据导入

一、下载tpch测试数据

  1. 使用普通用户如omm登录服务器
  2. 执行如下命令下载测试数据库:
    git clone https://gitee.com/xzp-blog/tpch-kit.git
    
    • 1

二、导入测试数据

  1. 进入dbgen目录下,生成makefile文件:
    cd /opt/software/tpch-kit/dbgen/
    make -f Makefile
    
    • 1
    • 2
  2. 连接openGauss数据库,创建tpch的database:
    gsql -d postgres -p 5432 -r
    openGauss=# CREATE DATABASE tpch; 
    openGauss=# \q
    
    • 1
    • 2
    • 3
  3. 创建对象8张测试表,执行如下命令:
    cd /opt/software/tpch-kit/dbgen
    gsql -d tpch -f dss.ddl
    
    • 1
    • 2
    执行完成后,登录数据库查看,会看到如下8张表:
    					List of relations
     Schema |   Name   | Type  | Owner |             Storage
    --------+----------+-------+-------+----------------------------------
     public | customer | table | omm   | {orientation=row,compression=no}
     public | lineitem | table | omm   | {orientation=row,compression=no}
     public | nation   | table | omm   | {orientation=row,compression=no}
     public | orders   | table | omm   | {orientation=row,compression=no}
     public | part     | table | omm   | {orientation=row,compression=no}
     public | partsupp | table | omm   | {orientation=row,compression=no}
     public | region   | table | omm   | {orientation=row,compression=no}
     public | supplier | table | omm   | {orientation=row,compression=no}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  4. 生成8张表测试数据,执行如下命令:
    cd /opt/software/tpch-kit/dbgen
    ./dbgen -vf -s 1
    
    • 1
    • 2
    执行结果如下:
    [omm@opengauss01 dbgen]$ ./dbgen -vf -s 1
    TPC-H Population Generator (Version 2.17.3)
    Copyright Transaction Processing Performance Council 1994 - 2010
    Generating data for suppliers table/
    Preloading text ... 100%
    done.
    Generating data for customers tabledone.
    Generating data for orders/lineitem tablesdone.
    Generating data for part/partsupplier tablesdone.
    Generating data for nation tabledone.
    Generating data for region tabledone.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  5. 编写导入数据脚本LoadData.sh:
    for i in `ls *.tbl`; do
      table=${i/.tbl/}
      echo "Loading $table..."
      sed 's/|$//' $i > /tmp/$i
      gsql tpch -q -c "TRUNCATE $table"
      gsql tpch -c "\\copy $table FROM '/tmp/$i' CSV DELIMITER '|'"
    done
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    授予执行权限:
    [omm@opengauss01 dbgen]$ chmod +x LoadData.sh
    
    • 1
  6. 导入数据到8张表中,执行导入脚本LoadData.sh:
    [omm@opengauss01 dbgen]$ sh LoadData.sh
    
    • 1
    执行结果如下:
    Loading customer...
    Loading lineitem...
    Loading nation...
    Loading orders...
    Loading partsupp...
    Loading part...
    Loading region...
    Loading supplier...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  7. 检验数据是否已完成导入:
    gsql -d tpch -p 5432 -r
    tpch=# select count(*) from supplier;
    
    • 1
    • 2
    查看了supplier表的总记录数为:10000条。
    感兴趣可以全部查看8张表各自的总记录数,如下所示:
    tpch=# select count(*) from supplier;
     count
    -------
     10000
    (1 row)
    
    tpch=# select count(*) from lineitem;
      count
    ---------
     6001215
    (1 row)
    
    tpch=# select count(*) from nation;
     count
    -------
        25
    (1 row)
    
    tpch=# select count(*) from orders;
      count
    ---------
     1500000
    (1 row)
    
    tpch=# select count(*) from part;
     count
    --------
     200000
    (1 row)
    
    tpch=# select count(*) from partsupp;
     count
    --------
     800000
    (1 row)
    
    tpch=# select count(*) from region;
     count
    -------
         5
    (1 row)
    
    tpch=#
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    至此,已完后TPCH测试数据的导入工作。
  8. 生成相关查询语句,为避免对原有查询语句脚本产生污染,将其复制到queries目录下:
    cd /opt/software/tpch-kit/dbgen
    cp dists.dss queries/
    cp qgen queries/
    cd queries/
    
    • 1
    • 2
    • 3
    • 4
  9. 编写生成查询语句脚本genda.sh,内容如下:
    cd /opt/software/tpch-kit/dbgen/queries
    vim genda.sh
    
    • 1
    • 2
    添加如下内容:
    for i in {1..22}; do
        ./qgen -d $i>$i_new.sql
     ./qgen -d $i_new | sed 's/limit -1//' | sed 's/limit 100//' | sed 's/limit 10//' | sed 's/limit 20//' | sed 's/day (3)/day/' > queries.sql
    done
    
    • 1
    • 2
    • 3
    • 4
  10. 执行脚本genda.sh:
    cd /opt/software/tpch-kit/dbgen
    sh genda.sh
    
    • 1
    • 2
  11. 验证生成的查询语句:
    cd /opt/software/tpch-kit/dbgen/queries
    ls -l queries.sql
    
    • 1
    • 2
    结果如下:
    [omm@opengauss01 queries]$ ls -l queries.sql
    -rw-r--r-- 1 omm dbgrp  12K Aug 29 23:49 queries.sql
    
    • 1
    • 2
    感兴趣可以查看下queries.sql内容,看下生成了哪些SQL语句
    至此,已完成了查询语句的生成。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/935502
推荐阅读
相关标签
  

闽ICP备14008679号