PostgreSQL DBA(6) - PG 11 New Features#3
PG 11即將正式釋出,本節簡單介紹了PG 11的新特性:PL/pgSQL增強和新增的配置引數。
一、PL/pgSQL
Procedure
PG 11新增了過程Procedure物件,類似Oracle的儲存過程.
testdb=# create or replace procedure sp_proc1(in p1 text) as
testdb-# $$
testdb$# declare
testdb$# v1 varchar(10);
testdb$# begin
testdb$# v1 := 'TEST';
testdb$# raise notice 'Parameter is : %',p1;
testdb$# raise notice 'v1 is : %',v1;
testdb$# end;
testdb$# $$
testdb-# language plpgsql;
CREATE PROCEDURE
過程使用CALL呼叫:
testdb=# call sp_proc1('test');
NOTICE: Parameter is : test
NOTICE: v1 is : TEST
CALL
檢視定義資訊:
testdb=# \df sp_proc1
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+----------+------------------+---------------------+------
public | sp_proc1 | | p1 text | proc
(1 row)
testdb=# \sf sp_proc1
CREATE OR REPLACE PROCEDURE public.sp_proc1(p1 text)
LANGUAGE plpgsql
AS $procedure$
declare
v1 varchar(10);
begin
v1 := 'TEST';
raise notice 'Parameter is : %',p1;
raise notice 'v1 is : %',v1;
end;
$procedure$
過程中可以對事務進行控制,但如果過程在事務中呼叫,而過程中有事務控制語句,則"不太好使".
儲存過程:
create or replace procedure sp_transaction(in p1 text) as
$$
begin
if lower(p1) = 'commit' then
commit;
elsif lower(p1) = 'rollback' then
rollback;
else
raise notice 'Invalid Parameter!';
end if;
end;
$$
language plpgsql;
測試場景:
testdb=# begin;
BEGIN
testdb=# insert into tt values(1);
INSERT 0 1
testdb=# call sp_transaction('commit');
ERROR: invalid transaction termination
CONTEXT: PL/pgSQL function sp_transaction(text) line 4 at COMMIT
testdb=# commit;
ROLLBACK
testdb=# commit;
WARNING: there is no transaction in progress
COMMIT
PL/pgSQL似乎沒有類似於Oracle自治事務的概念(在儲存過程中控制事務而與外層事務無關),不建議在過程/函式中使用事務,呼叫方統一管理事務.
變數定義
在函式或過程中,可定義變數為常量(CONSTANT關鍵字),並設定NOT NULL屬性,詳細請參照參考資料.
二、配置引數
新增的引數包括並行執行相關的引數如enable_parallel_hash等,詳見下表(更詳細的資訊參照參考資料).
三、參考資料
PostgreSQL 11 New Features With Examples(Beta 1)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/6906/viewspace-2374856/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PostgreSQL DBA(4) - PG 11 New Features#1SQL
- PostgreSQL DBA(5) - PG 11 New Features#2SQL
- PostgreSQL DBA(40) - PG 12 pg_promoteSQL
- PostgreSQL DBA(91) - PG upgradeSQL
- PostgreSQL DBA(41) - PG Index PropertiesSQLIndex
- PostgreSQL DBA(125) - PG 12(TPCC)SQL
- PostgreSQL DBA(53) - PG 12 Generated columnsSQL
- PostgreSQL DBA(63) - Extension(pg_qualstats)SQL
- PostgreSQL DBA(83) - Extension(pg_buffercache)SQL
- PostgreSQL DBA(84) - Extension(pg_prewarm)SQL
- PostgreSQL DBA(39) - PG 12 Functions for partitionsSQLFunction
- PostgreSQL DBA(46) - PG Operator classes and familiesSQL
- PostgreSQL DBA(163) - Extension(pg_cron)SQL
- PostgreSQL DBA(162) - Extension(pg_catcheck)SQL
- PostgreSQL DBA(172) - PG 13(WAL activity in EXPLAIN)SQLAI
- PostgreSQL DBA(138) - PG 13(Drop database force)SQLDatabase
- PostgreSQL DBA(92) - PG 12 Improving VACUUMSQL
- PostgreSQL DBA(67) - PG 12 SQLJSON pathSQLJSON
- PostgreSQL DBA(63) - Extension(pg_stat_statements)SQL
- PostgreSQL DBA(82) - PG 12 Improving COPYSQL
- PostgreSQL DBA(37) - PG 12 REINDEX CONCURRENTLYSQLIndex
- PostgreSQL DBA(142) - PG 12(Monitoring PostgreSQL VACUUM processes)SQL
- PostgreSQL DBA(129) - Extension(pg_variables).mdSQL
- PostgreSQL DBA(36) - PG 12 Inlined WITH queriesSQLinline
- PostgreSQL DBA(183) - PG 14(Better JSON)SQLJSON
- PostgreSQL DBA(18) - pg_waldump工具簡介SQL
- PostgreSQL DBA(189) - PG 14 Monitoring ImprovementsSQL
- PostgreSQL DBA(188) - PG 14 enable_memoizeSQL
- PostgreSQL DBA(171) - PG 13(pg_stat_statements to track planning statistics)SQL
- PostgreSQL DBA(146) - pgAdmin(pg_dumpall vs pg_dump)SQL
- PostgreSQL DBA(93) - PG 12 Improving Partition(Insert)SQL
- PostgreSQL DBA(94) - PG 12 Improving Partition(Select)SQL
- PostgreSQL DBA(95) - PG 12 Partition(out of shared memory)SQL
- PostgreSQL DBA(98) - PG 12 Faster float conversion to textSQLAST
- PostgreSQL DBA(79) - Locks(pg_blocking_pids)SQLBloC
- PostgreSQL DBA(62) - PG 12 More progress reportingSQL
- PostgreSQL DBA(38) - PG 12 Connection slots and WAL sendersSQL
- PostgreSQL DBA(126) - PG 12(搭建流複製)SQL