diff --git a/CN/modules/ROOT/nav.adoc b/CN/modules/ROOT/nav.adoc index a83e1c5..f1a1baa 100644 --- a/CN/modules/ROOT/nav.adoc +++ b/CN/modules/ROOT/nav.adoc @@ -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[日常维护] diff --git a/CN/modules/ROOT/pages/5.0.adoc b/CN/modules/ROOT/pages/5.0.adoc index 0cbd3cc..d9a776d 100644 --- a/CN/modules/ROOT/pages/5.0.adoc +++ b/CN/modules/ROOT/pages/5.0.adoc @@ -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 环境下稳定运行。用户可以根据业务需求选择合适的插件,进一步提升数据库系统的能力和灵活性。 diff --git a/CN/modules/ROOT/pages/5.11.adoc b/CN/modules/ROOT/pages/5.11.adoc new file mode 100644 index 0000000..f4a1334 --- /dev/null +++ b/CN/modules/ROOT/pages/5.11.adoc @@ -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 。 + diff --git a/EN/modules/ROOT/nav.adoc b/EN/modules/ROOT/nav.adoc index ced83c6..6b480fb 100644 --- a/EN/modules/ROOT/nav.adoc +++ b/EN/modules/ROOT/nav.adoc @@ -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] diff --git a/EN/modules/ROOT/pages/5.0.adoc b/EN/modules/ROOT/pages/5.0.adoc index 629391c..4214471 100644 --- a/EN/modules/ROOT/pages/5.0.adoc +++ b/EN/modules/ROOT/pages/5.0.adoc @@ -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. diff --git a/EN/modules/ROOT/pages/5.11.adoc b/EN/modules/ROOT/pages/5.11.adoc new file mode 100644 index 0000000..b89a407 --- /dev/null +++ b/EN/modules/ROOT/pages/5.11.adoc @@ -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 . +