pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_stat_statement not collecting information about queries inside functions.
2+ messages / 2 participants
[nested] [flat]

* pg_stat_statement not collecting information about queries inside functions.
@ 2026-07-30 13:41 MAILBOX-DBS <dba-mailbox@pictet.com>
  2026-07-30 14:10 ` Re: pg_stat_statement not collecting information about queries inside functions. Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: MAILBOX-DBS @ 2026-07-30 13:41 UTC (permalink / raw)
  To: pgsql-performance@lists.postgresql.org <pgsql-performance@lists.postgresql.org>

Hello all

pg_stat_statements does not seem to collect metrics for queries inside functions, in my understanding this should be possible.
Is there a documentation about restrictions or has someone a clue why this is not working for me?

Values of parameters that may influence the behaviour:

shared_preload_libraries = 'pgaudit,pg_stat_statements'
pg_stat_statements.track = 'all'
pg_stat_statements.max = 20000
track_functions = 'all'

the function header:
CREATE OR REPLACE FUNCTION core.sf_generic_daily_merge_landing_to_target(
            p_sys_daily_load_run_key bigint)
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
AS $BODY$
Declare

Best Regards
Rolf
 
 
This message is not intended for persons who are citizens of, domiciled or resident in, or entities registered in a country or jurisdiction in which its distribution, publication, provision or use would violate current laws and regulations.
The content of this message is confidential and may be read and/or used only by the recipient of this message. For information about personal data protection, please refer to the Pictet Group's Privacy Notice available at https://www.group.pictet/privacynotice. If you have received this e-mail message in error, please destroy it and delete it from your computer.
The Pictet Group may not be held liable for the use, transmission or treatment of the content of this message. The recipient of this message remains solely liable for any form of reproduction, copying, disclosure, modification and/or publication of the content. No liability whatsoever will be incurred by the Pictet Group. The recipient of this message agrees to comply with the applicable laws and regulations in the jurisdictions where they use the information contained herein..
 


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pg_stat_statement not collecting information about queries inside functions.
  2026-07-30 13:41 pg_stat_statement not collecting information about queries inside functions. MAILBOX-DBS <dba-mailbox@pictet.com>
@ 2026-07-30 14:10 ` Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Pavel Stehule @ 2026-07-30 14:10 UTC (permalink / raw)
  To: MAILBOX-DBS <dba-mailbox@pictet.com>; +Cc: pgsql-performance@lists.postgresql.org <pgsql-performance@lists.postgresql.org>

Hi

čt 30. 7. 2026 v 15:41 odesílatel MAILBOX-DBS <dba-mailbox@pictet.com>
napsal:

> Hello all
>
>
>
> pg_stat_statements does not seem to collect metrics for queries inside
> functions, in my understanding this should be possible.
>
> Is there a documentation about restrictions or has someone a clue why this
> is not working for me?
>
>
>
> Values of parameters that may influence the behaviour:
>
>
>
> shared_preload_libraries = 'pgaudit,pg_stat_statements'
>
> pg_stat_statements.track = 'all'
>
> pg_stat_statements.max = 20000
>
> track_functions = 'all'
>
>
>
> the function header:
>
> CREATE OR REPLACE FUNCTION core.sf_generic_daily_merge_landing_to_target(
>
>             p_sys_daily_load_run_key bigint)
>
>     RETURNS integer
>
>     LANGUAGE 'plpgsql'
>
>     COST 100
>
>     VOLATILE PARALLEL UNSAFE
>
> AS $BODY$
>
> Declare
>
>
>
> Best Regards
>
> Rolf
>
>
It does it - track=all surely does it.

CREATE OR REPLACE FUNCTION public.foo()
 RETURNS void
 LANGUAGE plpgsql
AS $function$declare x int;
begin
  select 1 from pg_sleep(1), pg_class limit 1 into x;
end;
$function$

select foo();

select * from pg_stat_statements;

and you should to see

2026-07-30 16:09:10) postgres=# select query, calls, total_exec_time from
pg_stat_statements where query like '%sleep%' and toplevel = 'f';
┌─[ RECORD 1 ]────┬────────────────────────────────────────────────┐
│ query           │ select $1 from pg_sleep($2), pg_class limit $3 │
│ calls           │ 1                                              │
│ total_exec_time │ 1001.123917                                    │
└─────────────────┴────────────────────────────────────────────────┘

 Regards

Pavel


>
>
> ------------------------------
>
>
>
> This message is not intended for persons who are citizens of, domiciled or
> resident in, or entities registered in a country or jurisdiction in which
> its distribution, publication, provision or use would violate current laws
> and regulations.
> The content of this message is confidential and may be read and/or used
> only by the recipient of this message. For information about personal data
> protection, please refer to the Pictet Group’s Privacy Notice available at
> https://www.group.pictet/privacynotice. If you have received this e-mail
> message in error, please destroy it and delete it from your computer.
> The Pictet Group may not be held liable for the use, transmission or
> treatment of the content of this message. The recipient of this message
> remains solely liable for any form of reproduction, copying, disclosure,
> modification and/or publication of the content. No liability whatsoever
> will be incurred by the Pictet Group. The recipient of this message agrees
> to comply with the applicable laws and regulations in the jurisdictions
> where they use the information contained herein..
>

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-07-30 14:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-30 13:41 pg_stat_statement not collecting information about queries inside functions. MAILBOX-DBS <dba-mailbox@pictet.com>
2026-07-30 14:10 ` Pavel Stehule <pavel.stehule@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox