Skip to content

Commit 466c024

Browse files
committed
support pg_readonly and zhparser extension
1 parent 662fb19 commit 466c024

8 files changed

Lines changed: 381 additions & 0 deletions

File tree

CN/modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
*** xref:master/ecosystem_components/pg_profile.adoc[pg_profile]
7171
*** xref:master/ecosystem_components/pg_repack.adoc[pg_repack]
7272
*** xref:master/ecosystem_components/pgdog.adoc[PgDog]
73+
*** xref:master/ecosystem_components/pg_readonly.adoc[pg_readonly]
74+
*** xref:master/ecosystem_components/zhparser.adoc[zhparser]
7375
* 监控运维
7476
** xref:master/getting-started/daily_monitoring.adoc[日常监控]
7577
** xref:master/getting-started/daily_maintenance.adoc[日常维护]

CN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ IvorySQL 作为一款兼容 Oracle 且基于 PostgreSQL 的高级开源数据库
3737
| 24 | xref:master/ecosystem_components/pg_profile.adoc[pg_profile] | 4.11 | 收集数据库资源密集型活动的统计,基于两次采样点的差量分析生成历史负载报告,帮助定位性能瓶颈 | 数据库性能分析
3838
| 25 | xref:master/ecosystem_components/pg_repack.adoc[pg_repack] | 1.5.3 | 在几乎不阻塞业务读写的情况下在线重整表和索引、消除存储膨胀,效果类似 VACUUM FULL | 表与索引在线重建、存储空间回收
3939
| 26 | xref:master/ecosystem_components/pgdog.adoc[PgDog] | 0.1.45 | 专为 PostgreSQL 设计的高性能、开源集群中间件(代理工具),采用 Rust 语言编写 | 自动分片、连接池和负载均衡功能
40+
| 27 | xref:master/ecosystem_components/pg_readonly.adoc[pg_readonly] | 1.0.5 | 可将 PostgreSQL 数据库集群设置为只读 | 系统调试、灾难恢复
41+
| 28 | xref:master/ecosystem_components/zhparser.adoc[zhparser] | master branch | 用于中文全文搜索的PostgreSQL插件,基于SCWS(即:简易中文分词系统)实现了一个中文解析器 | 搜索引擎、关键字提取 |
4042
|====
4143

4244
这些插件均经过 IvorySQL 团队的测试和适配,确保在 IvorySQL 环境下稳定运行。用户可以根据业务需求选择合适的插件,进一步提升数据库系统的能力和灵活性。
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
= pg_readonly
5+
6+
== 概述
7+
pg_readonly 是一个能够将所有 PostgreSQL 的数据库设为只读的插件。
8+
9+
pg_readonly 没有特定的GUC参数,它依靠内存中的全局标志来管理只读状态,并提供了SQL函数来设置或者查询全局标志。
10+
这个全局标志是集群级别的,集群中的数据库要么全部是只读的,要么全部是可读可写的。
11+
12+
只读模式通过过滤SQL语句实现。
13+
[literal]
14+
----
15+
允许不包含有写动作函数的SELECT语句;
16+
DML (INSERT, UPDATE, DELETE) 和 DDL 语句包括 TRUNCATE 完全不允许;
17+
DCL 语句 GRANT 与 REVOKE 也是禁止的;
18+
----
19+
20+
== 安装
21+
22+
[TIP]
23+
源码安装环境为 Ubuntu 24.04(x86_64),环境中已经安装了IvorySQL,安装路径为/path-to/ivorysql
24+
25+
=== 源码安装
26+
27+
[literal]
28+
----
29+
# 从 https://github.com/pierreforstmann/pg_readonly/releases/tag/1.0.5 下载 1.0.5 的源码包 1.0.5.tar.gz
30+
tar xvf 1.0.5.tar.gz
31+
cd pg_readonly-1.0.5
32+
33+
# 编译安装
34+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
35+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
36+
----
37+
38+
=== 配置预加载库
39+
修改 data 目录中的 ivorysql.conf 文件,向 shared_preload_libraries 中追加 pg_readonly。
40+
shared_preload_libraries = 'pg_readonly'
41+
42+
== 创建Extension并确认pg_readonly版本
43+
44+
psql 连接到数据库,执行如下命令:
45+
[literal]
46+
----
47+
ivorysql=# CREATE EXTENSION pg_readonly;
48+
CREATE EXTENSION
49+
50+
ivorysql=# SELECT * FROM pg_available_extensions WHERE name = 'pg_readonly';
51+
name | default_version | installed_version | location | comment
52+
-------------+-----------------+-------------------+----------+----------------------------
53+
pg_readonly | 1.0.4 | 1.0.4 | $system | cluster database read only
54+
(1 row)
55+
----
56+
57+
== 使用
58+
59+
=== 检查单个函数
60+
61+
[literal]
62+
----
63+
-- 查询当前集群只读状态
64+
select get_cluster_readonly();
65+
get_cluster_readonly
66+
----------------------
67+
f
68+
(1 row)
69+
70+
-- 设置当前集群为只读
71+
select set_cluster_readonly();
72+
set_cluster_readonly
73+
----------------------
74+
t
75+
(1 row)
76+
77+
-- 只读的集群只允许 SELECT 语句
78+
select * from t;
79+
x | y
80+
---+---
81+
(0 rows)
82+
83+
update t set x=33 where y='abc';
84+
ERROR: cannot execute UPDATE in a read-only transaction
85+
86+
select 1 into tmp;
87+
ERROR: cannot execute UPDATE in a read-only transaction
88+
89+
create table tmp(c text);
90+
ERROR: cannot execute UPDATE in a read-only transaction
91+
----
92+
93+
更多详细使用方法和高级特性,请参阅 https://github.com/pierreforstmann/pg_readonly [pg_readonly官方文档]。
94+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
= zhparser
5+
6+
== 概述
7+
zhparser 是一个用于中文全文搜索的PostgreSQL插件,它基于SCWS(即:简易中文分词系统)实现了一个中文解析器。
8+
9+
== 安装
10+
11+
[TIP]
12+
源码安装环境为 Ubuntu 24.04(x86_64),环境中已经安装了IvorySQL,安装路径为/path-to/ivorysql
13+
14+
=== 源码安装
15+
16+
[literal]
17+
----
18+
首先安装依赖
19+
20+
wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2
21+
tar xf scws-1.2.3.tar.bz2
22+
cd scws-1.2.3
23+
24+
编译安装scws
25+
./configure
26+
make
27+
sudo make install
28+
29+
# 使用git下载zhparser源代码,使用master分支
30+
git clone https://github.com/amutu/zhparser
31+
cd zhparser
32+
33+
# 编译安装
34+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
35+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
36+
----
37+
38+
== 创建Extension以及全文检索配置,给分词词性绑定词典规则
39+
40+
psql 连接到数据库,执行如下命令:
41+
[literal]
42+
----
43+
-- create the extension
44+
CREATE EXTENSION zhparser;
45+
46+
-- make test configuration using parser
47+
CREATE TEXT SEARCH CONFIGURATION testzhcfg (PARSER = zhparser);
48+
49+
-- add token mapping
50+
ALTER TEXT SEARCH CONFIGURATION testzhcfg ADD MAPPING FOR n,v,a,i,e,l WITH simple;
51+
----
52+
53+
== 使用
54+
55+
[literal]
56+
----
57+
-- ts_parse
58+
ivorysql=# SELECT * FROM ts_parse('zhparser', 'hello world! 2010年保障房建设在全国范围内获全面启动,从中央到地方纷纷加大 了保障房的建设和投入力度 。2011年,保障房进入了更大规模的建设阶段。住房城乡建设部党组书记、部长姜伟新去年底在全国住房城乡建设工作会议上表示,要继续推进保障性安居工程建设。');
59+
tokid | token
60+
-------+----------
61+
101 | hello
62+
101 | world
63+
117 | !
64+
101 | 2010
65+
113 | 年
66+
118 | 保障
67+
110 | 房建
68+
......
69+
70+
-- test to_tsvector
71+
ivorysql=# SELECT to_tsvector('testzhcfg','“今年保障房新开工数量虽然有所下调,但实际的年度在建规模以及竣工规模会超以往年份,相对应的对资金的需求也会 创历>史纪录。”陈国强说。在他看来,与2011年相比,2012年的保障房建设在资金配套上的压力将更为严峻。');
72+
73+
to_tsvector
74+
75+
-----------------------------------------------------------------------------------------------------------------------------------------------------
76+
-----------------------------------------------------------------------------------------------------------------------------------------------------
77+
---------------------------
78+
'2011':27 '2012':29 '上':35 '下调':7 '严峻':37 '会':14 '会创':20 '保障':1,30 '压力':36 '史':21 '国强':24 '在建':10 '实际':8 '对应':17 '年份':16 '年
79+
':9 '开工':4 '房':2 '房建':31 '数量':5 '新':3 '有所':6 '相比':28 '看来':26 '竣工':12 '纪录':22 '规模':11,13 '设在':32 '说':25 '资金':18,33 '超':15 '
80+
套':34 '陈':23 '需求':19
81+
(1 row)
82+
83+
-- test to_tsquery
84+
ivorysql=# SELECT to_tsquery('testzhcfg', '保障房资金压力');
85+
to_tsquery
86+
---------------------------------------
87+
'保障' <-> '房' <-> '资金' <-> '压力'
88+
(1 row)
89+
90+
----
91+
92+
更多详细使用方法和高级特性,请参阅 https://github.com/amutu/zhparser 。
93+

EN/modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
*** xref:master/ecosystem_components/pg_profile.adoc[pg_profile]
7171
*** xref:master/ecosystem_components/pg_repack.adoc[pg_repack]
7272
*** xref:master/ecosystem_components/pgdog.adoc[PgDog]
73+
*** xref:master/ecosystem_components/pg_readonly_en.adoc[pg_readonly]
74+
*** xref:master/ecosystem_components/zhparser_en.adoc[zhparser]
7375
* Monitor and O&M
7476
** xref:master/getting-started/daily_monitoring.adoc[Monitoring]
7577
** xref:master/getting-started/daily_maintenance.adoc[Maintenance]

EN/modules/ROOT/pages/master/ecosystem_components/ecosystem_overview.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ IvorySQL, as an advanced open-source database compatible with Oracle and based o
3838
|*24*| xref:master/ecosystem_components/pg_profile.adoc[pg_profile] | 4.11 | Collects statistics on resource-intensive database activities and generates historic workload reports based on delta analysis between two sample points, helping identify performance bottlenecks | Database performance analysis
3939
|*25*| xref:master/ecosystem_components/pg_repack.adoc[pg_repack] | 1.5.3 | Rebuilds tables and indexes online with minimal locking, eliminating storage bloat and achieving effects similar to VACUUM FULL | Online table and index rebuild, storage bloat reclamation
4040
|*26*| xref:master/ecosystem_components/pgdog.adoc[PgDog] | 0.1.45 | High-performance, open-source clustering middleware (proxy tool) designed specifically for PostgreSQL and written in Rust | Connection pooler, load balancer, distributed database.
41+
|*27*| xref:master/ecosystem_components/pg_readonly.adoc[pg_read_only] | 1.0.5 | allows to set all PostgreSQL cluster databases read only. | system debugging、disaster recevory.
42+
|*28*| xref:master/ecosystem_components/zhparser.adoc[zhparser] | master branch | PostgreSQL extension for full-text search of Chinese language (Mandarin Chinese). It implements a Chinese language parser base on the | search engine、keyword extraction.
4143
|====
4244

4345
These plugins have all been tested and adapted by the IvorySQL team to ensure stable operation in the IvorySQL environment. Users can select appropriate plugins based on business needs to further enhance the capabilities and flexibility of the database system.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
= pg_readonly
5+
6+
== Overview
7+
pg_readonly is a plugin that can set all PostgreSQL databases to read-only mode.
8+
9+
pg_readonly does not have specific GUC parameters. It relies on a global flag in memory to manage the read-only state and provides SQL functions to set or query this global flag.
10+
This global flag is cluster-level: either all databases in the cluster are read-only, or all are read-write.
11+
12+
Read-only mode is implemented by filtering SQL statements.
13+
[literal]
14+
----
15+
SELECT statements without write-operation functions are allowed;
16+
DML (INSERT, UPDATE, DELETE) and DDL statements including TRUNCATE are completely disallowed;
17+
DCL statements GRANT and REVOKE are also prohibited;
18+
----
19+
20+
== Installation
21+
22+
[TIP]
23+
The source installation environment is Ubuntu 24.04 (x86_64), with IvorySQL already installed at /path-to/ivorysql
24+
25+
=== Source Installation
26+
27+
[literal]
28+
----
29+
# Download the 1.0.5 source package 1.0.5.tar.gz from https://github.com/pierreforstmann/pg_readonly/releases/tag/1.0.5
30+
tar xvf 1.0.5.tar.gz
31+
cd pg_readonly-1.0.5
32+
33+
# Compile and install
34+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
35+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
36+
----
37+
38+
=== Configure Preloaded Libraries
39+
Modify the ivorysql.conf file in the data directory to append pg_readonly to shared_preload_libraries.
40+
shared_preload_libraries = 'pg_readonly'
41+
42+
== Create Extension and Verify pg_readonly Version
43+
44+
Connect to the database using psql and execute the following commands:
45+
[literal]
46+
----
47+
ivorysql=# CREATE EXTENSION pg_readonly;
48+
CREATE EXTENSION
49+
50+
ivorysql=# SELECT * FROM pg_available_extensions WHERE name = 'pg_readonly';
51+
name | default_version | installed_version | location | comment
52+
-------------+-----------------+-------------------+----------+----------------------------
53+
pg_readonly | 1.0.4 | 1.0.4 | $system | cluster database read only
54+
(1 row)
55+
----
56+
57+
== Usage
58+
59+
=== Check Individual Functions
60+
61+
[literal]
62+
----
63+
-- Query the current cluster read-only status
64+
select get_cluster_readonly();
65+
get_cluster_readonly
66+
----------------------
67+
f
68+
(1 row)
69+
70+
-- Set the current cluster to read-only mode
71+
select set_cluster_readonly();
72+
set_cluster_readonly
73+
----------------------
74+
t
75+
(1 row)
76+
77+
-- Read-only cluster only allows SELECT statements
78+
select * from t;
79+
x | y
80+
---+---
81+
(0 rows)
82+
83+
update t set x=33 where y='abc';
84+
ERROR: cannot execute UPDATE in a read-only transaction
85+
86+
select 1 into tmp;
87+
ERROR: cannot execute UPDATE in a read-only transaction
88+
89+
create table tmp(c text);
90+
ERROR: cannot execute UPDATE in a read-only transaction
91+
----
92+
93+
For more detailed usage and advanced features, please refer to the https://github.com/pierreforstmann/pg_readonly [official pg_readonly documentation].
94+

0 commit comments

Comments
 (0)