From 5f0d2aa28edcaced59d9954605c1683b4f9dee4b Mon Sep 17 00:00:00 2001 From: Mark Wong Date: Wed, 5 Jun 2019 03:32:42 +0000 Subject: Remove pg_stat_statements stats view Simplify the pg_top code by moving this functionality to pgstat. --- HISTORY | 1 - commands.c | 40 ---------------------------------------- help.h | 1 - machine.h | 1 - pg.c | 53 ----------------------------------------------------- pg.h | 24 ------------------------ pg_top.c | 7 ------- pg_top.h | 1 - 8 files changed, 128 deletions(-) diff --git a/HISTORY b/HISTORY index 3834bba..5583506 100644 --- a/HISTORY +++ b/HISTORY @@ -3,7 +3,6 @@ Release Notes Release 4.0.0 * Replace autoconf with cmake - * Add monitoring of pg_stat_statements * Remove table stats monitoring, use pgstat instead * Remove index stats monitoring, use pgstat instead diff --git a/commands.c b/commands.c index a51fe58..67cec07 100644 --- a/commands.c +++ b/commands.c @@ -72,7 +72,6 @@ static char *err_listem = char header_io_stats[64] = " PID RCHAR WCHAR SYSCR SYSCW READS WRITES CWRITES COMMAND"; -char header_statements[46] = " CALLS CALLS% TOTAL_TIME AVG_TIME QUERY"; /* These macros get used to reset and log the errors */ #define ERR_RESET errcnt = 0 @@ -120,7 +119,6 @@ struct cmd cmd_map[] = { {'r', cmd_renice}, #endif /* ENABLE_KILL */ {'s', cmd_delay}, - {'S', cmd_statements}, {'t', cmd_toggle}, {'T', cmd_order_time}, {'u', cmd_user}, @@ -446,26 +444,6 @@ cmd_order(struct pg_top_context *pgtctx) clear_message(); } break; - case MODE_STATEMENTS: - new_message(MT_standout, "Order to sort: "); - if (readline(tempbuf, sizeof(tempbuf), No) > 0) - { - if ((i = string_index(tempbuf, statement_ordernames)) == -1) - { - new_message(MT_standout, " %s: unrecognized sorting order", - tempbuf); - no_command = Yes; - } - else - { - pgtctx->statement_order_index = i; - } - } - else - { - clear_message(); - } - break; case MODE_PROCESSES: default: if (pgtctx->statics.order_names == NULL) @@ -612,24 +590,6 @@ cmd_renice(struct pg_top_context *pgtctx) } #endif /* ENABLE_KILL */ -int -cmd_statements(struct pg_top_context *pgtctx) -{ - if (pgtctx->mode == MODE_STATEMENTS) - { - pgtctx->mode = MODE_PROCESSES; - pgtctx->header_text = - pgtctx->header_processes; - } - else - { - pgtctx->mode = MODE_STATEMENTS; - pgtctx->header_text = header_statements; - } - reset_display(pgtctx); - return No; -} - int cmd_toggle(struct pg_top_context *pgtctx) { diff --git a/help.h b/help.h index e954210..305cc46 100644 --- a/help.h +++ b/help.h @@ -18,7 +18,6 @@ L - show locks held by a process\n\ M - sort by memory usage\n\ N - sort by pid\n\ P - sort by CPU usage\n\ -S - show pg_stat_statements statistics\n\ Q - show current query of a process\n\ T - sort by time\n\ c - toggle the display of process commands\n\ diff --git a/machine.h b/machine.h index d788e0f..a9ee29b 100644 --- a/machine.h +++ b/machine.h @@ -30,7 +30,6 @@ /* Display modes. */ #define MODE_PROCESSES 0 #define MODE_IO_STATS 3 -#define MODE_STATEMENTS 4 /* Display modes for table and index statistics. */ #define STATS_DIFF 0 diff --git a/pg.c b/pg.c index 15d291f..f240d72 100644 --- a/pg.c +++ b/pg.c @@ -42,10 +42,6 @@ "WHERE procpid = %d\n" \ " AND procpid = pid;" -char *statement_ordernames[] = { - "calls", "calls%", "total_time", "avg_time", NULL -}; - float pg_version(PGconn *); PGconn * @@ -66,55 +62,6 @@ connect_to_db(const char *values[]) return pgconn; } -int -pg_display_statements(const char *values[], int compare_index, int max_topn) -{ - int i; - int rows; - PGconn *pgconn; - PGresult *pgresult = NULL; - static char line[512]; - - int max_lines; - - pgconn = connect_to_db(values); - if (pgconn != NULL) - { - pgresult = PQexec(pgconn, CHECK_FOR_STATEMENTS_X); - if (PQntuples(pgresult) == 0) - return 1; - - snprintf(line, sizeof(line), SELECT_STATEMENTS, compare_index + 1); - pgresult = PQexec(pgconn, line); - rows = PQntuples(pgresult); - } - else - { - PQfinish(pgconn); - return 0; - } - PQfinish(pgconn); - - max_lines = rows < max_topn ? rows : max_topn; - - /* Display stats. */ - for (i = rows - 1; i > rows - max_lines - 1; i--) - { - snprintf(line, sizeof(line), "%7s %6.1f %10s %8s %s", - PQgetvalue(pgresult, i, 0), - atof(PQgetvalue(pgresult, i, 1)), - PQgetvalue(pgresult, i, 2), - PQgetvalue(pgresult, i, 3), - PQgetvalue(pgresult, i, 4)); - u_process(rows - i - 1, line); - } - - if (pgresult != NULL) - PQclear(pgresult); - - return 0; -} - PGresult * pg_locks(PGconn *pgconn, int procpid) { diff --git a/pg.h b/pg.h index b458772..e368351 100644 --- a/pg.h +++ b/pg.h @@ -5,34 +5,10 @@ #include -#define CHECK_FOR_STATEMENTS_X \ - "SELECT 1\n" \ - "FROM pg_extension\n" \ - "WHERE extname = 'pg_stat_statements'" - -#define SELECT_STATEMENTS \ - "WITH aggs AS (\n" \ - " SELECT sum(calls) AS calls_total\n" \ - " FROM pg_stat_statements\n" \ - ")\n" \ - "SELECT calls,\n" \ - " calls / calls_total AS calls_percentage,\n" \ - " to_char(INTERVAL '1 milliseconds' * total_time,\n" \ - " 'HH24:MI:SS.MS'),\n" \ - " to_char(INTERVAL '1 milliseconds' * (total_time / calls),\n" \ - " 'HH24:MI:SS.MS') AS average_time,\n" \ - " regexp_replace(query, E'[\\n\\r]+', ' ', 'g' ) AS query\n" \ - "FROM pg_stat_statements, aggs\n" \ - "ORDER BY %d ASC" - PGconn *connect_to_db(const char **); -int pg_display_statements(const char **, int, int); - PGresult *pg_locks(PGconn *, int); PGresult *pg_processes(PGconn *); PGresult *pg_query(PGconn *, int); -extern char *statement_ordernames[]; - #endif /* _PG_H_ */ diff --git a/pg_top.c b/pg_top.c index 1b34873..45d7e93 100644 --- a/pg_top.c +++ b/pg_top.c @@ -311,12 +311,6 @@ do_display(struct pg_top_context *pgtctx) /* Now show the top "n" processes or other statistics. */ switch (pgtctx->mode) { - case MODE_STATEMENTS: - if (pg_display_statements(pgtctx->values, - pgtctx->statement_order_index, max_topn) != 0) - new_message(MT_standout | MT_delayed, - " Extension pg_stat_statments not found"); - break; #ifdef __linux__ case MODE_IO_STATS: for (i = 0; i < active_procs; i++) @@ -756,7 +750,6 @@ main(int argc, char *argv[]) pgtctx.ps.uid = -1; pgtctx.ps.command = NULL; pgtctx.show_tags = No; - pgtctx.statement_order_index = 0; pgtctx.topn = 0; /* Show help or version number if necessary */ diff --git a/pg_top.h b/pg_top.h index cbea01d..58e4176 100644 --- a/pg_top.h +++ b/pg_top.h @@ -106,7 +106,6 @@ struct pg_top_context char *order_name; struct process_select ps; char show_tags; - int statement_order_index; struct statics statics; struct system_info system_info; struct timeval timeout; -- cgit v1.2.3