From bed6c2748071cfaad8ed933afd8d6dc69865bf35 Mon Sep 17 00:00:00 2001 From: wangfeihuo Date: Wed, 5 Mar 2025 17:29:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dretry=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Retry\347\256\241\347\220\206.md" | 64 ++++++++++++++++--- .../Retry\347\256\241\347\220\206.md" | 64 ++++++++++++++++--- 2 files changed, 110 insertions(+), 18 deletions(-) diff --git "a/content/docs-lite/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" "b/content/docs-lite/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" index b66e7a921..5937ecf7f 100644 --- "a/content/docs-lite/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" +++ "b/content/docs-lite/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" @@ -6,16 +6,62 @@ Retry是数据库在SQL或存储过程(包含匿名块)执行失败时,在 示例: + 首先要将需要重置的错误码写入到retry配置文件中(gsql同级目录下的retry_errcodes.conf文件),错误码可以通过\set VERBOSITY verbose 后获取: + + ``` + openGauss=# \set VERBOSITY verbose + openGauss=# call retry_basic(1); + ERROR: column "b" of relation "t1" does not exist + SQLSTATE: 42703 ------错误码 + LINE 1: INSERT INTO t1 (b) VALUES (x+1) + ^ + QUERY: INSERT INTO t1 (b) VALUES (x+1) + CONTEXT: PL/pgSQL function retry_basic(integer) line 3 at SQL statement ``` - openGauss=# CREATE OR REPLACE PROCEDURE retry_basic ( IN x INT) - AS - BEGIN - INSERT INTO t1 (a) VALUES (x); - INSERT INTO t1 (a) VALUES (x+1); - END; - / - openGauss=# CALL retry_basic(1); + 将错误码写入retry_errcodes.conf配置文件可以参考如下命令,并且写完错误码后需要退出和重新进入gsql生效。 + + ``` + echo "42703" >> ${GAUSSHOME}/bin/retry_errcodes.conf + ``` + + 重试失败的sql示例 + + ``` + openGauss=# create table t1(a int); + CREATE TABLE + openGauss=# CREATE OR REPLACE PROCEDURE retry_basic ( IN x INT) + openGauss-# AS + openGauss$# BEGIN + openGauss$# INSERT INTO t1 (a) VALUES (x); + openGauss$# INSERT INTO t1 (b) VALUES (x+1); + openGauss$# END; + openGauss$# / + CREATE PROCEDURE + openGauss=# + openGauss=# \set RETRY + Retry is on with default retry times: 5. + openGauss=# + openGauss=# call retry_basic(1); + INFO: query retry 1 time(s). + INFO: query retry 2 time(s). + INFO: query retry 3 time(s). + INFO: query retry 4 time(s). + INFO: query retry 5 time(s). + ERROR: column "b" of relation "t1" does not exist + LINE 1: INSERT INTO t1 (b) VALUES (x+1) + ^ + QUERY: INSERT INTO t1 (b) VALUES (x+1) + CONTEXT: PL/pgSQL function retry_basic(integer) line 3 at SQL statement + openGauss=# + openGauss=# select * from t1; + a + --- + (0 rows) + openGauss=# + openGauss=# \set RETRY + Retry is off. + openGauss=# + ``` - diff --git "a/content/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" "b/content/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" index c58b21d49..8f5416066 100644 --- "a/content/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" +++ "b/content/zh/docs/SQLReference/Retry\347\256\241\347\220\206.md" @@ -6,16 +6,62 @@ Retry是数据库在SQL或存储过程(包含匿名块)执行失败时,在 示例: + 首先要将需要重置的错误码写入到retry配置文件中(gsql同级目录下的retry_errcodes.conf文件),错误码可以通过\set VERBOSITY verbose 后获取: + + ``` + openGauss=# \set VERBOSITY verbose + openGauss=# call retry_basic(1); + ERROR: column "b" of relation "t1" does not exist + SQLSTATE: 42703 ------错误码 + LINE 1: INSERT INTO t1 (b) VALUES (x+1) + ^ + QUERY: INSERT INTO t1 (b) VALUES (x+1) + CONTEXT: PL/pgSQL function retry_basic(integer) line 3 at SQL statement ``` - openGauss=# CREATE OR REPLACE PROCEDURE retry_basic ( IN x INT) - AS - BEGIN - INSERT INTO t1 (a) VALUES (x); - INSERT INTO t1 (a) VALUES (x+1); - END; - / - openGauss=# CALL retry_basic(1); + 将错误码写入retry_errcodes.conf配置文件可以参考如下命令,并且写完错误码后需要退出和重新进入gsql生效。 + + ``` + echo "42703" >> ${GAUSSHOME}/bin/retry_errcodes.conf + ``` + + 重试失败的sql示例 + + ``` + openGauss=# create table t1(a int); + CREATE TABLE + openGauss=# CREATE OR REPLACE PROCEDURE retry_basic ( IN x INT) + openGauss-# AS + openGauss$# BEGIN + openGauss$# INSERT INTO t1 (a) VALUES (x); + openGauss$# INSERT INTO t1 (b) VALUES (x+1); + openGauss$# END; + openGauss$# / + CREATE PROCEDURE + openGauss=# + openGauss=# \set RETRY + Retry is on with default retry times: 5. + openGauss=# + openGauss=# call retry_basic(1); + INFO: query retry 1 time(s). + INFO: query retry 2 time(s). + INFO: query retry 3 time(s). + INFO: query retry 4 time(s). + INFO: query retry 5 time(s). + ERROR: column "b" of relation "t1" does not exist + LINE 1: INSERT INTO t1 (b) VALUES (x+1) + ^ + QUERY: INSERT INTO t1 (b) VALUES (x+1) + CONTEXT: PL/pgSQL function retry_basic(integer) line 3 at SQL statement + openGauss=# + openGauss=# select * from t1; + a + --- + (0 rows) + openGauss=# + openGauss=# \set RETRY + Retry is off. + openGauss=# + ``` - -- Gitee