如何检查我的postgresql函数是否正在运行?

时间:2018-12-20 06:33:11

标签: php postgresql

我已经创建

CREATE OR REPLACE FUNCTION public.officer_view_licences(
    IN lab_code_r character)
  RETURNS TABLE(appl_type_r character varying, appl_date_r timestamp without time zone, shop_name_r character varying, status_r character,  appl_no_r character varying, license_no_r character varying, license_issue_date_r date, issueing_authority_name_r character varying, issueing_authority_desig_r character varying, reject_date_r date, valid_upto_r date) AS
$BODY$
BEGIN
    return QUERY SELECT appl_type, appl_date,  appl_no, license_no, license_issue_date, issueing_authority_name, issueing_authority_desig, reject_date, valid_upto FROM license_detail where lab_code = lab_code_r order by  appl_type, license_issue_date desc ;   
END 
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;

我在pgsql中的数据库中的函数,然后从

调用它
public function officer_view_licences($lab_code){               
        $pgquery = pg_query("select * from officer_view_licences('".$lab_code."')");
        while($row = pg_fetch_assoc($pgquery)) {
            $records[] = $row;                             
        }       
        print_r($records);
        return $records;
    }

我已经打印了记录,但是那里没有记录打印。但是当我运行

SELECT appl_type, appl_date,  appl_no, license_no, license_issue_date, issueing_authority_name, issueing_authority_desig, reject_date, valid_upto FROM license_detail where lab_code = '119' order by  appl_type, license_issue_date desc ; 

它将打印一些记录。如何检查我的功能是否正常工作?

1 个答案:

答案 0 :(得分:0)

您应该查询pg_stat_activity

select * from  pg_stat_activity 
 where application_name ~* '[o]fficer_view_licences';

或者,您可以为会话明确指定应用程序名称,以进行正确标识

set application_name to officer_view_licences_thisone;

然后,您可以按以下方式查询它:

select * from  pg_stat_activity 
 where application_name = 'officer_view_licences_thisone';