DBMS_APPLICATION_INFO read_module、set_action、set_module 过程的 Postgres 替代品
Postgres alternatives for DBMS_APPLICATION_INFO read_module, set_action, set_module procedures
我有一个要迁移到 PostgreSQL 的 Oracle 存储过程。
存储过程中有 DBMS_APPLICATION_INFO.READ_MODULE
、DBMS_APPLICATION_INFO.SET_ACTION
和 DBMS_APPLICATION_INFO.SET_MODULE
过程,我无法在 Postgres 中找到替代方法。
Postgres 中这些过程最接近的替代方案是什么?
您可以使用参数application_name
:
示例:
postgres=# show application_name;
application_name
------------------
psql
(1 row)
postgres=# select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
------------------
psql
(1 row)
postgres=# set application_name='myapp';
SET
postgres=# select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
------------------
myapp
(1 row)
postgres=#
以下是实现操作和模块的可能解决方案:
begin;
BEGIN
set application_name='my_module:my_action';
SET
select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
---------------------
my_module:my_action
(1 row)
commit;
COMMIT
select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
---------------------
my_module:my_action
(1 row)
do
$$
declare
v_module text;
v_action text;
v_application_name text;
v_pos int;
begin
select application_name into v_application_name
from pg_stat_activity
where pid = pg_backend_pid();
v_pos = position(':' in v_application_name);
if (v_pos > 0)
then
v_module = substring(v_application_name, 1, v_pos - 1);
v_action = substring(v_application_name, v_pos + 1);
raise notice 'v_module=%, v_action=%', v_module, v_action;
end if;
end;
$$;
NOTICE: v_module=my_module, v_action=my_action
DO
我有一个要迁移到 PostgreSQL 的 Oracle 存储过程。
存储过程中有 DBMS_APPLICATION_INFO.READ_MODULE
、DBMS_APPLICATION_INFO.SET_ACTION
和 DBMS_APPLICATION_INFO.SET_MODULE
过程,我无法在 Postgres 中找到替代方法。
Postgres 中这些过程最接近的替代方案是什么?
您可以使用参数application_name
:
示例:
postgres=# show application_name;
application_name
------------------
psql
(1 row)
postgres=# select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
------------------
psql
(1 row)
postgres=# set application_name='myapp';
SET
postgres=# select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
------------------
myapp
(1 row)
postgres=#
以下是实现操作和模块的可能解决方案:
begin;
BEGIN
set application_name='my_module:my_action';
SET
select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
---------------------
my_module:my_action
(1 row)
commit;
COMMIT
select application_name from pg_stat_activity where pid = pg_backend_pid();
application_name
---------------------
my_module:my_action
(1 row)
do
$$
declare
v_module text;
v_action text;
v_application_name text;
v_pos int;
begin
select application_name into v_application_name
from pg_stat_activity
where pid = pg_backend_pid();
v_pos = position(':' in v_application_name);
if (v_pos > 0)
then
v_module = substring(v_application_name, 1, v_pos - 1);
v_action = substring(v_application_name, v_pos + 1);
raise notice 'v_module=%, v_action=%', v_module, v_action;
end if;
end;
$$;
NOTICE: v_module=my_module, v_action=my_action
DO