Skip to content

Commit d97cf1e

Browse files
authored
Merge branch 'IvorySQL:master' into master
2 parents a516a5f + f8940b6 commit d97cf1e

10 files changed

Lines changed: 1385 additions & 1 deletion

File tree

CN/modules/ROOT/nav.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
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]
75+
*** xref:master/ecosystem_components/pgbackrest.adoc[pgBackRest]
7376
* 监控运维
7477
** xref:master/getting-started/daily_monitoring.adoc[日常监控]
7578
** xref:master/getting-started/daily_maintenance.adoc[日常维护]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ 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(即:简易中文分词系统)实现了一个中文解析器 | 搜索引擎、关键字提取
42+
| 29 | xref:master/ecosystem_components/pgbackrest.adoc[pgBackRest] | 2.58.0 | 可靠的 PostgreSQL 备份和恢复解决方案 | 容灾备份、大库备份、异地/多层容灾
4043
|====
4144

4245
这些插件均经过 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.6 下载 1.0.6 的源码包 1.0.6.tar.gz
30+
tar xvf 1.0.6.tar.gz
31+
cd pg_readonly-1.0.6
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.6 | 1.0.6 | $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 。
94+

0 commit comments

Comments
 (0)