logo资料库

Postgres-XL安装使用说明.docx

第1页 / 共8页
第2页 / 共8页
第3页 / 共8页
第4页 / 共8页
第5页 / 共8页
第6页 / 共8页
第7页 / 共8页
第8页 / 共8页
资料共8页,全文预览结束
安装
管理
使用
高可用
数据节点增删
数据导入导出
安装 Centos 6.4 * 主机规划 192.168.1.97 192.168.1.99 192.168.1.100 时间同步设置 ntp SX-HDP-NN-02(gtm_proxy,coordinator,datanode) SX-HDP-DN-02 (gtm) SX-HDP-DN-03(gtm_proxy,coordinator,datanode) ftp server 检查/etc/hosts 文件配置 准备工作 yum install -y make gcc tar readline readline-devel zlib zlib-devel flex bison openjade docbook-style-dsssl yum list make gcc tar readline readline-devel zlib zlib-devel flex bison openjade docbook-style-dsssl 在各台机器的/var/ftp/pub 目录下解压源码 #tar -zxvf postgres-xl-v9.2-src.tar.gz # cd postgres-xl # ./configure # gmake # gmake install 在 SX-HDP-DN-02 上安装 pgxc_ctl # cdpostgres-xl/contrib/pgxc_ctl/ # ./configure # gmake # gmake install 这样 pgxc_ctl 就安装完成了,后续的安装就可以用该命令来进行了。 /sbin/ldconfig /usr/local/pgsql/lib * 创建用户 为每台主机创建用户 postgres # useradd postgres # passwd postgres # 输入密码
#注意这里环境变量一定要添加到.bashrc 文件中,否则会找不到相关命令 * 设置环境变量 # su - postgres $ vi .bashrc export PGHOME=/usr/local/pgsql export PGUSER=postgres export LD_LIBRARY_PATH=$PGHOME/lib export PATH=$PGHOME/bin:$PATH * 权限设置 安装过程中需要在 datanode 上创建目录,所以需要有$PGHOME 目录的写权限。 在每台 datanode 和 coordinator 主机上执行以下命令: chown -R postgres:postgres /usr/local/pgsql * pgxc_ctl 免密码运行 在 SX-HDP-DN-02 上以 postgres 用户运行 ssh-keygen -t rsa (in ~/.ssh 目录下) cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 authorized_keys chmod 700 .ssh 若不是在本地安装,需要把该文件的内容添加到其他需要安装的机器的 authorized_keys 文 件中 scp authorized_keys postgres@SX-HDP-NN-02:/home/postgres/.ssh/ scp authorized_keys postgres@SX-HDP-DN-03:/home/postgres/.ssh/ 这样 postgres 用户就可以免密码登陆其他主机了 pgxc_ctl PGXC pwd /home/postgres/pgxc_ctl PGXC prepare config template.conf 配置文件 pgxc_ctl.conf 执行如下命令初始化集群 pgxc_ctl -c pgxc_ctl.conf init all 管理 pgxc_ctl PGXC monitor all PGXC stop all
PGXC start all 使用 在非 gtm 节点执行如下命令,创建数据库 createdb mydb psql mydb mydb=# select version(); mydb=# select current_date; mydb=# select 2+2; mydb=# select datname from pg_database; cd/var/ftp/pub/postgres-xl/src/tutorial gmake psql -s mydb mydb=# \ibasics.sql mydb=# \iadvanced.sql 安装 pgadmin 工具来远程连接集群
高可用 GTM 高可用 数据节点高可用 DISTRIBUTE BY Note: The following description applies only to Postgres-XL This clause specifies how the table is distributed or replicated among Datanodes. REPLICATION Each row of the table will be replicated to all the Datanode of the Postgres-XL database cluster. ROUNDROBIN Each row of the table will be placed in one of the Datanodes in a round-robin manner. The value of the row will not be needed to determine what Datanode to go. HASH ( column_name ) Each row of the table will be placed based on the hash value of the specified column. Following type is allowed as distribution column: INT8, INT2, OID, INT4, BOOL, INT2VECTOR, OIDVECTOR, CHAR, NAME, TEXT, BPCHAR, BYTEA, VARCHAR, FLOAT4, FLOAT8, NUMERIC, CASH, ABSTIME, RELTIME, DATE, TIME, TIMESTAMP, TIMESTAMPTZ, INTERVAL, and TIMETZ. Please note that floating point is not allowed as a basis of the distribution column.
MODULO ( column_name ) Each row of the table will be placed based on the modulo of the specified column. Following type is allowed as distribution column: INT8, INT2, OID, INT4, BOOL, INT2VECTOR, OIDVECTOR, CHAR, NAME, TEXT, BPCHAR, BYTEA, VARCHAR, FLOAT4, FLOAT8, NUMERIC, CASH, ABSTIME, RELTIME, DATE, TIME, TIMESTAMP, TIMESTAMPTZ, INTERVAL, and TIMETZ. Please note that floating point is not allowed as a basis of the distribution column. If DISTRIBUTE BY is not specified, columns with UNIQUE constraint will be chosen as the distribution key. If no such column is specified, distribution column is the first eligible column in the definition. If no such column is found, then the table will be distributed by ROUNDROBIN. 创建一个 REPLICATION 的表 CREATE TABLE products_rep ( product_no integer, name text ) DISTRIBUTE BY REPLICATION; COPY products_rep from '/home/postgres/temp/products_rep.d' delimiter '|'; 创建一个 DISTRIBUTE 的表 CREATE TABLE products_dis ( product_no integer UNIQUE, name text ) DISTRIBUTE BY HASH(product_no); COPY products_dis from '/home/postgres/temp/products_rep.d' delimiter '|'; 数据节点增删 增加(红字节点) 192.168.1.97 192.168.1.99 192.168.1.100 192.168.1.98 SX-HDP-NN-02(gtm_proxy,coordinator,datanode) SX-HDP-DN-02 (gtm) SX-HDP-DN-03(gtm_proxy,coordinator,datanode) SX-HDP-DN-01(gtm_proxy,coordinator,datanode) ftp server 按照之前安装操作为节点安装软件 备份数据库
add gtm_proxy gtm_pxy3 SX-HDP-DN-01 20001 /home/postgres/pgxc/nodes/gtm_pxy add coordinator master coord3 SX-HDP-DN-01 5432 20010 /home/postgres/pgxc/nodes/coord add datanode3 /home/postgres/pgxc/nodes/dn_master datanode1 SX-HDP-DN-01 datanode master 15432 20012 Redistribute existing data by using ALTER TABLE REDISTRIBUTE. 删除(红字节点) 192.168.1.97 192.168.1.99 192.168.1.100 192.168.1.98 SX-HDP-NN-02(gtm_proxy,coordinator,datanode) SX-HDP-DN-02 (gtm) SX-HDP-DN-03(gtm_proxy,coordinator,datanode) SX-HDP-DN-01(gtm_proxy,coordinator,datanode) ftp server 备份 distribution 表 pg_dump -U postgres -t products_dis mydb>mydb.sql 用如下语句迁移 replication 表 alter table products_rep_2 delete node (datanode3); 检查要删除的数据节点是否还存在数据 SELECT c.pcrelid FROM pgxc_class c, pgxc_node n WHERE n.node_name = 'datanode2' AND n.oid = ANY (c.nodeoids); remove gtm_proxy gtm_pxy3 clean remove coordinator master coord3 clean remove datanode master datanode3 clean 重启 cluster 重新为集群导入 distribution 表 psql -U postgres mydb
3. 利用 pgxc_ctl 工具,直接通过 add gtm_proxy 、add coordinator 、 datanode 命令,在新增节点创建 gtm_proxy、coordinator、datanode,并加入原有集 add 群 4. 通过 monitor 命令检查节点是否已经加入 5. 重启所有节点服务 通过此命令实现对老表数据的重新分布 alter table products_dis_r to node (datanode1,datanode2,datanode3),DISTRIBUTE BY HASH(product_no); 【删除节点】 1. 停止所有数据库链接等操作,用 pg_dump 备份数据库的 distribution 表,然 后删除所有 distribution 表,用 alter table 命令从要删除的节点迁移 replication 表的 数据 2. 利用 pgxc_ctl 工具,直接通过 remove gtm_proxy 、remove coordinator 、 remove datanode 命令,将要删除节点的服务从原有集群删除 3. 通过 monitor 命令检查节点服务是否已删除 4. 重启所有节点服务 5. 重新导入备份的所有 distribution 表数据 通过此命令实现对老数据的重新分布 alter table products_dis_r to node (datanode1,datanode2); 数据导入导出 pg_dump 可以导出 2 中格式的文件,如下 XX.sql XX.dump --用 pg_restore 恢复数据 --用 psql 恢复数据 数据导出 pg_dump -U postgres(连接用户名) 例:pg_dump -U postgres -t weather -t cities mydb>test.sql 数据导入 psql -U postgres(用户名) 数据库名(缺省时同用户名) < C:\fulldb.sql 例:psql -U postgres template1 c:\fulldb.sql 数据导出 pg_dump --host localhost --port 5432 --username postgres –format custom --blobs --verbose --file "E:/MyDatabase.backup" MyDatabase 例:pg_dump -h SX-HDP-DN-03 -p 5432 -U postgres -Fc -t weather -t cities -f test.dump template1 数据导入
pg_restore --host localhost --port 5432 --username postgres --dbnameMyDatabase --verbose "E:/MyDatabase.backup" 例:pg_restore -h SX-HDP-DN-03 -p 5432 -U postgres -d postgrestest.dump COPY TO COPY FROM --将 postgresql 中的表数据拷贝到本地文件 --将本地文件内容拷贝到 postgresql 中的表里 例: mydb=# COPY weather to '/home/postgres/temp/weather.sql'; mydb=# COPY weather from '/home/postgres/temp/weather.sql'; --导出表数据 --导入文件数据 指定列分隔符 mydb=# COPY weather to '/home/postgres/temp/weather.2' delimiter '|'; mydb=# COPY weather from '/home/postgres/temp/weather.2' delimiter '|'; 直接在 shell 下执行,不用进入数据库 echo "COPY weather to '/home/postgres/temp/weather.3' delimiter '|'" | psqlpostgres echo "COPY weather from '/home/postgres/temp/weather.3' delimiter '|'" | psqlpostgres
分享到:
收藏