Skip to content

Commit 9fe00d8

Browse files
committed
support pgtt in V5.4
1 parent d29e6bd commit 9fe00d8

6 files changed

Lines changed: 247 additions & 0 deletions

File tree

CN/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
*** xref:5.8.adoc[pgaudit]
5252
*** xref:5.9.adoc[pgrouting]
5353
*** xref:5.10.adoc[system_stats]
54+
*** xref:5.11.adoc[pgtt]
5455
* 监控运维
5556
** xref:3.2.adoc[日常监控]
5657
** xref:3.3.adoc[日常维护]

CN/modules/ROOT/pages/5.0.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ IvorySQL 作为一款兼容 Oracle 且基于 PostgreSQL 的高级开源数据库
2121
| 8 | xref:5.8.adoc[pgaudit] | 18.0 | 提供细粒度的审计功能,记录数据库操作日志,便于安全审计和合规性检查 | 数据库安全审计、合规性检查、审计报告生成
2222
| 9 | xref:5.9.adoc[pgrouting] | 3.8.0 | 提供地理空间数据的路由计算功能,支持多种算法和数据格式 | 地理空间分析、路径规划、物流优化
2323
| 10 | xref:5.10.adoc[system_stats] | 3.2 | 提供用于访问系统级统计信息的函数 | 系统监控
24+
| 11 | xref:5.11.adoc[pgtt] | 4.5 | 创建、管理与使用Oracle风格临时表 | 业务开发
2425
|====
2526

2627
这些插件均经过 IvorySQL 团队的测试和适配,确保在 IvorySQL 环境下稳定运行。用户可以根据业务需求选择合适的插件,进一步提升数据库系统的能力和灵活性。

CN/modules/ROOT/pages/5.11.adoc

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
= pgtt
5+
6+
== 概述
7+
pgtt 是一个创建、管理与使用Oracle风格临时表的PostgreSQL插件。这个插件的目标是在PG内核实现临时表之前提供类似特性。
8+
9+
== 安装
10+
11+
[TIP]
12+
源码安装环境为 Ubuntu 24.04(x86_64),环境中已经安装了IvorySQL,安装路径为/path-to/ivorysql
13+
14+
=== 源码安装
15+
16+
[literal]
17+
----
18+
# 下载pgtt源代码
19+
wget https://github.com/darold/pgtt/archive/refs/tags/v4.5.tar.gz
20+
tar zxvf v4.5.tar.gz
21+
cd pgtt-4.5
22+
23+
# 编译安装
24+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
25+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
26+
----
27+
28+
== 创建Extension
29+
30+
psql 连接到数据库,执行如下命令:
31+
[literal]
32+
----
33+
-- create the extension
34+
CREATE EXTENSION pgtt;
35+
----
36+
37+
== 载入插件
38+
39+
[literal]
40+
----
41+
创建插件后还需要载入才能使用
42+
可以使用以下三种方式之一进行载入:
43+
44+
1. 在配置文件中修改 session_preload_libraries
45+
session_preload_libraries = 'pgtt'
46+
47+
2. 在database级别上启用
48+
ALTER DATABASE mydb SET session_preload_libraries = 'pgtt';
49+
50+
3. 在session中载入
51+
LOAD 'pgtt';
52+
53+
成功载入插件后可以看到 pgtt.enabled 的值为 on
54+
ivorysql=# show pgtt.enabled;
55+
pgtt.enabled
56+
--------------
57+
on
58+
(1 row)
59+
60+
search_path 中增加了 pgtt_schema
61+
ivorysql=# SHOW search_path;
62+
search_path
63+
------------------------------
64+
"$user", public, pgtt_schema
65+
(1 row)
66+
67+
----
68+
69+
== 使用
70+
71+
[literal]
72+
----
73+
创建临时表:
74+
使用这条语句会产生一条警告信息,但是可以忽略。
75+
76+
ivorysql=# CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
77+
id integer,
78+
lbl text
79+
) ON COMMIT PRESERVE ROWS;
80+
WARNING: GLOBAL is deprecated in temporary table creation
81+
LINE 1: CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
82+
^
83+
CREATE TABLE
84+
85+
如果不希望产生这条井道信息,可以使用注释符号:
86+
CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table (
87+
id integer,
88+
lbl text
89+
) ON COMMIT PRESERVE ROWS;
90+
91+
92+
创建临时表也可以使用 LIKE 子句:
93+
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table AS SELECT * FROM source_table WITH DATA;
94+
CREATE TABLE AS
95+
96+
在表列上创建索引:
97+
ivorysql=# CREATE INDEX ON test_gtt_table (id);
98+
CREATE INDEX
99+
100+
删除临时表:
101+
ivorysql=# drop table test_gtt_table;
102+
DROP TABLE
103+
104+
添加约束(除了外键):
105+
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (
106+
c1 serial PRIMARY KEY,
107+
c2 VARCHAR (50) UNIQUE NOT NULL,
108+
c3 boolean DEFAULT false
109+
);
110+
CREATE TABLE
111+
112+
创建带有外键的表是不允许的:
113+
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t1 (c1 integer, FOREIGN KEY (c1) REFERENCES source (id));
114+
ERROR: attempt to create referential integrity constraint on global temporary table
115+
116+
ivorysql=# ALTER TABLE t2 ADD FOREIGN KEY (c1) REFERENCES source (id);
117+
ERROR: attempt to create referential integrity constraint on global temporary table
118+
----
119+
120+
更多详细使用方法和高级特性,请参阅 https://github.com/amutu/pgtt 。
121+

EN/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
*** xref:5.8.adoc[pgaudit]
5252
*** xref:5.9.adoc[pgrouting]
5353
*** xref:5.10.adoc[system_stats]
54+
*** xref:5.11.adoc[pgtt]
5455
* Monitor and O&M
5556
** xref:3.2.adoc[Monitoring]
5657
** xref:3.3.adoc[Maintenance]

EN/modules/ROOT/pages/5.0.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ IvorySQL, as an advanced open-source database compatible with Oracle and based o
2222
|*8*| xref:5.8.adoc[pgaudit] | 18.0 | Provides fine-grained auditing, recording database operation logs to support security auditing and compliance checks | Database security auditing, compliance checks, audit report generation
2323
|*9*| xref:5.9.adoc[pgrouting] | 3.8.0 | Provides routing computation for geospatial data, supporting multiple algorithms and data formats | Geospatial analysis, route planning, logistics optimization
2424
|*10*| xref:5.10.adoc[system_stats] | 3.2 | Provide functions for accessing system-level statistics. | system monitor
25+
|*10*| xref:5.11.adoc[pgtt] | 4.5 | Create, manage and use Oracle-style Global Temporary Tables. | Business development
2526
|====
2627

2728
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.

EN/modules/ROOT/pages/5.11.adoc

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
= pgtt
5+
6+
== Overview
7+
pgtt is a PostgreSQL extension to create, manage and use Oracle-style Global Temporary Tables.
8+
The objective of this extension it to provide the Global Temporary Table feature to PostgreSQL waiting for an in core implementation
9+
10+
== Installation
11+
12+
[TIP]
13+
The source installation environment is Ubuntu 24.04 (x86_64), with IvorySQL already installed in the environment at /path-to/ivorysql
14+
15+
=== Source Installation
16+
17+
[literal]
18+
----
19+
# Download pgtt source code
20+
wget https://github.com/darold/pgtt/archive/refs/tags/v4.5.tar.gz
21+
tar zxvf v4.5.tar.gz
22+
cd pgtt-4.5
23+
24+
# Compile and install
25+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
26+
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
27+
----
28+
29+
== Create Extension
30+
31+
Connect to the database using psql and execute the following command:
32+
[literal]
33+
----
34+
-- create the extension
35+
CREATE EXTENSION pgtt;
36+
----
37+
38+
== Load the Extension
39+
40+
[literal]
41+
----
42+
After creating the extension, it needs to be loaded before use
43+
You can use one of the following three methods to load it:
44+
45+
1. Modify session_preload_libraries in the configuration file
46+
session_preload_libraries = 'pgtt'
47+
48+
2. Enable at database level
49+
ALTER DATABASE mydb SET session_preload_libraries = 'pgtt';
50+
51+
3. Load in session
52+
LOAD 'pgtt';
53+
54+
After successfully loading the extension, you can see that the value of pgtt.enabled is on
55+
ivorysql=# show pgtt.enabled;
56+
pgtt.enabled
57+
--------------
58+
on
59+
(1 row)
60+
61+
pgtt_schema is added to search_path
62+
ivorysql=# SHOW search_path;
63+
search_path
64+
------------------------------
65+
"$user", public, pgtt_schema
66+
(1 row)
67+
68+
----
69+
70+
== Usage
71+
72+
[literal]
73+
----
74+
Create temporary table:
75+
Using this statement will produce a warning message, but it can be ignored.
76+
77+
ivorysql=# CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
78+
id integer,
79+
lbl text
80+
) ON COMMIT PRESERVE ROWS;
81+
WARNING: GLOBAL is deprecated in temporary table creation
82+
LINE 1: CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
83+
^
84+
CREATE TABLE
85+
86+
If you don't want to produce this warning message, you can use comment symbols:
87+
CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table (
88+
id integer,
89+
lbl text
90+
) ON COMMIT PRESERVE ROWS;
91+
92+
93+
Temporary tables can also be created using the LIKE clause:
94+
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table AS SELECT * FROM source_table WITH DATA;
95+
CREATE TABLE AS
96+
97+
Create indexes on table columns:
98+
ivorysql=# CREATE INDEX ON test_gtt_table (id);
99+
CREATE INDEX
100+
101+
Drop temporary table:
102+
ivorysql=# drop table test_gtt_table;
103+
DROP TABLE
104+
105+
Add constraints (except foreign keys):
106+
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (
107+
c1 serial PRIMARY KEY,
108+
c2 VARCHAR (50) UNIQUE NOT NULL,
109+
c3 boolean DEFAULT false
110+
);
111+
CREATE TABLE
112+
113+
Creating tables with foreign keys is not allowed:
114+
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t1 (c1 integer, FOREIGN KEY (c1) REFERENCES source (id));
115+
ERROR: attempt to create referential integrity constraint on global temporary table
116+
117+
ivorysql=# ALTER TABLE t2 ADD FOREIGN KEY (c1) REFERENCES source (id);
118+
ERROR: attempt to create referential integrity constraint on global temporary table
119+
----
120+
121+
For more detailed usage and advanced features, please refer to https://github.com/amutu/pgtt .
122+

0 commit comments

Comments
 (0)