免费注册
帮助文档(华北一、二)

  • 1. DW客户端的方式访问

    ● 1.1 DW(greenplum)客户端方式访问(以Centos为例)

    如果你选择的数据仓库类型是greenplum、可以采用下面的方式访问

    1)下载greenplum客户端解压

     wget http://downloadupt.infile.inspurcloud.cn/greenplum-client.tar.gz

    tar -zxvf greenplum-client.tar.gz

    2)配置dw客户端

    进入greenplum-client安装目录,编辑 greenplumclientpath.sh 修改UDWHOME:export UDWHOME= client安装目录(如/root/greenplum-client)

    3) 使配置生效

    在~/.bashrc中添加如下配置

    source /data/greenplum-client/greenplumclientpath.sh

    source ~/.bashrc

    备注:/data/greenplum-client是greenplum-client的安装路径

    4) 连接数据库

    psql -h hostIP(或域名) –U username -d database -p port –W

    ● 1.2 udw(udpg)客户端方式访问(以Centos为例)

    如果你选择的数据仓库类型是udpg、可以采用下面的方式访问

    1)下载dw客户端

     wget http://udwclient.ufile.ucloud.cn/udw-client.tar

    解压: tar xvf udw-client.tar

    2)配置udw客户端

    进入udw-client安装目录,编辑 udwclientpath.sh,修改UDWCLIENT:export UDWCLIENT= client安装目录(如/root/udw-client)

    3)使配置生效在~/.bashrc中添加如下配置

     
    source /data/udw-client/udw_client_path.sh 
    source ~/.bashrc 
    备注:/data/udw-client是udw-client的安装路径

    4) 连接数据库

    psql -h hostIP(或域名) –U username -d database -p port –W

    2. python客户端访问

     $yum install python-psycopg2

    ● 示例1. 连接DW testconn.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully"

    执行 python testconn.py

    ● 示例2. 创建一个表 createTable.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully" 
    cur = conn.cursor() 
    cur.execute('''CREATE TABLE COMPANY     
    (ID INT PRIMARY KEY     NOT NULL,     
    NAME           TEXT    NOT NULL,     
    AGE            INT     NOT NULL,     
    ADDRESS        CHAR(50),     
    SALARY         REAL);''') 
    print "Table created successfully" 
    conn.commit() 
    conn.close()

    ● 示例3. 插入记录 insert.py

     
    #!/usr/bin/python   
    import psycopg2 
    conn = psycopg2.connect(database="dev", user="username", 
    password="password", host="hostIP", port="port") 
    print "Opened database successfully" 
    cur = conn.cursor() 
    cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \