Commit Graph

459 Commits (8330ecdaf2be3eaee05a4a1ac88fc287a59c3929)

Author SHA1 Message Date
Ibrar Ahmed 4a30cccdac
Merge pull request #104 from LenzGr/doc-fixes
Documentation: Minor textual/formatting improvements
2021-09-20 10:41:15 +05:00
Ibrar Ahmed 0d1bf6b237
Merge pull request #103 from nastena1606/PG-208-Contributing-guide
PG-208: Doc Added Contibuting guide
2021-09-20 10:40:56 +05:00
Mikhail Samoylov 4a2a042955 Test pg_stat_monitor with pg from packages 2021-09-11 10:12:01 +03:00
Anastasia Alexadrova 88492e5b9b PG-208 Doc Added Contibuting guide
new file: CONTRIBUTING.md
2021-09-09 15:50:30 +03:00
Lenz Grimmer 40e6dff0f9 Documentation: Minor textual/formatting improvements
Updated `README.md` and `USER_GUIDE.md`, improved wording
and formatting. Slightly updated description in `META.json`.

Signed-off-by: Lenz Grimmer <lenz.grimmer@percona.com>
2021-09-09 11:05:31 +02:00
Ibrar Ahmed 0ceef74071
Bumping version for upcoming 0.9.2-beta1 release 2021-09-06 15:40:53 +05:00
Ibrar Ahmed b48522961b
Merge pull request #102 from EngineeredVirus/master
Bumping version for upcoming 0.9.2-beta1 release
2021-09-06 15:30:48 +05:00
Hamid Akhtar d633126a2d Bumping version for upcoming 0.9.2-beta1 release 2021-09-06 15:21:55 +05:00
Ibrar Ahmed bd4ae3ec37
Merge pull request #101 from darkfronza/PG-225_fix_deadlock
PG-225: Fix deadlock in pgss_store.
2021-09-06 15:08:19 +05:00
Diego Fronza eafb2e89a8 PG-225: Fix deadlock in pgss_store.
The deadlock scenario is describe below:
1. pgss_store is called, it acquires the lock pgss->lock.
2. An error ocurr, mostly out of memory when accessing internal hash
   tables used to store internal data, on functions
   pgss_store_query_info and pgss_get_entry.
3. Call elog() to report out of memory error.
4. Our pgsm_emit_log_hook is called, it calls pgss_store_error, which in
   turn calls pgss_store.
5. Try to acquire already acquired lock pgss->lock, deadlock happens.

To fix the problem, there are two modifications worth mentioning done by
this commit:
1. We are now passing HASH_ENTER_NULL flag to hash_search, instead of
   HASH_ENTER, as read in postgresql sources, this prevents this
   function from reporting error when out of memory, but instead it will
   only return NULL if we pass HASH_ENTER_NULL, so we can handle the
   error ourselves.
2. In pgss_store, if an error happens after the pgss->lock is acquired,
   we only set a flag, then, after releasing the lock, we check if the
   flag is set and report the error accordingly.
2021-09-03 14:43:32 -04:00
Ibrar Ahmed e541633670
Merge pull request #100 from darkfronza/PG-204_save_previous_emit_log_hook
PG-204: Fix save previous emit_log_hook.
2021-09-01 23:43:36 +05:00
Diego Fronza b8198278cd PG-204: Fix save previous emit_log_hook.
pg_stat_monitor was not saving the pointer to the previous hook for
emit_log_hook, this commit fix the issue.
2021-09-01 11:19:48 -04:00
Ibrar Ahmed 81a2c705b6 Removing commit (4d1c2e6), because it must be in its branch. 2021-09-01 11:27:19 +00:00
Ibrar Ahmed bd2ebf2a5b Regression output fix. 2021-09-01 10:25:42 +00:00
Ibrar Ahmed 6695670d73
Merge pull request #99 from darkfronza/PG-224_fix_memory_leak
PG-224: Fix memory leak on extract_query_comments.
2021-09-01 14:57:11 +05:00
Ibrar Ahmed 7a543bafb0 Regression output fix. 2021-09-01 09:55:35 +00:00
Diego Fronza b5aa300e82 pg-224: Fix memory leak on extract_query_comments.
There were two objects leaking memory in this function, the comments
variable of type char * allocated using palloc0, and the regular
expression object preg.

If the regcomp function failed, the function was returning without
releasing the comments variable allocated previously.

If the regexec function failed, the function was returning without
releasing the preg object and the comments variable.

This commit does two changes, first it turns the comments in
extract_query_comments an argument to the function, in pgss_store we
declare the comments variable in the stack, so it will clean up after
itself.

The second change was to move the regular expression object to global
scope, this way we compile the object only once, during module
initialization.

With these two changes we fix the memory leak and avoid
allocating/releasing memory for every call to this function.
2021-08-31 18:29:22 -04:00
Ibrar Ahmed 3d3ece2f99 PG-221: Use alternate of GetUserID function in error hook. 2021-08-31 14:55:53 +00:00
Ibrar Ahmed aee45ebe52 PG-221: Use alternat of GetUserID function in error hook. 2021-08-31 12:10:11 +00:00
Ibrar Ahmed bdab22e7cc
Merge pull request #98 from mu-samoylov/master
Add PPG job
2021-08-28 23:07:50 +05:00
Ibrar Ahmed f7f38e363f
Merge pull request #97 from darkfronza/PG-223_improve_performance
PG-223: improve performance
2021-08-28 23:07:32 +05:00
Diego Fronza 549347025d PG-223: Use memcpy and strlcpy to copy relations to counters.
We redefine macro _snprintf to use memcpy, which performs better, we
also update call sites using this macro to add the null terminator
'\0' to the source string length, this way memcpy also correctly
copies the null terminator to the destination string.

We update _snprintf2 macro to use strlcpy, the reason we don't use
memcpy here is because in the place where this macro is called,
pgss_update_entry, only the maximum string length of REL_LEN=1000 is
specified as an upper bound to copy the relations string vector to the
destination counters, but since this data is string, we don't need to
copy 1k bytes for every entry, by using strlcpy the copy ends as soon as
the null terminator '\0' is found in the source string.
2021-08-27 17:07:34 -04:00
Mikhail Samoylov 58f707c6d9 Add PPG job 2021-08-28 00:05:52 +03:00
Diego Fronza a847ed95de PG-223: Remove relations and num_relations from pgssSharedState.
These variables can't be in shared state, as the following problem was
taking place:
1. Process1 call pgss_ExecutorCheckPerms(), acquire lock, update
   relations and num_relations, release lock.
2. Process 2 call pgss_ExecutorCheckPerms(), acquire lock, update
   num_relations = 0;
3. Process 1 read num_relations = 0 in pgss_update_entry, this value is
   wrong as it was updated by Process 2.

Even if we acquire the lock in pgss_update_entry to read num_relations
and relations variable, Process 1 may end up acquiring the lock after
Process 2 has ovewritten the variable values, leading to Process 1
reading of wrong data.

By defining relations and num_relations to be static and global in
pg_stat_monitor.c we take advantage that each individual PostgreSQL
backend will have its own copy of this data, which allows us to remove
the locking in pgss_ExecutorCheckPerms to update these variables,
improving pg_stat_monitor overall performance.
2021-08-27 15:53:11 -04:00
Ibrar Ahmed f3962509fb
Merge pull request #94 from darkfronza/PG-203_possible_memory_leak
PG-203: Fix memory leak.
2021-08-23 21:30:54 +05:00
Ibrar Ahmed 8202900f3a
Merge pull request #96 from darkfronza/PG-222_add_hook_runtime_execution_benchmark
PG-222: Add benchmark support for measuring hook execution time.
2021-08-23 21:30:31 +05:00
Ibrar Ahmed a78dddd790
Merge pull request #95 from Naeem-Akhter/master
PG-195: Change pgsm_bucket_time value from 300 to 60.
2021-08-23 21:30:17 +05:00
Diego Fronza 775c087fb2 PG-222: Add benchmark support for measuring hook execution time.
Added a new view 'pg_stat_monitor_hook_stats' that provide execution
time statistics for all hooks installed by the module, following is a
description of the fields:
  -       hook: The hook function name.
  -   min_time: The fastest execution time recorded for the given hook.
  -   max_time: The slowest execution time recorded for the given hook.
  - total_time: Total execution time taken by all calls to the hook.
  -   avg_time: Average execution time of a call to the hook.
  -     ncalls: Total number of calls to the hook.
  - load_comparison: A percentual of time taken by an individual hook
                     compared to every other hook.

To enable benchmark, code must be compiled with -DBENCHMARK flag, this
will make the hook functions to be replaced by a function with the same
name plus a '_benchmark' suffix, e.g. hook_function_benchmark.

The hook_function_benchmark will call the original function and
calculate the amount of time it took to execute, than it will update
statistics for that hook.
2021-08-23 11:50:56 -04:00
Naeem Akhter 2e31738f15 PG-195: Change pgsm_bucket_time value from 300 to 60.
Changed the default value of pgsm_bucket_time from 300 to 60. Now neither PMM users will need to adjust the default value, nor
restart of PG server will be required for this purpose.
2021-08-17 18:23:15 +05:00
Diego Fronza 33b22e4ef2 PG-203: Fix memory leak.
The query_txt variable is allocated at the beginning of the
pg_stat_monitor_internal() function and released at the end, but an
extra malloc call to allocate it was added within an internal loop in
the funcion, thus allocating memory for every loop iteration, without
releasing the memory in the loop.

The query_txt variable can be reused inside the loop body, so this
commit removes the redundant declaration of query_txt from inside the
loop, which also fixes the leak.
2021-08-06 15:52:29 -04:00
Ibrar Ahmed 641c91980c
Merge pull request #93 from Naeem-Akhter/master
PG-218: Added Coverall code coverage to pg_stat_monitor.
2021-08-06 22:43:26 +05:00
Naeem Akhter 7d5b7e13a6 PG-218: Add Coverall code coverage to pg_stat_monitor.
Added 'Coverall' (https://coveralls.io) code coverage to pg_stat_monitor repo so that in future we don't have to perform this activity manually. Secondly, it will also make sure that code coverage detailed report link and status is readily available on repos github main page for each checkin (PR & Push), eventually helping in development velocity.
2021-08-06 18:24:41 +05:00
Ibrar Ahmed 661077ddf2
Merge pull request #87 from darkfronza/PG-200_add_appname_to_bucket_id
PG-200: Add application name to the bucket ID.
2021-08-03 17:35:02 +05:00
Ibrar Ahmed 5449a9da1d
Merge pull request #91 from Naeem-Akhter/master
DISTPG-271: Fix the failing 'relations' testcase on master branch.
2021-08-03 17:34:22 +05:00
Naeem Akhter 13501632b1 DISTPG-271: Fix the failing 'relations' testcase 2021-08-02 19:37:14 +05:00
Diego Fronza 99f01d37e3 PG-200: Add application name to the bucket ID.
Add application name to the key used to identify queries in the hash
table, this allows different applications to have separate entries in
pg_stat_monitor view if they issued the same query.
2021-07-29 15:05:08 -04:00
Ibrar Ahmed 7934ccbbdf
Merge pull request #86 from nastena1606/PG-198-Doc-update-accent-on-PPG
PG-198 Update readme with more attention to Percona Distribution
2021-07-29 21:59:34 +05:00
Anastasia Alexadrova 226cd0ba33 PG-198 Update readme with more attention to Percona Distribution
modified:   README.md
2021-07-29 18:00:40 +03:00
Ibrar Ahmed 88948d6a0a README file updated. 2021-07-27 13:41:31 +00:00
Ibrar Ahmed 81b88cf3cc PG-194: PostgreSQL 13.3 and 14 support.
PostgreSQL-14 GitHub Action added.
2021-07-27 13:39:23 +00:00
Ibrar Ahmed 6c2e052396 PG-194: PostgreSQL 13.3 and 14 support. 2021-07-27 13:37:13 +00:00
Ibrar Ahmed 1dcf596194 Merge branch 'master' of https://github.com/percona/pg_stat_monitor 2021-07-27 12:58:22 +00:00
Ibrar Ahmed 815e543bfe PG-194: PostgreSQL 13.3 and 14 support. 2021-07-27 12:57:29 +00:00
Ibrar Ahmed c329646b0f
Merge pull request #84 from darkfronza/PG-197_fix_conflict_pg_stat_statements
PG-197: Fix conflict with pg_stat_statements
2021-07-26 18:26:14 +05:00
Diego Fronza a3a4c99011 PG-197: Fix conflict with pg_stat_statements.
If pg_stat_monitor is loaded after pg_stat_statement, then it will end
up calling standard_planner function twice in the pgss_planner_hook()
function, this will trigger an assertion failure from PostgreSQL as this
function expects an untouched Query* object, and the first call to
standard_planner() done by pg_stat_statements modifies the object.

To address the problem, we avoid calling standard_planner function twice
in pg_stat_monitor, if a previous handler is installed for the hook
planner_hook, then we assume that this previous hook has already called
standard_planner function and don't do it again.
2021-07-26 10:16:29 -04:00
Roma Novikov 66385ab577
Update USER_GUIDE.md
typo fix
2021-06-08 18:19:38 +03:00
Ibrar Ahmed 2200ba8659 Merge branch 'master' of https://github.com/percona/pg_stat_monitor 2021-05-21 21:31:00 +05:00
Ibrar Ahmed f470ba591a PG-194: PostgreSQL-14 support added. 2021-05-21 21:29:58 +05:00
Ibrar Ahmed afb552dc8a
PG-193: Comment based tags to identify different parameters. 2021-05-19 22:17:07 +05:00
Ibrar Ahmed 67b3d961ca PG-193: Comment based tags to identify different parameters. 2021-05-19 22:15:37 +05:00