Skip to content

Commit 7f968f0

Browse files
committed
new doc
1 parent 63126ee commit 7f968f0

File tree

9 files changed

+806
-3
lines changed

9 files changed

+806
-3
lines changed

201607/20160725_02.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 如何加快PostgreSQL结巴分词加载速度
1+
## 如何加快PostgreSQL结巴分词pg_jieba加载速度
22
33
### 作者
44
digoal

201607/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
##### 20160725_05.md [《PostgreSQL 如何高效解决 按任意字段分词检索的问题 - case 1》](20160725_05.md)
1717
##### 20160725_04.md [《PostgreSQL Oracle 兼容性之 - 锁定执行计划(Outline system)》](20160725_04.md)
1818
##### 20160725_03.md [《mongoDB BI 分析利器 - PostgreSQL FDW (MongoDB Connector for BI)》](20160725_03.md)
19-
##### 20160725_02.md [如何加快PostgreSQL结巴分词加载速度](20160725_02.md)
19+
##### 20160725_02.md [如何加快PostgreSQL结巴分词pg_jieba加载速度](20160725_02.md)
2020
##### 20160725_01.md [《PostgreSQL 使用递归SQL 找出数据库对象之间的依赖关系》](20160725_01.md)
2121
##### 20160723_03.md [《一致性哈希在分布式数据库中的应用探索》](20160723_03.md)
2222
##### 20160723_02.md [《关键时刻HINT出彩 - PG优化器的参数优化、执行计划固化CASE》](20160723_02.md)

201804/20180408_01.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
## PostgreSQL 11 preview - Logical replication support for TRUNCATE
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2018-04-08
8+
9+
### 标签
10+
PostgreSQL , 逻辑订阅 , TRUNCATE
11+
12+
----
13+
14+
## 背景
15+
PostgreSQL 11 逻辑订阅支持insert, update, delete, truncate。
16+
17+
后期可能还会增加对DDL的支持,目前的DDL(包括对已有订阅表的结构修改,新增,删除表等操作)通过如下方法来支持:
18+
19+
[《PostgreSQL 逻辑订阅 - DDL 订阅 实现方法》](../201712/20171204_04.md)
20+
21+
22+
支持TRUNCATE的PATCH如下
23+
24+
```
25+
Logical replication support for TRUNCATE
26+
27+
author Peter Eisentraut <[email protected]>
28+
Sat, 7 Apr 2018 23:24:53 +0800 (11:24 -0400)
29+
committer Peter Eisentraut <[email protected]>
30+
Sat, 7 Apr 2018 23:34:11 +0800 (11:34 -0400)
31+
commit 039eb6e92f20499ac36cc74f8a5cef7430b706f6
32+
tree 2cf52aeafb59917d5c7ed396acb6d86325b4a8b0 tree | snapshot
33+
parent 5dfd1e5a6696b271a2cdee54143fbc209c88c02f commit | diff
34+
35+
Logical replication support for TRUNCATE
36+
37+
Update the built-in logical replication system to make use of the
38+
previously added logical decoding for TRUNCATE support. Add the
39+
required truncate callback to pgoutput and a new logical replication
40+
protocol message.
41+
42+
Publications get a new attribute to determine whether to replicate
43+
truncate actions. When updating a publication via pg_dump from an older
44+
version, this is not set, thus preserving the previous behavior.
45+
46+
Author: Simon Riggs <[email protected]>
47+
Author: Marco Nenciarini <[email protected]>
48+
Author: Peter Eisentraut <[email protected]>
49+
Reviewed-by: Petr Jelinek <[email protected]>
50+
Reviewed-by: Andres Freund <[email protected]>
51+
Reviewed-by: Alvaro Herrera <[email protected]>
52+
```
53+
54+
```
55+
WITH ( publication_parameter [= value] [, ... ] )
56+
57+
This clause specifies optional parameters for a publication. The following parameters are supported:
58+
59+
publish (string)
60+
61+
This parameter determines which DML operations will be published by the new publication to the subscribers. The value is comma-separated list of operations. The allowed operations are insert, update, delete, and truncate. The default is to publish all actions, and so the default value for this option is 'insert, update, delete, truncate'.
62+
```
63+
64+
```
65+
CREATE PUBLICATION insert_only FOR TABLE mydata
66+
WITH (publish = 'insert');
67+
```
68+
69+
```
70+
+ List of publications
71+
+ Name | Owner | All tables | Inserts | Updates | Deletes | Truncates
72+
+--------------------+--------------------------+------------+---------+---------+---------+-----------
73+
+ testpib_ins_trunct | regress_publication_user | f | t | f | f | f
74+
+ testpub_default | regress_publication_user | f | f | t | f | f
75+
(2 rows)
76+
77+
78+
+ List of publications
79+
+ Name | Owner | All tables | Inserts | Updates | Deletes | Truncates
80+
+--------------------+--------------------------+------------+---------+---------+---------+-----------
81+
+ testpib_ins_trunct | regress_publication_user | f | t | f | f | f
82+
+ testpub_default | regress_publication_user | f | t | t | t | f
83+
(2 rows)
84+
85+
86+
+ Publication testpub_foralltables
87+
+ Owner | All tables | Inserts | Updates | Deletes | Truncates
88+
+--------------------------+------------+---------+---------+---------+-----------
89+
+ regress_publication_user | t | t | t | f | f
90+
(1 row)
91+
92+
93+
+ Publication testpub3
94+
+ Owner | All tables | Inserts | Updates | Deletes | Truncates
95+
+--------------------------+------------+---------+---------+---------+-----------
96+
+ regress_publication_user | f | t | t | t | t
97+
98+
99+
+ Publication testpub4
100+
+ Owner | All tables | Inserts | Updates | Deletes | Truncates
101+
+--------------------------+------------+---------+---------+---------+-----------
102+
+ regress_publication_user | f | t | t | t | t
103+
```
104+
105+
106+
107+
## 参考
108+
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=039eb6e92f20499ac36cc74f8a5cef7430b706f6
109+
110+
https://www.postgresql.org/docs/devel/static/sql-createpublication.html
111+
112+
https://www.postgresql.org/docs/devel/static/sql-alterpublication.html
113+
114+
115+
116+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
117+

201804/20180408_02.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
## PostgreSQL Oracle 兼容性之 - ALTER TRIGGER ENABLE|DISABLE
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2018-04-08
8+
9+
### 标签
10+
PostgreSQL , 触发器 , enable , disable
11+
12+
----
13+
14+
## 背景
15+
Oracle 临时关闭或启用触发器的语法如下
16+
17+
https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4001.htm
18+
19+
```
20+
ALTER TRIGGER [ schema. ]trigger
21+
{ ENABLE
22+
| DISABLE
23+
| RENAME TO new_name
24+
| COMPILE [ DEBUG ]
25+
[ compiler_parameters_clause
26+
[ compiler_parameters_clause ] ... ]
27+
[ REUSE SETTINGS ]
28+
} ;
29+
```
30+
31+
## PostgreSQL 触发器开关语法更丰富一些
32+
PostgreSQL中对应的语法在alter table中,因为触发器与表相关,这样设计语法也符合逻辑的。
33+
34+
https://www.postgresql.org/docs/devel/static/sql-altertable.html
35+
36+
```
37+
ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
38+
action [, ... ]
39+
40+
DISABLE TRIGGER [ trigger_name | ALL | USER ]
41+
ENABLE TRIGGER [ trigger_name | ALL | USER ]
42+
43+
ENABLE REPLICA TRIGGER trigger_name
44+
ENABLE ALWAYS TRIGGER trigger_name
45+
```
46+
47+
细节(注意触发器被触发还受制于session_replication_role参数与replica|always的配置。)
48+
49+
These forms configure the firing of trigger(s) belonging to the table. A disabled trigger is still known to the system, but is not executed when its triggering event occurs. For a deferred trigger, the enable status is checked when the event occurs, not when the trigger function is actually executed. One can disable or enable a single trigger specified by name, or all triggers on the table, or only user triggers (this option excludes internally generated constraint triggers such as those that are used to implement foreign key constraints or deferrable uniqueness and exclusion constraints). Disabling or enabling internally generated constraint triggers requires superuser privileges; it should be done with caution since of course the integrity of the constraint cannot be guaranteed if the triggers are not executed.
50+
51+
The trigger firing mechanism is also affected by the configuration variable session_replication_role. Simply enabled triggers (the default) will fire when the replication role is “origin” (the default) or “local”. Triggers configured as ENABLE REPLICA will only fire if the session is in “replica” mode, and triggers configured as ENABLE ALWAYS will fire regardless of the current replication role.
52+
53+
The effect of this mechanism is that in the default configuration, triggers do not fire on replicas. This is useful because if a trigger is used on the origin to propagate data between tables, then the replication system will also replicate the propagated data, and the trigger should not fire a second time on the replica, because that would lead to duplication. However, if a trigger is used for another purpose such as creating external alerts, then it might be appropriate to set it to ENABLE ALWAYS so that it is also fired on replicas.
54+
55+
This command acquires a SHARE ROW EXCLUSIVE lock.
56+
57+
58+
trigger_name
59+
60+
Name of a single trigger to disable or enable.
61+
62+
ALL
63+
64+
Disable or enable all triggers belonging to the table. (This requires superuser privilege if any of the triggers are internally generated constraint triggers such as those that are used to implement foreign key constraints or deferrable uniqueness and exclusion constraints.)
65+
66+
USER
67+
68+
Disable or enable all triggers belonging to the table except for internally generated constraint triggers such as those that are used to implement foreign key constraints or deferrable uniqueness and exclusion constraints.
69+
70+
(内部用于foreign key, unique, 排他 等约束的触发器除外)
71+
72+
关闭或开启指定或所有表,或者某个用户,某个schema下的所有表的触发器。
73+
74+
使用函数,参考:
75+
76+
https://stackoverflow.com/questions/3942258/how-do-i-temporarily-disable-triggers-in-postgresql
77+
78+
```
79+
For example if you have tables in a particular namespace it could be:
80+
81+
create or replace function disable_triggers(a boolean, nsp character varying) returns void as
82+
$$
83+
declare
84+
act character varying;
85+
r record;
86+
begin
87+
if(a is true) then
88+
act = 'disable';
89+
else
90+
act = 'enable';
91+
end if;
92+
93+
for r in select c.relname from pg_namespace n
94+
join pg_class c on c.relnamespace = n.oid and c.relhastriggers = true
95+
where n.nspname = nsp
96+
loop
97+
execute format('alter table %I %s trigger all', r.relname, act);
98+
end loop;
99+
end;
100+
$$
101+
language plpgsql;
102+
If you want to disable all triggers with certain trigger function it could be:
103+
104+
create or replace function disable_trigger_func(a boolean, f character varying) returns void as
105+
$$
106+
declare
107+
act character varying;
108+
r record;
109+
begin
110+
if(a is true) then
111+
act = 'disable';
112+
else
113+
act = 'enable';
114+
end if;
115+
116+
for r in select c.relname from pg_proc p
117+
join pg_trigger t on t.tgfoid = p.oid
118+
join pg_class c on c.oid = t.tgrelid
119+
where p.proname = f
120+
loop
121+
execute format('alter table %I %s trigger all', r.relname, act);
122+
end loop;
123+
end;
124+
$$
125+
language plpgsql;
126+
127+
also dosent work for me in Postgres 9.1. i use the two function described by bartolo-otrit with some modification. I modified the first function to make it work for me because the namespace or the schema must be present to identify the table correctly. The new code is :
128+
129+
CREATE OR REPLACE FUNCTION disable_triggers(a boolean, nsp character varying)
130+
RETURNS void AS
131+
$BODY$
132+
declare
133+
act character varying;
134+
r record;
135+
begin
136+
if(a is true) then
137+
act = 'disable';
138+
else
139+
act = 'enable';
140+
end if;
141+
142+
for r in select c.relname from pg_namespace n
143+
join pg_class c on c.relnamespace = n.oid and c.relhastriggers = true
144+
where n.nspname = nsp
145+
loop
146+
execute format('alter table %I.%I %s trigger all', nsp,r.relname, act);
147+
end loop;
148+
end;
149+
$BODY$
150+
LANGUAGE plpgsql VOLATILE
151+
COST 100;
152+
ALTER FUNCTION disable_triggers(boolean, character varying)
153+
OWNER TO postgres;
154+
then i simply do a select query for every schema :
155+
156+
SELECT disable_triggers(true,'public');
157+
SELECT disable_triggers(true,'Adempiere');
158+
```
159+
160+
## 参考
161+
162+
https://www.postgresql.org/docs/devel/static/sql-altertable.html
163+
164+
https://www.postgresql.org/docs/devel/static/runtime-config-client.html#GUC-SESSION-REPLICATION-ROLE
165+
166+
https://stackoverflow.com/questions/3942258/how-do-i-temporarily-disable-triggers-in-postgresql
167+
168+
[《PostgreSQL rotate table 自动清理调度 - 约束,触发器》](../201803/20180311_06.md)
169+
170+
[《PostgreSQL 事件触发器应用 - DDL审计记录 + 异步通知(notify)》](../201709/20170925_02.md)
171+
172+
[《数据入库实时转换 - trigger , rule》](../201706/20170619_02.md)
173+
174+
[《(流式、lambda、触发器)实时处理大比拼 - 物联网(IoT)\金融,时序处理最佳实践》](../201705/20170518_01.md)
175+
176+
[《快速入门PostgreSQL应用开发与管理 - 7 函数、存储过程和触发器》](../201704/20170412_02.md)
177+
178+
[《PostgreSQL 10.0 preview 功能增强 - 触发器函数内置中间表》](../201704/20170401_01.md)
179+
180+
[《PostgreSQL 安全陷阱 - 利用触发器或规则,结合security invoker函数制造反噬陷阱》](../201509/20150929_01.md)
181+
182+
[《use PostgreSQL trigger manage stock & offer infomation》](../201507/20150717_03.md)
183+
184+
[《PostgreSQL trigger/rule based replication configure, DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER | RULE》](../201506/20150615_01.md)
185+
186+
[《PostgreSQL Oracle 兼容性之 - 事件触发器实现类似Oracle的回收站功能》](../201504/20150429_01.md)
187+
188+
[《PostgreSQL 触发器应用 - use trigger audit record which column modified, insert, delete.》](../201412/20141214_01.md)
189+
190+
[《use event trigger function record user who alter table's SQL》](../201412/20141211_02.md)
191+
192+
[《PostgreSQL 事件触发器 - DDL审计 , DDL逻辑复制 , 打造DDL统一管理入》](../201412/20141211_01.md)
193+
194+
[《PostgreSQL 触发器应用 - (触发器WHEN)前置条件过滤跟踪目标记录》](../201409/20140917_01.md)
195+
196+
[《PostgreSQL 闪回 - flash back query emulate by trigger》](../201408/20140828_01.md)
197+
198+
[《PostgreSQL 事件触发器 - PostgreSQL 9.3 Event Trigger》](../201303/20130313_01.md)
199+
200+
[《表级复制(base on trigger) -- PostgreSQL general sync and async multi-master replication trigger function》](../201303/20130311_03.md)
201+
202+
[《PostgreSQL 触发器 用法详解 2》](../201303/20130311_02.md)
203+
204+
[《PostgreSQL 触发器 用法详解 1》](../201303/20130311_01.md)
205+
206+
[《递归优化CASE - performance tuning case :use cursor\trigger\recursive replace (group by and order by) REDUCE needed blockes scan》](../201209/20120914_01.md)
207+
208+
[《PostgreSQL general public partition table trigger》](../201209/20120907_01.md)
209+
210+
[《表级复制(base on trigger) -- multi master replication & performance tuning》](../201208/20120831_02.md)
211+
212+
[《表级复制(base on trigger) -- one(rw) to many(ro|rw)》](../201208/20120831_01.md)
213+
214+
[《PostgreSQL 跟踪DDL时间 - cann't use pg_class's trigger trace user_table's create,modify,delete Time》](../201206/20120626_01.md)
215+
216+
<a rel="nofollow" href="http://info.flagcounter.com/h9V1" ><img src="http://s03.flagcounter.com/count/h9V1/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_12/viewers_0/labels_0/pageviews_0/flags_0/" alt="Flag Counter" border="0" ></a>
217+

0 commit comments

Comments
 (0)