GPDB之基础笔记

2016/11/03 GPDB 共 2254 字,约 7 分钟

建表

建普通表

CREATE TABLE demo_tbl
(
  id integer,
  name character varying,
  gao character varying
)
DISTRIBUTED BY (id);

建带分区的表

CREATE TABLE demo_tbl
(
  id integer,
  name character varying,
  gao character varying
)
DISTRIBUTED BY (id)
PARTITION BY RANGE(id)  
(
PARTITION p1 START (1) END (10), 
PARTITION p10 START (10) END (100)
);

 

新增分区

语法

alter table  表名 add partition 分区名 start(开始时间) end(结束时间) with (appendonly=true,orientation=column,compresstype=zlib,compresslevel=5)';

例子

alter table demo_tbl add  partition p1000 start(1000) end(10000);

删除指定分区

语法

alter table 表名 drop partition 分区名;

例子

alter table demo_tbl drop partition p1000 ;

给分区表重命名

语法

alter table 表名 rename partition 原分区名 to 新分区名;

例子

alter table demo_tbl rename partition p1000 to p111;

 

交换分区

语法: (将表1中的分区1 与 表2 的交换)

alter  table 表1  exchange partition 分区1  with table 表2;

例子:

alter table fath_tbl exchange partition pmaxvalue with table temp_tbl_t;

 

屏蔽\的转移含义

set standard_conforming_strings=on;
开启后insert含有'\'的字符串不会报错,会正常入库

 

gpload工具使用

1.在服务器上切换至pgadmin用户

su – pgadmin

2.制作好ctl文件(配置文件格式要求非常严谨)

VERSION: 1.0.0.1
DATABASE: <db_name>
USER: <db_username>
HOST: <master_hostname>
PORT: <master_port>
GPLOAD:
   INPUT:
    - SOURCE:
         LOCAL_HOSTNAME:
           - <hostname_or_ip>
         PORT: <http_port>
       | PORT_RANGE: [<start_port_range>, <end_port_range>]
         FILE: 
           - </path/to/input_file>
         SSL: true | false
         CERTIFICATES_PATH: </path/to/certificates>
    - COLUMNS:
           - <field_name>: <data_type>
    - TRANSFORM: '<transformation>' 
    - TRANSFORM_CONFIG: '<configuration-file-path>' 
    - MAX_LINE_LENGTH: <integer> 
    - FORMAT: text | csv
    - DELIMITER: '<delimiter_character>'
    - ESCAPE: '<escape_character>' | 'OFF'
    - NULL_AS: '<null_string>'
    - FORCE_NOT_NULL: true | false
    - QUOTE: '<csv_quote_character>'
    - HEADER: true | false
    - ENCODING: <database_encoding>
    - ERROR_LIMIT: <integer>
    - ERROR_TABLE: <schema>.<table_name>
    - LOG_ERRORS: true | false
   EXTERNAL:
    - SCHEMA: <schema> | '%'
   OUTPUT:
    - TABLE: <schema>.<table_name>
    - MODE: insert | update | merge
    - MATCH_COLUMNS:
           - <target_column_name>
    - UPDATE_COLUMNS:
           - <target_column_name>
    - UPDATE_CONDITION: '<boolean_condition>'
    - MAPPING:
            <target_column_name>: <source_column_name> | '<expression>'
   PRELOAD:
    - TRUNCATE: true | false
    - REUSE_TABLES: true | false
   SQL:
    - BEFORE: "<sql_command>"
    - AFTER: "<sql_command>"

3.执行gpload

gpload -U gpadmin -d demo_db -h xxx.xxx.xxx.xxx -f  xxxxxx.ctl -l xxx.log

文档信息

Search

    Table of Contents