{"id":11376,"date":"2018-06-28T06:22:56","date_gmt":"2018-06-28T04:22:56","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/"},"modified":"2018-06-28T06:22:56","modified_gmt":"2018-06-28T04:22:56","slug":"pgio-pg_stat_activity-and-pg_stat_statements","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/","title":{"rendered":"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nFor an Oracle DBA, we are used to join active sessions (from V$SESSION where status=&#8217;ACTIVE) with active statements (from V$SQL where users_executing&gt;0) on the SQL_ID. V$ACTIVE_SESSION_HISTORY also displays the TOP_LEVEL_SQL_ID to get the entrypoint of the usercall if we need it. With Postgres it is a bit more difficult because it seems that PG_STAT_ACTIVITY do not show the active statement but only the top-level one. But pg_stat_statement collects statistics for the final statements.<br \/>\n<!--more--><br \/>\nHere is an example where I&#8217;ve run pgio (the SLOB method for Postgres by <a href=\"https:\/\/kevinclosson.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">Kevin Closson<\/a>) in a Bitnami Postgres Compute service on the <a href=\"https:\/\/oracle.bitnami.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Oracle Cloud<\/a>. pgio runs all statements from a PL\/pgSQL function MYPGIO. This function runs the SELECT statements and some UPDATE statements depending on UPDATE_PCT. Most of the time is spend in those statements and very few in PL\/pgSQL itself, which is the goal of pgio &#8211; measuring logical and physical I\/O without the noise of other application components.<\/p>\n<p>I have added the pg_stat_statements extension by setting the following in postgresql.conf and installing postgresql10-contrib<\/p>\n<pre><code>\nshared_preload_libraries = 'pg_stat_statements'\npg_stat_statements.track = all\n<\/code><\/pre>\n<p>I&#8217;ve reset the statistics before running pgio:<\/p>\n<pre><code>\nselect pg_stat_reset();\nselect pg_stat_statements_reset();\n<\/code><\/pre>\n<p>The I&#8217;ve run the runit.sh with 4 schemas and 20 threads.<\/p>\n<h3>pg_stat_activity<\/h3>\n<p>Here is what I can see in PG_STAT_ACTIVITY when it is running:<\/p>\n<pre><code>postgres=# select substr(query,1,100) query,backend_type,application_name,query_start,wait_event_type,wait_event,state from pg_stat_activity where datid=17021;\n&nbsp;\n                                                query                                                 |   backend_type    |    application_name    |          query_start          | wait_event_type |  wait_event   | state\n------------------------------------------------------------------------------------------------------+-------------------+------------------------+-------------------------------+-----------------+---------------+--------\n select query,backend_type,application_name,query_start,wait_event_type,wait_event,state from pg_stat | client backend    | PostgreSQL JDBC Driver | 2018-06-27 20:15:11.578023+00 | Client          | ClientRead    | idle\n autovacuum: VACUUM ANALYZE public.pgio3                                                              | autovacuum worker |                        | 2018-06-27 20:01:19.785971+00 |                 |               | active\n autovacuum: VACUUM ANALYZE public.pgio4                                                              | autovacuum worker |                        | 2018-06-27 20:02:19.811009+00 |                 |               | active\n autovacuum: VACUUM ANALYZE public.pgio1                                                              | autovacuum worker |                        | 2018-06-27 20:08:19.864763+00 |                 |               | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.915761+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.925117+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.934903+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio2', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.931038+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.9269+00   | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.923288+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio2', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.95252+00  | LWLock          | WALWriteLock  | active\n SELECT * FROM mypgio('pgio3', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.96237+00  |                 |               | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.951347+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.962725+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio4', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.985567+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio1', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.98943+00  | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio2', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.976483+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio4', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:56.032111+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio4', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:55.998013+00 | Lock            | transactionid | active\n SELECT * FROM mypgio('pgio4', 10, 300, 131072, 255, 8);                                              | client backend    | psql.bin               | 2018-06-27 20:14:56.043566+00 | Lock            | transactionid | active\n(20 rows)<\/code><\/pre>\n<p>My client sessions are active on the MYPGIO function. This is the top-level statement which runs some SELECT and UPDATE and there is a very small chance to get samples with the session active on the controller procedural code rather than one of those statements. However, that&#8217;s the only thing I can see here.<\/p>\n<h3>pg_stat_statements<\/h3>\n<p>Now looking at PG_STAT_STATEMENTS:<\/p>\n<pre><code>postgres=# create extension pg_stat_statements;\nCREATE EXTENSION\n&nbsp;\npostgres=# select substr(query,1,100) query,calls,total_time\/1e6 seconds,total_time\/calls\/1e6 \"sec.\/call\",rows from pg_stat_statements where dbid=17021 order by total_time desc;\n                                                query                                                 | calls |       seconds       |      sec.\/call       | rows\n------------------------------------------------------------------------------------------------------+-------+---------------------+----------------------+-------\n UPDATE pgio1 SET scratch = scratch + $1 WHERE mykey BETWEEN $2 AND $3                                |  2081 |   0.583796520366999 | 0.000280536530690533 | 18729\n UPDATE pgio4 SET scratch = scratch + $1 WHERE mykey BETWEEN $2 AND $3                                |  2076 |      0.565067778457 | 0.000272190644728805 | 18684\n UPDATE pgio2 SET scratch = scratch + $1 WHERE mykey BETWEEN $2 AND $3                                |  2229 |      0.412313896512 | 0.000184977073356662 | 20061\n SELECT sum(scratch) FROM pgio3 WHERE mykey BETWEEN $1 AND $2                                         | 19199 |   0.317597650247998 | 1.65424058673888e-05 | 19199\n UPDATE pgio3 SET scratch = scratch + $1 WHERE mykey BETWEEN $2 AND $3                                |  2202 |   0.304893281095001 | 0.000138461980515441 | 19818\n SELECT sum(scratch) FROM pgio2 WHERE mykey BETWEEN $1 AND $2                                         | 19500 |       0.29686205481 | 1.52236951184615e-05 | 19500\n SELECT sum(scratch) FROM pgio1 WHERE mykey BETWEEN $1 AND $2                                         | 17873 |      0.285481468151 | 1.59727783892464e-05 | 17873\n SELECT sum(scratch) FROM pgio4 WHERE mykey BETWEEN $1 AND $2                                         | 17889 |      0.273855678533 | 1.53086074421711e-05 | 17889\n SELECT pgio_get_random_number($6, v_scale - v_select_batch_size)                                     | 83129 | 0.00134782461999997 | 1.62136513130192e-08 | 83129\n select blks_read from pg_stat_database where datname = $1                                            |     1 |       1.0456142e-05 |        1.0456142e-05 |     1\n create table pgio_audit_table ( c1 numeric , c2 numeric,  c3  numeric  , c4 numeric, c5 numeric, c6  |     1 |        7.636071e-06 |         7.636071e-06 |     0\n CREATE OR REPLACE FUNCTION mypgio(                                                                  +|     1 |        6.425742e-06 |         6.425742e-06 |     0\n v_mytab                 varchar,                                                                    +|       |                     |                      |\n v_pctupd                int,                                                                        +|       |                     |                      |\n v_runtime_secs          bigint,                                                                     +|       |                     |                      |\n v_scal                                                                                               |       |                     |                      |\n select substr(query,$1,$2) query,calls,total_time\/$3 seconds,total_time\/calls\/$4 \"sec.\/call\",rows fr |     9 |        5.017752e-06 |          5.57528e-07 |   139\n CREATE OR REPLACE FUNCTION pgio_get_random_number(BIGINT, BIGINT) RETURNS BIGINT AS $$              +|     1 |        4.217947e-06 |         4.217947e-06 |     0\n DECLARE                                                                                             +|       |                     |                      |\n     v                                                                                                |       |                     |                      |\n drop table pgio_audit_table                                                                          |     1 |        3.337471e-06 |         3.337471e-06 |     0\n DROP TYPE pgio_return CASCADE                                                                        |     1 |        2.451694e-06 |         2.451694e-06 |     0\n CREATE TYPE pgio_return AS (                                                                        +|     1 |        1.746512e-06 |         1.746512e-06 |     0\n mypid int,                                                                                          +|       |                     |                      |\n loop_iterations bigint ,                                                                            +|       |                     |                      |\n sql_selects bigint,                                                                                 +|       |                     |                      |\n sql_updates                                                                                          |       |                     |                      |\n select query,backend_type,application_name,query_start,wait_event_type,wait_event,state from pg_stat |     3 |        1.312499e-06 | 4.37499666666667e-07 |   172\n SELECT pg_backend_pid()                                                                              |    80 |         6.10539e-07 |        7.6317375e-09 |    80\n select pg_stat_statements_reset()                                                                    |     1 |          1.8114e-07 |           1.8114e-07 |     1\n select datname, blks_hit, blks_read,tup_returned,tup_fetched,tup_updated from pg_stat_database where |     1 |         1.60161e-07 |          1.60161e-07 |     1\n select blks_hit from pg_stat_database where datname = $1                                             |     1 |         1.48597e-07 |          1.48597e-07 |     1\n select pg_stat_reset()                                                                               |     1 |          5.3776e-08 |           5.3776e-08 |     1\n SET application_name = 'PostgreSQL JDBC Driver'                                                      |     2 |          5.2967e-08 |          2.64835e-08 |     0\n SET extra_float_digits = 3                                                                           |     2 |          3.7514e-08 |           1.8757e-08 |     0\n show shared_buffers--quiet                                                                           |     1 |          2.1151e-08 |           2.1151e-08 |     0\n(26 rows)\n<\/code><\/pre>\n<p>Here I can see that the main activity is on UPDATE and SELECT. There&#8217;s even no mention of the MYPGIO function except for its creation. I don&#8217;t even see the calls for it. We can see the same graphically from <a href=\"https:\/\/orachrome.com\/index.php\" target=\"_blank\" rel=\"noopener noreferrer\">Orachrome<\/a> Lighty for Postgres where only the top-level statement is displayed:<br \/>\n<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\" alt=\"CapturePGIO\" width=\"1024\" height=\"559\" class=\"aligncenter size-large wp-image-24651\" \/><\/a><\/p>\n<p>This makes it very difficult to match those two views. From PG_STAT_ACTIVITY I know that I spend time on MYPGIO function call and its system activity (here lot of locks waiting for vacuum sessions and some latch contention on WAL). We have sampling information, but nothing about database time and read\/write measures. From PG_STAT_STATEMENT we have all measures, but with no link to the sampling activity, and then no link with the wait events. Coming from Oracle databases, the most important in Oracle tuning is the DB time which can be detailed from the system point of view (wait events, CPU, I\/O) and from the user point of view (time model, SQL statements, Segments). And it can be a cumulative measure (each session measuring the time in a call or an operation) or a sampling one (counting the sessions active and on which operation). And ASH makes the link between all those dimensions. With this, we can directly address the user response time with our actions on the system, digging from the end-user perceived problem to the internal application or system root cause. <\/p>\n<p>With current Postgres statistics, it seems that we can look at SQL statements on one side and at the system on the other side. But can we ensure that we really address the user problems? Especially when calling the statements from a function, which is the optimized way to avoid useless roundtrips and context switches? Postgres is evolving a lot from the community. I hope that more and more information will be available in PG_STAT_ACTIVITY to be sampled and link all dimensions related to the system and the users. Like with any analytic query, we need all dimensions at the same level of granularity.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . For an Oracle DBA, we are used to join active sessions (from V$SESSION where status=&#8217;ACTIVE) with active statements (from V$SQL where users_executing&gt;0) on the SQL_ID. V$ACTIVE_SESSION_HISTORY also displays the TOP_LEVEL_SQL_ID to get the entrypoint of the usercall if we need it. With Postgres it is a bit more difficult because it [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":11377,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[59,83],"tags":[699,570,77,1218],"type_dbi":[],"class_list":["post-11376","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oracle","category-postgresql","tag-ash","tag-postgres","tag-postgresql","tag-tuning"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . For an Oracle DBA, we are used to join active sessions (from V$SESSION where status=&#8217;ACTIVE) with active statements (from V$SQL where users_executing&gt;0) on the SQL_ID. V$ACTIVE_SESSION_HISTORY also displays the TOP_LEVEL_SQL_ID to get the entrypoint of the usercall if we need it. With Postgres it is a bit more difficult because it [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-28T04:22:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1049\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS\",\"datePublished\":\"2018-06-28T04:22:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\"},\"wordCount\":654,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\",\"keywords\":[\"ASH\",\"postgres\",\"PostgreSQL\",\"tuning\"],\"articleSection\":[\"Oracle\",\"PostgreSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\",\"name\":\"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\",\"datePublished\":\"2018-06-28T04:22:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png\",\"width\":1920,\"height\":1049},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/","og_locale":"en_US","og_type":"article","og_title":"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS","og_description":"By Franck Pachot . For an Oracle DBA, we are used to join active sessions (from V$SESSION where status=&#8217;ACTIVE) with active statements (from V$SQL where users_executing&gt;0) on the SQL_ID. V$ACTIVE_SESSION_HISTORY also displays the TOP_LEVEL_SQL_ID to get the entrypoint of the usercall if we need it. With Postgres it is a bit more difficult because it [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/","og_site_name":"dbi Blog","article_published_time":"2018-06-28T04:22:56+00:00","og_image":[{"width":1920,"height":1049,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png","type":"image\/png"}],"author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS","datePublished":"2018-06-28T04:22:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/"},"wordCount":654,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png","keywords":["ASH","postgres","PostgreSQL","tuning"],"articleSection":["Oracle","PostgreSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/","url":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/","name":"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png","datePublished":"2018-06-28T04:22:56+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CapturePGIO.png","width":1920,"height":1049},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/pgio-pg_stat_activity-and-pg_stat_statements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PGIO, PG_STAT_ACTIVITY and PG_STAT_STATEMENTS"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/11376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=11376"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/11376\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/11377"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=11376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=11376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=11376"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=11376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}