pg_pathman安装、测试

本文详细介绍了如何在PostgreSQL中使用pg_pathman扩展进行范围(range)和哈希(hash)分区管理,包括下载、安装、配置、重启、测试及具体分区操作步骤。通过实例演示了如何创建分区主表、插入数据、创建分区并进行数据迁移。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载
$ git clone https://github.com/postgrespro/pg_pathman.git
$ git branch -a
$ git checkout PGPRO

2.安装
[root@localhost home]# export PATH=/home/postgres:$PATH
[root@localhost home]# cd pg_pathman
[root@localhost pg_pathman]# make USE_PGXS=1
[root@localhost pg_pathman]# make USE_PGXS=1 install
[root@localhost pg_pathman]# cd $PGDATA
[root@leo data]# vi postgresql.conf
        shared_preload_libraries = 'pg_pathman,pg_stat_statements'

3.重启
/usr/local/postgresql-10.5/bin/pg_ctl restart -D /usr/local/pgsql/data/ -m fast

如果报找不到pg_stat_statements:
进入安装的源码包里    /usr/local/postgresql-10.5/contrib/pg_stat_statements/
[postgres@localhost pg_stat_statements]$ make
[postgres@localhost pg_stat_statements]$ make install

可能报错,缺少openssl/ssl ,需要安装openssl-devel
yum install openssl-devel

4.测试
[postgres@localhost pg_stat_statements]$ psql zyx_database
psql (10.5)
Type "help" for help.

zyx_database=# create extension pg_pathman;

5.分区管理(range分区、hash分区)
range分区实验

#创建分区主表
zyx_database=# create table part_test(id int, info text, crt_time timestamp not null);
CREATE TABLE
zyx_database=# insert into part_test select id,md5(random()::text),clock_timestamp() from generate_series(1,10000) t(id);
INSERT 0 10000
zyx_database=# select * from part_test limit 10;
id |               info               |          crt_time          
----+----------------------------------+----------------------------
  1 | ab8e5ee0448a2b4ad61d7e0e767ee1ea | 2019-6-12 16:04:18.294478
  2 | 28a626af632e0ccebbd111a3e1a240e1 | 2019-6-12 16:04:18.294745
  3 | faf2f529a9a83d27b6e13e68ee8e7407 | 2019-6-12 16:04:18.294761
  4 | f4afc8263ea625000305825efff52eaa | 2019-6-12 16:04:18.294768
  5 | 385d942fded21a969f5c0dda64cb1aad | 2019-6-12 16:04:18.294774
  6 | 703f3bee94e322e3234a50cfed01ad24 | 2019-6-12 16:04:18.29478
  7 | 6e28eac2c127263860929b4c24b46a09 | 2019-6-12 16:04:18.294787
  8 | 68b9e8133af0aa1b024aa323ffae0c9c | 2019-6-12 16:04:18.294793
  9 | 58428fa313fc49d13dc14dad18b10fad | 2019-6-12 16:04:18.294799
 10 | cd2cb16088f7304a1f08cd9c9b774fd9 | 2019-6-12 16:04:18.294805
(10 rows)

注意:
   a.分区列必须有NOT NULL约束
   b.分区个数必须能覆盖已有的所有记录
#创建10个分区,每个分区包含一个月的数据
zyx_database=# select create_range_partitions(
'part_test'::regclass, --主表oid
'crt_time',  --分区字段,一定要not null约束
'2019-6-12 00:00:00'::timestamp, --开始时间
interval '1 month',   --分区间隔,一个月
10,  --分区表数量
false  --  不立即将数据从主表迁移到分区
);

执行完会创建10个分区表,然后执行非堵塞迁移。
使用非堵塞式的迁移接口
partition_table_concurrently(relation   REGCLASS,              -- 主表OID
                             batch_size INTEGER DEFAULT 1000,  -- 一个事务批量迁移多少记录
                             sleep_time FLOAT8 DEFAULT 1.0)    -- 获得行锁失败时,休眠多久再次获取,重试60次退出任务。
zyx_database=# select partition_table_concurrently('part_test'::regclass,10000,1.0);

迁移后,查看仅仅存在主表的数据
zyx_database=# select count(*) from only part_test;
 count 
-------
     0
迁移成功!

Q1:
make: warning:  Clock skew detected.  Your build may be incomplete.
解决:
其原因是,当前系统时间还在编译目录中的文件最后修改时间之前,如用date命令查到的是2018年6月12日,而目录文件中最后修改时间为2019年6月12日。
date -s 06/12/2019
date -s 13:12:00

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值