Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CN/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*** xref:5.8.adoc[pgaudit]
*** xref:5.9.adoc[pgrouting]
*** xref:5.10.adoc[system_stats]
*** xref:5.11.adoc[pgtt]
* 监控运维
** xref:3.2.adoc[日常监控]
** xref:3.3.adoc[日常维护]
Expand Down
1 change: 1 addition & 0 deletions CN/modules/ROOT/pages/5.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ IvorySQL 作为一款兼容 Oracle 且基于 PostgreSQL 的高级开源数据库
| 8 | xref:5.8.adoc[pgaudit] | 18.0 | 提供细粒度的审计功能,记录数据库操作日志,便于安全审计和合规性检查 | 数据库安全审计、合规性检查、审计报告生成
| 9 | xref:5.9.adoc[pgrouting] | 3.8.0 | 提供地理空间数据的路由计算功能,支持多种算法和数据格式 | 地理空间分析、路径规划、物流优化
| 10 | xref:5.10.adoc[system_stats] | 3.2 | 提供用于访问系统级统计信息的函数 | 系统监控
| 11 | xref:5.11.adoc[pgtt] | 4.5 | 创建、管理与使用Oracle风格临时表 | 业务开发
|====

这些插件均经过 IvorySQL 团队的测试和适配,确保在 IvorySQL 环境下稳定运行。用户可以根据业务需求选择合适的插件,进一步提升数据库系统的能力和灵活性。
Expand Down
121 changes: 121 additions & 0 deletions CN/modules/ROOT/pages/5.11.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
:sectnums:
:sectnumlevels: 5

= pgtt

== 概述
pgtt 是一个创建、管理与使用Oracle风格临时表的PostgreSQL插件。这个插件的目标是在PG内核实现临时表之前提供类似特性。

== 安装

[TIP]
源码安装环境为 Ubuntu 24.04(x86_64),环境中已经安装了IvorySQL,安装路径为/path-to/ivorysql

=== 源码安装

[literal]
----
# 下载pgtt源代码
wget https://github.com/darold/pgtt/archive/refs/tags/v4.5.tar.gz
tar zxvf v4.5.tar.gz
cd pgtt-4.5

# 编译安装
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
----

== 创建Extension

psql 连接到数据库,执行如下命令:
[literal]
----
-- create the extension
CREATE EXTENSION pgtt;
----

== 载入插件

[literal]
----
创建插件后还需要载入才能使用
可以使用以下三种方式之一进行载入:

1. 在配置文件中修改 session_preload_libraries
session_preload_libraries = 'pgtt'

2. 在database级别上启用
ALTER DATABASE mydb SET session_preload_libraries = 'pgtt';

3. 在session中载入
LOAD 'pgtt';

成功载入插件后可以看到 pgtt.enabled 的值为 on
ivorysql=# show pgtt.enabled;
pgtt.enabled
--------------
on
(1 row)

search_path 中增加了 pgtt_schema
ivorysql=# SHOW search_path;
search_path
------------------------------
"$user", public, pgtt_schema
(1 row)

----

== 使用

[literal]
----
创建临时表:
使用这条语句会产生一条警告信息,但是可以忽略。

ivorysql=# CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
id integer,
lbl text
) ON COMMIT PRESERVE ROWS;
WARNING: GLOBAL is deprecated in temporary table creation
LINE 1: CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
^
CREATE TABLE

如果不希望产生这条警告信息,可以使用注释符号:
CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table (
id integer,
lbl text
) ON COMMIT PRESERVE ROWS;


创建临时表也可以使用 LIKE 子句:
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table AS SELECT * FROM source_table WITH DATA;
CREATE TABLE AS

在表列上创建索引:
ivorysql=# CREATE INDEX ON test_gtt_table (id);
CREATE INDEX

删除临时表:
ivorysql=# drop table test_gtt_table;
DROP TABLE

添加约束(除了外键):
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (
c1 serial PRIMARY KEY,
c2 VARCHAR (50) UNIQUE NOT NULL,
c3 boolean DEFAULT false
);
CREATE TABLE

创建带有外键的表是不允许的:
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t1 (c1 integer, FOREIGN KEY (c1) REFERENCES source (id));
ERROR: attempt to create referential integrity constraint on global temporary table

ivorysql=# ALTER TABLE t2 ADD FOREIGN KEY (c1) REFERENCES source (id);
ERROR: attempt to create referential integrity constraint on global temporary table
----

更多详细使用方法和高级特性,请参阅 https://github.com/amutu/pgtt 。

1 change: 1 addition & 0 deletions EN/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*** xref:5.8.adoc[pgaudit]
*** xref:5.9.adoc[pgrouting]
*** xref:5.10.adoc[system_stats]
*** xref:5.11.adoc[pgtt]
* Monitor and O&M
** xref:3.2.adoc[Monitoring]
** xref:3.3.adoc[Maintenance]
Expand Down
1 change: 1 addition & 0 deletions EN/modules/ROOT/pages/5.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ IvorySQL, as an advanced open-source database compatible with Oracle and based o
|*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
|*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
|*10*| xref:5.10.adoc[system_stats] | 3.2 | Provide functions for accessing system-level statistics. | system monitor
|*11*| xref:5.11.adoc[pgtt] | 4.5 | Create, manage and use Oracle-style Global Temporary Tables. | Business development
|====

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.
Expand Down
122 changes: 122 additions & 0 deletions EN/modules/ROOT/pages/5.11.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
:sectnums:
:sectnumlevels: 5

= pgtt

== Overview
pgtt is a PostgreSQL extension to create, manage and use Oracle-style Global Temporary Tables.
The objective of this extension it to provide the Global Temporary Table feature to PostgreSQL waiting for an in core implementation

== Installation

[TIP]
The source installation environment is Ubuntu 24.04 (x86_64), with IvorySQL already installed in the environment at /path-to/ivorysql

=== Source Installation

[literal]
----
# Download pgtt source code
wget https://github.com/darold/pgtt/archive/refs/tags/v4.5.tar.gz
tar zxvf v4.5.tar.gz
cd pgtt-4.5

# Compile and install
make PG_CONFIF=/path-to/ivorysql/bin/pg_config
make PG_CONFIF=/path-to/ivorysql/bin/pg_config install
----

== Create Extension

Connect to the database using psql and execute the following command:
[literal]
----
-- create the extension
CREATE EXTENSION pgtt;
----

== Load the Extension

[literal]
----
After creating the extension, it needs to be loaded before use
You can use one of the following three methods to load it:

1. Modify session_preload_libraries in the configuration file
session_preload_libraries = 'pgtt'

2. Enable at database level
ALTER DATABASE mydb SET session_preload_libraries = 'pgtt';

3. Load in session
LOAD 'pgtt';

After successfully loading the extension, you can see that the value of pgtt.enabled is on
ivorysql=# show pgtt.enabled;
pgtt.enabled
--------------
on
(1 row)

pgtt_schema is added to search_path
ivorysql=# SHOW search_path;
search_path
------------------------------
"$user", public, pgtt_schema
(1 row)

----

== Usage

[literal]
----
Create temporary table:
Using this statement will produce a warning message, but it can be ignored.

ivorysql=# CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
id integer,
lbl text
) ON COMMIT PRESERVE ROWS;
WARNING: GLOBAL is deprecated in temporary table creation
LINE 1: CREATE GLOBAL TEMPORARY TABLE test_gtt_table (
^
CREATE TABLE

If you don't want to produce this warning message, you can use comment symbols:
CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table (
id integer,
lbl text
) ON COMMIT PRESERVE ROWS;


Temporary tables can also be created using the LIKE clause:
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE test_gtt_table AS SELECT * FROM source_table WITH DATA;
CREATE TABLE AS

Create indexes on table columns:
ivorysql=# CREATE INDEX ON test_gtt_table (id);
CREATE INDEX

Drop temporary table:
ivorysql=# drop table test_gtt_table;
DROP TABLE

Add constraints (except foreign keys):
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (
c1 serial PRIMARY KEY,
c2 VARCHAR (50) UNIQUE NOT NULL,
c3 boolean DEFAULT false
);
CREATE TABLE

Creating tables with foreign keys is not allowed:
ivorysql=# CREATE /*GLOBAL*/ TEMPORARY TABLE t1 (c1 integer, FOREIGN KEY (c1) REFERENCES source (id));
ERROR: attempt to create referential integrity constraint on global temporary table

ivorysql=# ALTER TABLE t2 ADD FOREIGN KEY (c1) REFERENCES source (id);
ERROR: attempt to create referential integrity constraint on global temporary table
----

For more detailed usage and advanced features, please refer to https://github.com/amutu/pgtt .

Loading