当前位置:   article > 正文

pg_partman_怎么下载partman

怎么下载partman

os: centos 7.4
db: postgresql 11.6

之前分区组件一直使用的 pg_pathman,今天在看 citus 的文档时发现还有个 pg_partman 组件

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
# 
# yum list installed |grep -i postgresql
postgresql11.x86_64                11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-contrib.x86_64        11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-debuginfo.x86_64      11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-devel.x86_64          11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-docs.x86_64           11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-libs.x86_64           11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-llvmjit.x86_64        11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-odbc.x86_64           12.00.0000-1PGDG.rhel7              @pgdg11  
postgresql11-plperl.x86_64         11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-plpython.x86_64       11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-pltcl.x86_64          11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-server.x86_64         11.6-2PGDG.rhel7                    @pgdg11  
postgresql11-tcl.x86_64            2.4.0-2.rhel7.1                     @pgdg11  
postgresql11-test.x86_64           11.6-2PGDG.rhel7                    @pgdg11
# 
# su - postgres
Last login: Mon Dec 16 20:13:53 CST 2019 on pts/0
-bash-4.2$ psql
psql (11.6)
Type "help" for help.

postgres=# select version();
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 11.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)

postgres=#

  • 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

下载、安装、编译

使用的是 yum 方式安装的 postgresql,所以使用 root 用户安装(或者 postgres 用户使用 sudo)

# cd /var/lib/pgsql/
# wget https://github.com/pgpartman/pg_partman/archive/v4.2.2.tar.gz
# tar -zxvf ./v4.2.2.tar.gz
# ls -l
total 2552
drwxr-xr-x  8 root root     211 Oct 16 21:43 pg_partman-4.2.2

# cd pg_partman-4.2.2/
# make
/bin/sh: pg_config: command not found
/bin/sh: pg_config: command not found
make: pg_config: Command not found
make: *** No rule to make target `install'.  Stop.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

pg_config 不在 PATH下

# export PATH=/usr/pgsql-11/bin:${PATH}
# which pg_config
/usr/pgsql-11/bin/pg_config

# make

/opt/rh/llvm-toolset-7/root/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -O2  -I. -I./ -I/usr/pgsql-11/include/server -I/usr/pgsql-11/include/internal  -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include -flto=thin -emit-llvm -c -o src/pg_partman_bgw.bc src/pg_partman_bgw.c
make: /opt/rh/llvm-toolset-7/root/usr/bin/clang: Command not found
make: *** [src/pg_partman_bgw.bc] Error 127

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

报错 /opt/rh/llvm-toolset-7/root/usr/bin/clang: Command not found 需要按照如下方式解决

<</opt/rh/llvm-toolset-7/root/usr/bin/clang: Command not found>>

再次编译安装

# make

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -I. -I./ -I/usr/pgsql-11/include/server -I/usr/pgsql-11/include/internal  -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include  -c -o src/pg_partman_bgw.o src/pg_partman_bgw.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -L/usr/pgsql-11/lib -Wl,--as-needed -L/usr/lib64/llvm5.0/lib  -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-11/lib',--enable-new-dtags  -shared -o src/pg_partman_bgw.so src/pg_partman_bgw.o
/opt/rh/llvm-toolset-7/root/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -O2  -I. -I./ -I/usr/pgsql-11/include/server -I/usr/pgsql-11/include/internal  -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include -flto=thin -emit-llvm -c -o src/pg_partman_bgw.bc src/pg_partman_bgw.c

# make install

/bin/mkdir -p '/usr/pgsql-11/share/extension'
/bin/mkdir -p '/usr/pgsql-11/share/extension'
/bin/mkdir -p '/usr/pgsql-11/lib'
/bin/mkdir -p '/usr/pgsql-11/doc/extension'
/bin/mkdir -p '/usr/pgsql-11/bin'
/bin/install -c -m 644 .//pg_partman.control '/usr/pgsql-11/share/extension/'
/bin/install -c -m 644 .//updates/pg_partman--2.5.0--2.5.1.sql .//updates/pg_partman--2.3.2--2.3.3.sql .//updates/pg_partman--2.6.2--2.6.3.sql .//updates/pg_partman--4.1.0--4.2.0.sql .//updates/pg_partman--2.2.1--2.2.2.sql .//updates/pg_partman--1.8.7--2.0.0.sql .//updates/pg_partman--2.2.3--2.3.0.sql .//updates/pg_partman--1.8.0--1.8.1.sql .//updates/pg_partman--2.0.0--2.1.0.sql .//updates/pg_partman--2.2.0--2.2.1.sql .//updates/pg_partman--1.3.0--1.4.0.sql .//updates/pg_partman--2.3.3--2.3.4.sql .//updates/pg_partman--4.2.1--4.2.2.sql .//updates/pg_partman--1.8.2--1.8.3.sql .//updates/pg_partman--1.8.1--1.8.2.sql .//updates/pg_partman--1.7.0--1.7.1.sql .//updates/pg_partman--1.1.0--1.2.0.sql .//updates/pg_partman--2.5.1--2.6.0.sql .//updates/pg_partman--0.1.2--0.2.0.sql .//updates/pg_partman--2.3.0--2.3.1.sql .//updates/pg_partman--3.0.2--3.1.0.sql .//updates/pg_partman--0.3.1--0.3.2.sql .//updates/pg_partman--0.2.0--0.3.0.sql .//updates/pg_partman--3.2.0--3.2.1.sql .//updates/pg_partman--1.7.1--1.7.2.sql .//updates/pg_partman--2.3.4--2.4.0.sql .//updates/pg_partman--0.3.0--0.3.1.sql .//updates/pg_partman--4.2.0--4.2.1.sql .//updates/pg_partman--1.4.5--1.5.0.sql .//updates/pg_partman--3.0.1--3.0.2.sql .//updates/pg_partman--1.8.8--2.0.0.sql .//updates/pg_partman--1.5.0--1.5.1.sql .//updates/pg_partman--3.1.1--3.1.2.sql .//updates/pg_partman--1.2.0--1.3.0.sql .//updates/pg_partman--1.4.3--1.4.4.sql .//updates/pg_partman--3.0.0--3.0.1.sql .//updates/pg_partman--1.8.6--1.8.7.sql .//updates/pg_partman--3.1.0--3.1.1.sql .//updates/pg_partman--2.4.0--2.4.1.sql .//updates/pg_partman--1.7.2--1.8.0.sql .//updates/pg_partman--3.1.2--3.1.3.sql .//updates/pg_partman--0.4.1--0.4.2.sql .//updates/pg_partman--1.5.1--1.6.0.sql .//updates/pg_partman--2.6.4--3.0.0.sql .//updates/pg_partman--3.2.1--4.0.0.sql .//updates/pg_partman--2.3.1--2.3.2.sql .//updates/pg_partman--0.1.1--0.1.2.sql .//updates/pg_partman--0.4.0--0.4.1.sql .//updates/pg_partman--1.8.7--1.8.8.sql .//updates/pg_partman--2.6.3--2.6.4.sql .//updates/pg_partman--0.1.0--0.1.1.sql .//updates/pg_partman--1.0.0--1.1.0.sql .//updates/pg_partman--1.6.1--1.7.0.sql .//updates/pg_partman--1.4.4--1.4.5.sql .//updates/pg_partman--1.8.4--1.8.5.sql .//updates/pg_partman--2.4.1--2.5.0.sql .//updates/pg_partman--0.3.2--0.4.0.sql .//updates/pg_partman--2.1.0--2.2.0.sql .//updates/pg_partman--1.6.0--1.6.1.sql .//updates/pg_partman--1.4.1--1.4.2.sql .//updates/pg_partman--1.4.2--1.4.3.sql .//updates/pg_partman--4.0.0--4.1.0.sql .//updates/pg_partman--1.8.3--1.8.4.sql .//updates/pg_partman--3.1.3--3.2.0.sql .//updates/pg_partman--2.2.2--2.2.3.sql .//updates/pg_partman--1.4.0--1.4.1.sql .//updates/pg_partman--2.6.1--2.6.2.sql .//updates/pg_partman--0.4.2--1.0.0.sql .//updates/pg_partman--1.8.5--1.8.6.sql .//updates/pg_partman--2.6.0--2.6.1.sql .//sql/pg_partman--4.2.2.sql  '/usr/pgsql-11/share/extension/'
/bin/install -c -m 755  src/pg_partman_bgw.so '/usr/pgsql-11/lib/'
/bin/mkdir -p '/usr/pgsql-11/lib/bitcode/src/pg_partman_bgw'
/bin/mkdir -p '/usr/pgsql-11/lib/bitcode'/src/pg_partman_bgw/src/
/bin/install -c -m 644 src/pg_partman_bgw.bc '/usr/pgsql-11/lib/bitcode'/src/pg_partman_bgw/src/
cd '/usr/pgsql-11/lib/bitcode' && /usr/lib64/llvm5.0/bin/llvm-lto -thinlto -thinlto-action=thinlink -o src/pg_partman_bgw.index.bc src/pg_partman_bgw/src/pg_partman_bgw.bc
/bin/install -c -m 644 .//doc/migration_to_partman.md .//doc/pg_partman.md .//doc/pg_partman_howto.md '/usr/pgsql-11/doc/extension/'
/bin/install -c -m 755 .//bin/common/*.py '/usr/pgsql-11/bin/'

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

查看生成的文件

# ls -l /usr/pgsql-11/lib |grep -i pg_part
-rwxr-xr-x   1 root     root       59112 Dec 18 09:51 pg_partman_bgw.so

# ls -l /usr/pgsql-11/share/extension/ |grep -i pg_part

-rw-r--r--  1 root root 135485 Dec 18 09:51 pg_partman--4.0.0--4.1.0.sql
-rw-r--r--  1 root root 120577 Dec 18 09:51 pg_partman--4.1.0--4.2.0.sql
-rw-r--r--  1 root root  13967 Dec 18 09:51 pg_partman--4.2.0--4.2.1.sql
-rw-r--r--  1 root root   9194 Dec 18 09:51 pg_partman--4.2.1--4.2.2.sql
-rw-r--r--  1 root root 310105 Dec 18 09:51 pg_partman--4.2.2.sql
-rw-r--r--  1 root root    111 Dec 18 09:51 pg_partman.control

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

使用

# vi /var/lib/pgsql/11/data/postgresql.conf 

shared_preload_libraries = 'pg_partman_bgw' 


# systemctl restart postgresql-11.service

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
# su - postgres
$ psql

postgres=# select * from pg_available_extensions where name like 'pg_part%';
    name    | default_version | installed_version |                       comment                        
------------+-----------------+-------------------+------------------------------------------------------
 pg_partman | 4.2.2           |                   | Extension to manage partitioned tables by time or ID
(1 row)

postgres=# create extension pg_partman;
CREATE EXTENSION
postgres=# \dx
                               List of installed extensions
    Name    | Version |   Schema   |                     Description                      
------------+---------+------------+------------------------------------------------------
 pg_partman | 4.2.2   | public     | Extension to manage partitioned tables by time or ID
 plpgsql    | 1.0     | pg_catalog | PL/pgSQL procedural language
(2 rows)

postgres=# \dx+ pg_partman
                                             Objects in extension "pg_partman"
                                                     Object description                                                     
----------------------------------------------------------------------------------------------------------------------------
 function apply_cluster(text,text,text,text)
 function apply_constraints(text,text,boolean,bigint,boolean)
 function apply_foreign_keys(text,text,bigint,boolean)
 function apply_privileges(text,text,text,text,bigint)
 function apply_publications(text,text,text)
 function autovacuum_off(text,text,text,text)
 function autovacuum_reset(text,text,text,text)
 function check_automatic_maintenance_value(text)
 function check_control_type(text,text,text)
 function check_default(boolean)
 function check_epoch_type(text)
 function check_name_length(text,text,boolean)
 function check_partition_type(text)
 function check_subpartition_limits(text,text)
 function check_subpart_sameconfig(text)
 function create_function_id(text,bigint)
 function create_function_time(text,bigint)
 function create_parent(text,text,text,text,text[],integer,text,text,boolean,text,text,text[],boolean,text,boolean,boolean)
 function create_partition_id(text,bigint[],boolean,boolean)
 function create_partition_time(text,timestamp with time zone[],boolean,boolean)
 function create_sub_parent(text,text,text,text,text,text[],integer,text,boolean,text,text,boolean,boolean,boolean)
 function create_trigger(text)
 function drop_constraints(text,text,boolean)
 function drop_partition_column(text,text)
 function drop_partition_id(text,bigint,boolean,boolean,text)
 function drop_partition_time(text,interval,boolean,boolean,text)
 function inherit_template_properties(text,text,text)
 function partition_data_id(text,integer,bigint,numeric,text,boolean,text)
 function partition_data_proc(text,text,integer,integer,text,text,integer,integer,boolean)
 function partition_data_time(text,integer,interval,numeric,text,boolean,text)
 function reapply_constraints_proc(text,boolean,boolean,integer,boolean)
 function reapply_privileges(text)
 function run_maintenance_proc(integer,boolean,boolean,boolean)
 function run_maintenance(text,boolean,boolean,boolean)
 function show_partition_info(text,text,text)
 function show_partition_name(text,text)
 function show_partitions(text,text,boolean)
 function stop_sub_partition(text,boolean)
 function undo_partition_proc(text,text,integer,integer,text,boolean,integer,integer,boolean)
 function undo_partition(text,integer,text,boolean,numeric,text)
 table custom_time_partitions
 table part_config
 table part_config_sub
 type check_default_table
 view table_privs
(45 rows)

postgres=# select name,setting from pg_settings where name like 'pg_part%';
          name           | setting  
-------------------------+----------
 pg_partman_bgw.analyze  | off
 pg_partman_bgw.dbname   | 
 pg_partman_bgw.interval | 3600
 pg_partman_bgw.jobmon   | on
 pg_partman_bgw.role     | postgres
(5 rows)

  • 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
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80

具体使用仔细阅读 <<Example Guide On Setting Up Trigger-based Partitioning>>

发现是通过触发器来实现的,这是在 pgsql 10 之前的分区实现方式,效率较低。总之感觉没有 pg_pathman 好用。

If you’re using the Background Worker (BGW), set the pg_partman_bgw.interval value in postgresql.conf. This example sets it to run every 12 hrs (43200 seconds). See the doc/pg_partman.md file for more information on the BGW settings.

参考:
https://github.com/pgpartman/pg_partman
https://github.com/pgpartman/pg_partman/blob/master/doc/pg_partman.md
https://github.com/pgpartman/pg_partman/blob/master/doc/pg_partman_howto.md

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号