久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

PostgreSQL的插件pg

133次閱讀
沒有評論

共計 10018 個字符,預計需要花費 26 分鐘才能閱讀完成。

本篇內容主要講解“PostgreSQL 的插件 pg_variables 有什么作用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“PostgreSQL 的插件 pg_variables 有什么作用”吧!

安裝
使用 git 下載源碼,編譯安裝

[pg12@localhost contrib]$ git clone https://github.com/postgrespro/pg_variables.git
Cloning into  pg_variables ...
remote: Enumerating objects: 585, done.
remote: Total 585 (delta 0), reused 0 (delta 0), pack-reused 585
Receiving objects: 100% (585/585), 328.79 KiB | 75.00 KiB/s, done.
Resolving deltas: 100% (404/404), done.
[pg12@localhost contrib]$ cd pg_variables/
[pg12@localhost pg_variables]$ make USE_PGXS=1
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC -I. -I./ -I/appdb/pg12/pg12.0/include/postgresql/server -I/appdb/pg12/pg12.0/include/postgresql/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pg_variables.o pg_variables.c -MMD -MP -MF .deps/pg_variables.Po
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC -I. -I./ -I/appdb/pg12/pg12.0/include/postgresql/server -I/appdb/pg12/pg12.0/include/postgresql/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o pg_variables_record.o pg_variables_record.c -MMD -MP -MF .deps/pg_variables_record.Po
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC -shared -o pg_variables.so pg_variables.o pg_variables_record.o -L/appdb/pg12/pg12.0/lib -Wl,--as-needed -Wl,-rpath, /appdb/pg12/pg12.0/lib ,--enable-new-dtags 
cat pg_variables--1.0.sql pg_variables--1.0--1.1.sql pg_variables--1.1--1.2.sql   pg_variables--1.2.sql
[pg12@localhost pg_variables]$ make USE_PGXS=1 install
/bin/mkdir -p  /appdb/pg12/pg12.0/lib/postgresql 
/bin/mkdir -p  /appdb/pg12/pg12.0/share/postgresql/extension 
/bin/mkdir -p  /appdb/pg12/pg12.0/share/postgresql/extension 
/bin/install -c -m 755 pg_variables.so  /appdb/pg12/pg12.0/lib/postgresql/pg_variables.so 
/bin/install -c -m 644 .//pg_variables.control  /appdb/pg12/pg12.0/share/postgresql/extension/ 
/bin/install -c -m 644 .//pg_variables--1.0.sql .//pg_variables--1.0--1.1.sql .//pg_variables--1.1--1.2.sql pg_variables--1.2.sql  /appdb/pg12/pg12.0/share/postgresql/extension/ 
[pg12@localhost pg_variables]$ make USE_PGXS=1 installcheck
/appdb/pg12/pg12.0/lib/postgresql/pgxs/src/makefiles/../../src/test/regress/pg_regress --inputdir=./ --bindir= /appdb/pg12/pg12.0/bin  --dbname=contrib_regression pg_variables pg_variables_any pg_variables_trans
(using postmaster on Unix socket, default port)
============== dropping database  contrib_regression  ==============
psql: error: could not connect to server: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket  /tmp/.s.PGSQL.5432 ?
command failed:  /appdb/pg12/pg12.0/bin/psql  -X -c  DROP DATABASE IF EXISTS \ contrib_regression\   postgres 
make: *** [installcheck] Error 2
[pg12@localhost pg_variables]$ pg_ctl start
waiting for server to start....2019-11-18 14:43:59.175 CST [2254] LOG: starting PostgreSQL 12.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
2019-11-18 14:43:59.175 CST [2254] LOG: listening on IPv4 address  0.0.0.0 , port 5432
2019-11-18 14:43:59.175 CST [2254] LOG: listening on IPv6 address  :: , port 5432
2019-11-18 14:43:59.176 CST [2254] LOG: listening on Unix socket  /tmp/.s.PGSQL.5432 
2019-11-18 14:43:59.769 CST [2254] LOG: redirecting log output to logging collector process
2019-11-18 14:43:59.769 CST [2254] HINT: Future log output will appear in directory  pg_log .
 done
server started
[pg12@localhost pg_variables]$ make USE_PGXS=1 installcheck
/appdb/pg12/pg12.0/lib/postgresql/pgxs/src/makefiles/../../src/test/regress/pg_regress --inputdir=./ --bindir= /appdb/pg12/pg12.0/bin  --dbname=contrib_regression pg_variables pg_variables_any pg_variables_trans
(using postmaster on Unix socket, default port)
============== dropping database  contrib_regression  ==============
NOTICE: database  contrib_regression  does not exist, skipping
DROP DATABASE
============== creating database  contrib_regression  ==============
CREATE DATABASE
ALTER DATABASE
============== running regression test queries ==============
test pg_variables ... ok 161 ms
test pg_variables_any ... ok 47 ms
test pg_variables_trans ... ok 128 ms
=====================
 All 3 tests passed. 
=====================
[pg12@localhost pg_variables]$

簡單使用
創建擴展

[local]:5432 pg12@testdb=# create extension pg_variables;
CREATE EXTENSION
[local]:5432 pg12@testdb=#

pg_variables 中包含了多個函數

[local]:5432 pg12@testdb=# \df pgv*
 List of functions
 Schema | Name | Result data type | Argument data types | Type 
--------+---------------------+----------------------------------------------------------+----------------------------------------------------------------------------------------------------+------
 public | pgv_delete | boolean | package text, name text, value anynonarray | func
 public | pgv_exists | boolean | package text | func
 public | pgv_exists | boolean | package text, name text | func
 public | pgv_free | void | | func
 public | pgv_get | anyarray | package text, name text, var_type anyarray, strict boolean DEFAULT true | func
 public | pgv_get | anynonarray | package text, name text, var_type anynonarray, strict boolean DEFAULT true | func
 public | pgv_get_date | date | package text, name text, strict boolean DEFAULT true | func
 public | pgv_get_int | integer | package text, name text, strict boolean DEFAULT true | func
 public | pgv_get_jsonb | jsonb | package text, name text, strict boolean DEFAULT true | func
 public | pgv_get_numeric | numeric | package text, name text, strict boolean DEFAULT true | func
 public | pgv_get_text | text | package text, name text, strict boolean DEFAULT true | func
 public | pgv_get_timestamp | timestamp without time zone | package text, name text, strict boolean DEFAULT true | func
 public | pgv_get_timestamptz | timestamp with time zone | package text, name text, strict boolean DEFAULT true | func
 public | pgv_insert | void | package text, name text, r record, is_transactional boolean DEFAULT false | func
 public | pgv_list | TABLE(package text, name text, is_transactional boolean) | | func
 public | pgv_remove | void | package text | func
 public | pgv_remove | void | package text, name text | func
 public | pgv_select | SETOF record | package text, name text | func
 public | pgv_select | SETOF record | package text, name text, value anyarray | func
 public | pgv_select | record | package text, name text, value anynonarray | func
 public | pgv_set | void | package text, name text, value anyarray, is_transactional boolean DEFAULT false | func
 public | pgv_set | void | package text, name text, value anynonarray, is_transactional boolean DEFAULT false | func
 public | pgv_set_date | void | package text, name text, value date, is_transactional boolean DEFAULT false | func
 public | pgv_set_int | void | package text, name text, value integer, is_transactional boolean DEFAULT false | func
 public | pgv_set_jsonb | void | package text, name text, value jsonb, is_transactional boolean DEFAULT false | func
 public | pgv_set_numeric | void | package text, name text, value numeric, is_transactional boolean DEFAULT false | func
 public | pgv_set_text | void | package text, name text, value text, is_transactional boolean DEFAULT false | func
 public | pgv_set_timestamp | void | package text, name text, value timestamp without time zone, is_transactional boolean DEFAULT false | func
 public | pgv_set_timestamptz | void | package text, name text, value timestamp with time zone, is_transactional boolean DEFAULT false | func
 public | pgv_stats | TABLE(package text, allocated_memory bigint) | | func
 public | pgv_update | boolean | package text, name text, r record | func
(31 rows)

可以看到,該插件支持常規的數據類型,而對于復雜數據類型,則使用 jsonb。
上述函數中,其中重要的函數主要有兩個:pgv_set 和 pgv_get

[local]:5432 pg12@testdb=# \df pgv_get
 List of functions
 Schema | Name | Result data type | Argument data types | Type 
--------+---------+------------------+----------------------------------------------------------------------------+------
 public | pgv_get | anyarray | package text, name text, var_type anyarray, strict boolean DEFAULT true | func
 public | pgv_get | anynonarray | package text, name text, var_type anynonarray, strict boolean DEFAULT true | func
(2 rows)
[local]:5432 pg12@testdb=# \df pgv_set
 List of functions
 Schema | Name | Result data type | Argument data types | Type 
--------+---------+------------------+------------------------------------------------------------------------------------+------
 public | pgv_set | void | package text, name text, value anyarray, is_transactional boolean DEFAULT false | func
 public | pgv_set | void | package text, name text, value anynonarray, is_transactional boolean DEFAULT false | func
(2 rows)
[local]:5432 pg12@testdb=# select pgv_set(pk1 , pk1_var1 ,1);
 pgv_set 
---------
(1 row)
[local]:5432 pg12@testdb=# select pgv_get(pk1 , pk1_var1 ,null::int);
 pgv_get 
---------
 1
(1 row)
[local]:5432 pg12@testdb=# select pgv_set(pk1 , pk1_var1 ,101);
 pgv_set 
---------
(1 row)
[local]:5432 pg12@testdb=# select pgv_get(pk1 , pk1_var1 ,null::int);
 pgv_get 
---------
 101
(1 row)
[local]:5432 pg12@testdb=#

而且變量的作用域只在當前 session 中有效

[root@localhost ~]# su - pg12
Last login: Mon Nov 18 14:39:19 CST 2019 on pts/0
[pg12@localhost ~]$ psql -d testdb
Expanded display is used automatically.
psql (12.0)
Type  help  for help.
[local]:5432 pg12@testdb=# select pgv_get(pk1 , pk1_var1 ,null::int);
ERROR: unrecognized package  pk1 
[local]:5432 pg12@testdb=#

到此,相信大家對“PostgreSQL 的插件 pg_variables 有什么作用”有了更深的了解,不妨來實際操作一番吧!這里是丸趣 TV 網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-26發表,共計10018字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 治多县| 永泰县| 集安市| 清新县| 卓尼县| 兴和县| 萝北县| 车险| 比如县| 安仁县| 伊春市| 新龙县| 胶南市| 东光县| 龙泉市| 延长县| 扎兰屯市| 区。| 泗阳县| 黎平县| 深泽县| 含山县| 都昌县| 那坡县| 柳河县| 宣化县| 土默特左旗| 滨海县| 丰城市| 芮城县| 同江市| 中西区| 略阳县| 马龙县| 永德县| 盘山县| 浦县| 青田县| 碌曲县| 建德市| 张家界市|