Compare commits

..

54 Commits
2.1.0 ... main

Author SHA1 Message Date
Zsolt Parragi 9e0a252873
PG-1674: Fix comment parsing logic at two places (#542)
* PG-1674: Fix query hash calculation comment removal logic

The previous conditions only removed the first few starting characters
of the comment, and leaved everything else there.

This modification fixes this and correctly removes everything.

* PG-1674: Fix performance issues with comment extraction

The previous logic used complex regex parsers, which caused performance
issues with large (megabyte sized) queries. This change removes the
regex dependency and uses the same (fixed) logic from the query hashing
code, which is much faster.

It also checks the related GUC variable, which the previous code
ignored: if we do not want to display extracted comments, we won't
extract them in the first place.

This commit doesn't try to address other issues with comment parsing logic:

* we shouldn't treat comment like things within strings as comments
* we should handle nested C style comments
* we don't extract `--` style comments

All of these issues are still there, as before.
2025-06-23 13:46:15 +01:00
Artem Gavrilov 3653dd6041
Add back case for zero cmd_type value in get_cmd_type function (#543) 2025-06-19 15:44:41 +02:00
Artem Gavrilov 76b0802142
PG-1313 Fix decode_error_level SQL function (#539)
Update decode_error_level funcion to support error codes up to PG
version 17.
2025-06-19 15:38:44 +02:00
Zsolt Parragi 61662cc58f
PG-1621: fix cmd_type mostly showing 0 values (#538)
This was actually caused by two bugs internally:

* cmd_type was only set in some codepaths, other parts of the code
never set a value. Depending on which query / how was executed,
it was possibly never changed (after a reset to 0)
* the update first set the cmd_type, then reset all counters. As
the cmd_type is stored within the counters for some reason, this
reset its value to 0 in most execution paths, even if it was corretly
set before.

And according to this the fix is simple:

* cmd_type is now set in all codepaths except for failing queries,
as we only have the error string in this case, without the type.
* in the update logic, we again overwrite cmd_type with the proper
value after a reset
2025-06-17 14:52:28 +01:00
dependabot[bot] f7dc7fb5fe
Bump github/codeql-action from 3.28.19 to 3.29.0 (#541)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.19 to 3.29.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](fca7ace96b...ce28f5bb42)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-17 14:25:52 +02:00
dependabot[bot] 38f13e893f
Bump github/codeql-action from 3.28.18 to 3.28.19 (#540)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.18 to 3.28.19.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](ff0a06e83c...fca7ace96b)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-11 14:09:21 +02:00
dependabot[bot] 9d2f2cd8cc
Bump ossf/scorecard-action from 2.4.1 to 2.4.2 (#537)
Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.1 to 2.4.2.
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](f49aabe0b5...05b42c6244)

---
updated-dependencies:
- dependency-name: ossf/scorecard-action
  dependency-version: 2.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-06 13:46:18 +02:00
dependabot[bot] d0237f8d83
Bump github/codeql-action from 3.28.17 to 3.28.18 (#534)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.17 to 3.28.18.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](60168efe1c...ff0a06e83c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-21 12:01:55 +02:00
dependabot[bot] d116dd47fe
Bump codecov/codecov-action from 5.4.2 to 5.4.3 (#535)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.2 to 5.4.3.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](ad3126e916...18283e04ce)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: 5.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-21 12:01:33 +02:00
dependabot[bot] 9c72c2e73d
Bump github/codeql-action from 3.28.16 to 3.28.17 (#533)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.16 to 3.28.17.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](28deaeda66...60168efe1c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-05 23:58:23 +02:00
dependabot[bot] 76424b6c64
Bump github/codeql-action from 3.28.14 to 3.28.16 (#532)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.14 to 3.28.16.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](fc7e4a0fa0...28deaeda66)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.16
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-28 20:44:08 +02:00
dependabot[bot] f76b1860e3
Bump codecov/codecov-action from 5.4.0 to 5.4.2 (#531)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.0 to 5.4.2.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](0565863a31...ad3126e916)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: 5.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-23 19:02:17 +02:00
Artem Gavrilov a7edd766e3
Update CODEOWNERS (#529) 2025-04-16 15:44:18 +02:00
Artem Gavrilov 24c1c59416
PG-1370 PGSM 2.1.1 release (#514)
PG-1370 Bump PGSM version up to 2.1.1
2025-04-09 18:57:44 +02:00
dependabot[bot] b860effd97
Bump github/codeql-action from 3.28.13 to 3.28.14 (#528)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.13 to 3.28.14.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](1b549b9259...fc7e4a0fa0)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.28.14
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-08 10:22:49 +02:00
dependabot[bot] 64b08e422c
Bump github/codeql-action from 3.28.11 to 3.28.13 (#525)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.11 to 3.28.13.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](6bb031afdd...1b549b9259)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-02 18:22:48 +02:00
dependabot[bot] acd559842f
Bump actions/upload-artifact from 4.6.1 to 4.6.2 (#526)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.6.1 to 4.6.2.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](4cec3d8aa0...ea165f8d65)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-02 18:22:24 +02:00
Muhammad Aqeel 8bbb49e409
Adds date timestamp to keep packages in different directories. (#527) 2025-03-27 16:31:25 +05:00
dependabot[bot] 7bddd5a033
Bump github/codeql-action from 3.28.10 to 3.28.11 (#524)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.10 to 3.28.11.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](b56ba49b26...6bb031afdd)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-11 14:24:19 +02:00
dependabot[bot] 5312f6f8a7
Bump actions/upload-artifact from 4.6.0 to 4.6.1 (#523)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.6.0 to 4.6.1.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](65c4c4a1dd...4cec3d8aa0)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-05 12:26:33 +02:00
dependabot[bot] c305b8a086
Bump github/codeql-action from 3.28.9 to 3.28.10 (#522)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.9 to 3.28.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](9e8d0789d4...b56ba49b26)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-05 12:25:58 +02:00
dependabot[bot] 8dcf24a879
Bump ossf/scorecard-action from 2.4.0 to 2.4.1 (#521)
Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.0 to 2.4.1.
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](62b2cac7ed...f49aabe0b5)

---
updated-dependencies:
- dependency-name: ossf/scorecard-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-05 12:25:36 +02:00
dependabot[bot] 32b1beb6ff
Bump codecov/codecov-action from 5.3.1 to 5.4.0 (#520)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.3.1 to 5.4.0.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](13ce06bfc6...0565863a31)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-05 12:25:14 +02:00
Andreas Karlsson 9333608c3a PG-1349 Remove call to LWLockRelease() in PG_CATCH()
It is not safe to release an LWLock in a catch section without
incrementing InterruptHoldoffCount so let's isntead simply not release
the lock here.
2025-02-20 17:30:24 +01:00
Andreas Karlsson 4ebb3d1f36 PG-1349 Prevent LWLock deadlocks from happening
Instead of trying to fix every case where we could throw an error and
handling that properly we just make sure to disable the error capture
of the hook while our backend holds the lock.

We keep the check for IsSystemOOM() in the hook even though that might
not be relevant anymore because if we are in OOM it is not like there
would be any point to log the error anyway.

This is done via a global variable, similar to the
__pgsm_do_not_capture_error variable that we are replacing, which we
also use in one place to disable recursive calls to the log hook
where we do not hold the lock.

A potential future improvement would be to make this variable a counter,
or have two separate globals, so that we could guard against recursive
calls to the hook running us out of stack and not just prevent the
deadlocks.
2025-02-20 11:38:37 +01:00
Artem Gavrilov fd43b75153
Revert "PG-156: replace query placeholders with actual arguments for… (#517)
Revert "PG -156: replace query placeholders with actual arguments for prepared statements (#481)"

This reverts commit c921d483a8.
2025-02-17 19:13:15 +02:00
Artem Gavrilov c949d21656
Add OSSF best practices badge (#507) 2025-02-14 14:34:31 +02:00
dependabot[bot] fbdff8b444
Bump apache/skywalking-eyes from 0.6.0 to 0.7.0 (#512)
Bumps [apache/skywalking-eyes](https://github.com/apache/skywalking-eyes) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/apache/skywalking-eyes/releases)
- [Changelog](https://github.com/apache/skywalking-eyes/blob/main/CHANGES.md)
- [Commits](cd7b195c51...5c5b974209)

---
updated-dependencies:
- dependency-name: apache/skywalking-eyes
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-11 11:35:44 +02:00
dependabot[bot] e099628e18
Bump github/codeql-action from 3.28.8 to 3.28.9 (#513)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.8 to 3.28.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](dd746615b3...9e8d0789d4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-11 11:35:16 +02:00
dependabot[bot] d2b2eafc85
Bump github/codeql-action from 3.28.5 to 3.28.8 (#511)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.5 to 3.28.8.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](f6091c0113...dd746615b3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-04 14:30:59 +02:00
dependabot[bot] ba8d7bd83b
Bump codecov/codecov-action from 5.1.2 to 5.3.1 (#509)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.1.2 to 5.3.1.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](1e68e06f1d...13ce06bfc6)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-01-28 16:04:20 +02:00
dependabot[bot] b47ae95fa8
Bump github/codeql-action from 3.28.1 to 3.28.5 (#510)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.1 to 3.28.5.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](b6a472f63d...f6091c0113)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-01-28 16:03:56 +02:00
Artem Gavrilov 980116acea
Add issue assingees (#508) 2025-01-24 12:01:44 -03:00
dependabot[bot] ef9518c98e
Bump github/codeql-action from 3.28.0 to 3.28.1 (#504)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.0 to 3.28.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](48ab28a6f5...b6a472f63d)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-01-14 14:59:26 +02:00
dependabot[bot] 2769e6dcb2
Bump actions/upload-artifact from 4.5.0 to 4.6.0 (#505)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.5.0 to 4.6.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](6f51ac03b9...65c4c4a1dd)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-01-14 14:59:01 +02:00
dependabot[bot] d0b67ef32a
Bump github/codeql-action from 3.27.9 to 3.28.0 (#503)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.9 to 3.28.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](df409f7d92...48ab28a6f5)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-23 19:38:41 +02:00
dependabot[bot] d008bbbfa7
Bump actions/upload-artifact from 4.4.3 to 4.5.0 (#502)
* Bump actions/upload-artifact from 4.4.3 to 4.5.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.4.3 to 4.5.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4.4.3...6f51ac03b9356f520e9adb1b1b7802705f340c2b)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update .github/workflows/scorecard.yml

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Artem Gavrilov <artem.gavrilov@percona.com>
2024-12-23 19:38:15 +02:00
dependabot[bot] 971c62025e
Bump codecov/codecov-action from 5.1.1 to 5.1.2 (#501)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.1.1 to 5.1.2.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](7f8b4b4bde...1e68e06f1d)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-23 19:36:56 +02:00
dependabot[bot] 8ed7f1dbb7
Bump github/codeql-action from 3.27.6 to 3.27.9 (#499)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.6 to 3.27.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](aa57810251...df409f7d92)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-16 19:55:54 +02:00
dependabot[bot] 2a5a2f07c4
Bump github/codeql-action from 3.27.5 to 3.27.6 (#498)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.5 to 3.27.6.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](f09c1c0a94...aa57810251)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-11 14:41:17 +02:00
dependabot[bot] 7d57e2476f
Bump codecov/codecov-action from 5.0.7 to 5.1.1 (#497)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.0.7 to 5.1.1.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](015f24e681...7f8b4b4bde)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-11 14:40:51 +02:00
dependabot[bot] 6c7512afa5
Bump codecov/codecov-action from 5.0.2 to 5.0.7 (#496)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.0.2 to 5.0.7.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](5c47607acb...015f24e681)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-25 21:21:02 +02:00
dependabot[bot] ee7f6d071f
Bump github/codeql-action from 3.27.4 to 3.27.5 (#495)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.4 to 3.27.5.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](ea9e4e3799...f09c1c0a94)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-25 21:20:38 +02:00
Muhammad Aqeel 7f1344e12d
Fixes llvm-devel package installation issue. (#494) 2024-11-22 12:27:18 +05:00
Artem Gavrilov 85f0401b96
Create pull_request_template.md (#489) 2024-11-19 09:31:37 +01:00
dependabot[bot] df65136090
Bump codecov/codecov-action from 4.6.0 to 5.0.2 (#491)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.6.0 to 5.0.2.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](b9fd7d16f6...5c47607acb)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-18 22:21:04 +02:00
dependabot[bot] 534790f39b
Bump ossf/scorecard-action from 2.3.1 to 2.4.0 (#492)
Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.3.1 to 2.4.0.
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](0864cf1902...62b2cac7ed)

---
updated-dependencies:
- dependency-name: ossf/scorecard-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-18 22:20:38 +02:00
dependabot[bot] 646f01420f
Bump github/codeql-action from 3.27.3 to 3.27.4 (#493)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.3 to 3.27.4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](396bb3e453...ea9e4e3799)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-18 22:20:11 +02:00
dependabot[bot] c63e172100
Bump actions/checkout from 4.1.1 to 4.2.2 (#490)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.2.2.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4.1.1...11bd71901bbe5b1630ceea73d27597364c9af683)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-18 22:19:34 +02:00
StepSecurity Bot 091b5866d4
[StepSecurity] ci: Harden GitHub Actions (#488)
Signed-off-by: StepSecurity Bot <bot@stepsecurity.io>
2024-11-14 15:19:16 +02:00
Artem Gavrilov 186c2e4795
Add OSSF Scorecard (#487)
* Create scorecard.yml

* Add OSSF scorecard badge

* Update README.md
2024-11-14 11:11:37 +02:00
Diego Fronza c921d483a8
PG -156: replace query placeholders with actual arguments for prepared statements (#481)
* Denormalize prepared statement queries

Added support for extracting query arguments for prepared statements
when `pg_stat_monitor.pgsm_normalized_query` is off.

Previously pg_stat_monitor was unable to extract the arguments for
prepared statements, thus leaving queries with placeholders $1
.. $N instead of the actual arguments.

* Optmize query denormalization

Instead of copying original query text byte by byte, copy data between
query placeholders in chunks, example:

`INSERT INTO foo(a, b, c) VALUES('test', 100, 'test again)'`

Would result in normalized query:

`INSERT INTO foo(a, b, c) VALUES($1, $2, $3)`

The original patch would copy the parts between placeholders byte by
byte, e.g. `INSERT INTO foo(a, b, c) VALUES(`, instead we can copy this
whole block at once, 1 function call and maybe 1 buffer re-allocation
per call.

Also make use of `appendBinaryStringInfo` to avoid calculating string
length as we have this info already.

* Optmize query denormalization(2)

Avoid allocating an array of strings for extracting query argument
values, instead append the current parameter value directly in the
buffer used to store the denormalized query.

This avoids not only unnecessary memory allocations, but also copying
data between temporary memory and the buffer.

* Store denormalized query only under certain constraints

This commit introduces a little optimization along with a feature, it
stores the query in denormalized form only under the circumstances
below:

- The psgm_normalized_query GUC is disabled (off).
- The query is seem for the first time, or the query total
  execution time exceeds the mean execution time calculated for
  the previous queries.

Having the query which took most execution time along with it's
arguments could help users in further investigating performance issues.

* Fix regression tests

When query normalization is disabled utility queries like SELECT 10+20
are now stored as is, instead of SELECT $1+$2.

Also when functions or sub queries are created the arguments used
internally by the function or subqueries will be replaced by NULL instead
of $1..$N. The actual arguments will be displayed when the function or
subquery is actually invoked.

* Add query denormalization regression test for prepared statements

Ensures that the denormalization of prepared statements is working, also
ensure that a query which takes more time to execute replaces the
previous denormalized query.

* Updated pgsm_query_id regression tests

With the query dernomalization feature, having integer literals used in
sql like 1, or 2 could create some confusion on whether those are
placeholders or constant values, thus this commit updates the
pgsm_query_id regression test to use different integer literals to avoid
confusion.

* Improve query denormalization regression test

Add a new test case:

1. Execute a prepared statement with larger execution time first.
2. Execute the same prepared statement with cheap execution time.
3. Ensures that the denormalized heavy query is not replaced by the
   cheaper.

* Format source using pgindent

* Fix top query regression tests on PG 12,13

On PG 12, 13, the internal return instruction in the following function:
```
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS
  $$
  BEGIN
     return (select $1 + $2);
  END; $$ language plpgsql;
```

Is stored as SELECT (select expr1 + expr2)

On PG 14 onward it's stored just as SELECT (expr1 + expr2)
2024-11-01 19:28:16 -03:00
Artem Gavrilov 467394fb6e
Add timeouts to CI jobs (#484) 2024-08-26 12:00:58 -03:00
Artem Gavrilov bcf7bed60b
Use PG17-beta3 (#483) 2024-08-16 11:52:31 -03:00
44 changed files with 522 additions and 205 deletions

2
.github/CODEOWNERS vendored
View File

@ -1,4 +1,4 @@
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
# Order is important; the last matching pattern takes the most precedence.
* @artemgavrilov @darkfronza
* @artemgavrilov @dutow

View File

@ -1,7 +1,10 @@
name: Bug Report
description: File a bug report
labels: ["bug"]
assignees: []
assignees:
- artemgavrilov
- dutow
body:
- type: markdown
attributes:

View File

@ -1,7 +1,10 @@
name: Feature Request
description: Suggest an idea for this project
labels: ["feature"]
assignees: []
assignees:
- artemgavrilov
- dutow
body:
- type: markdown
attributes:

9
.github/pull_request_template.md vendored Normal file
View File

@ -0,0 +1,9 @@
PG-0
### Description
<!--- Describe your changes in detail -->
### Links
<!--- Please provide links to any related PRs in this or other repositories --->

View File

@ -6,15 +6,16 @@ jobs:
cppcheck:
name: Cppcheck
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Checkout sources
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: src/pg_stat_monitor
- name: Checkout cppcheck sources
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: "danmar/cppcheck"
ref: "2.13.4"
@ -38,16 +39,17 @@ jobs:
format:
name: Format
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_17_STABLE'
- name: Checkout sources
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'contrib/pg_stat_monitor'
@ -81,12 +83,13 @@ jobs:
license:
name: License
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Checkout sources
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Check license headers
uses: apache/skywalking-eyes/header@v0.6.0
uses: apache/skywalking-eyes/header@5c5b974209f0de5d905f37deb69369068ebfc15c # v0.7.0
with:
token: "" # Prevent comments

View File

@ -5,13 +5,18 @@ on:
branches:
- main
permissions:
contents: read
jobs:
build:
name: coverage-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_15_STABLE'
@ -78,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -108,7 +113,7 @@ jobs:
working-directory: src/pg_stat_monitor
- name: Upload
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
@ -125,7 +130,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,10 +7,14 @@ on:
required: true
type: string
permissions:
contents: read
jobs:
release:
name: Release
runs-on: ubuntu-22.04
timeout-minutes: 10
container: pgxn/pgxn-tools
steps:
- name: Validate version tag
@ -18,7 +22,7 @@ jobs:
shell: bash
- name: Check out
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: '${{ inputs.version }}'

View File

@ -7,13 +7,18 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-12-build-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_12_STABLE'
@ -79,7 +84,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -113,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |
@ -136,7 +141,7 @@ jobs:
make installcheck-world
- name: Report on installcheck-world test suites fail
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -7,13 +7,18 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-12-pgdg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -75,7 +80,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,6 +7,9 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-12-pgsm-pmm-integration-test
@ -14,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'
@ -39,7 +42,7 @@ jobs:
run: docker exec pgsql_pgsm_12 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
- name: Upload Tests Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-12-ppg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -91,7 +95,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-13-build-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_13_STABLE'
@ -79,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -113,7 +117,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |
@ -136,7 +140,7 @@ jobs:
make installcheck-world
- name: Report on installcheck-world test suites fail
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-13-pgdg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -75,7 +79,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,6 +7,9 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-13-pgsm-pmm-integration-test
@ -14,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'
@ -39,7 +42,7 @@ jobs:
run: docker exec pgsql_pgsm_13 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
- name: Upload Tests Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-13-ppg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -88,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-14-build-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_14_STABLE'
@ -79,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -114,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |
@ -136,7 +140,7 @@ jobs:
run: make installcheck-world
- name: Report on installcheck-world test suites fail
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-14-pgdg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -74,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,6 +7,9 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-14-pgsm-pmm-integration-test
@ -14,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'
@ -39,7 +42,7 @@ jobs:
run: docker exec pgsql_pgsm_14 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
- name: Upload Tests Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-14-ppg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -88,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-15-build-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_15_STABLE'
@ -79,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -114,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |
@ -136,7 +140,7 @@ jobs:
run: make installcheck-world
- name: Report on installcheck-world test suites fail
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-15-pgdg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -74,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,6 +7,9 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-15-pgsm-pmm-integration-test
@ -14,7 +17,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'
@ -39,7 +42,7 @@ jobs:
run: docker exec pgsql_pgsm_15 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
- name: Upload Tests Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-15-ppg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -88,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-16-build-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_16_STABLE'
@ -79,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -114,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |
@ -136,7 +140,7 @@ jobs:
run: make installcheck-world
- name: Report on installcheck-world test suites fail
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-16-pgdg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -74,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-16-ppg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -88,7 +92,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

View File

@ -7,16 +7,20 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-17-build-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone postgres repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: 'postgres/postgres'
ref: 'REL_17_BETA2' # TODO: Replace with REL_17_STABLE
ref: 'REL_17_STABLE'
- name: Install dependencies
run: |
@ -79,7 +83,7 @@ jobs:
pg_ctl -D /opt/pgsql/data -l logfile start
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -114,7 +118,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |
@ -136,7 +140,7 @@ jobs:
run: make installcheck-world
- name: Report on installcheck-world test suites fail
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: Regressions output files of failed testsuite, and pg log

View File

@ -7,13 +7,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: read
jobs:
build:
name: pg-17-pgdg-package-test
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- name: Clone pg_stat_monitor repository
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: 'src/pg_stat_monitor'
@ -74,7 +78,7 @@ jobs:
- name: Upload logs on fail
if: ${{ failure() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: Regressions diff and postgresql log
path: |

48
.github/workflows/scorecard.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: Scorecard
on:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: "24 3 * * 1"
push:
branches:
- main
# Declare default permissions as read only.
permissions: read-all
jobs:
analysis:
name: Analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Run analysis
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- name: Upload results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: SARIF file
path: results.sarif
retention-days: 5
# Upload the results to GitHub's code scanning dashboard (optional).
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
with:
sarif_file: results.sarif

View File

@ -2,7 +2,7 @@
"name": "pg_stat_monitor",
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"description": "pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL's contrib module pg_stat_statements. PostgreSQL’s pg_stat_statements provides the basic statistics, which is sometimes not enough. The major shortcoming in pg_stat_statements is that it accumulates all the queries and their statistics and does not provide aggregated statistics nor histogram information. In this case, a user would need to calculate the aggregates, which is quite an expensive operation.",
"version": "2.1.0",
"version": "2.1.1",
"maintainer": [
"Artem Gavrilov <artem.gavrilov@percona.com>",
"Diego dos Santos Fronza <diego.fronza@percona.com>"
@ -15,7 +15,7 @@
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"file": "pg_stat_monitor--2.0--2.1.sql",
"docfile": "README.md",
"version": "2.1.0"
"version": "2.1.1"
}
},
"prereqs": {

View File

@ -4,7 +4,7 @@ MODULE_big = pg_stat_monitor
OBJS = hash_query.o guc.o pg_stat_monitor.o $(WIN32RES)
EXTENSION = pg_stat_monitor
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql
DATA = pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql pg_stat_monitor--2.0--2.1.sql pg_stat_monitor--2.1--2.2.sql
PGFILEDESC = "pg_stat_monitor - execution statistics of SQL statements"
@ -12,7 +12,26 @@ LDFLAGS_SL += $(filter -lm, $(LIBS))
TAP_TESTS = 1
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_monitor/pg_stat_monitor.conf --inputdir=regression
REGRESS = basic version guc pgsm_query_id functions counters relations database error_insert application_name application_name_unique top_query different_parent_queries cmd_type error rows tags user level_tracking
REGRESS = basic \
version \
guc \
pgsm_query_id \
functions \
counters \
relations \
database \
error_insert \
application_name \
application_name_unique \
top_query \
different_parent_queries \
cmd_type \
error \
rows \
tags \
user \
level_tracking \
decode_error_level
# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
# which typical installcheck users do not have (e.g. buildfarm clients).

View File

@ -6,6 +6,8 @@
[![postgresql-17-pgdg-package](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-17-pgdg-package.yml/badge.svg)](https://github.com/percona/pg_stat_monitor/actions/workflows/postgresql-17-pgdg-package.yml)
[![PGXN version](https://badge.fury.io/pg/pg_stat_monitor.svg)](https://badge.fury.io/pg/pg_stat_monitor)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/percona/pg_stat_monitor/badge)](https://scorecard.dev/viewer/?uri=github.com/percona/pg_stat_monitor)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9703/badge)](https://www.bestpractices.dev/projects/9703)
[![Code coverage](https://codecov.io/gh/percona/pg_stat_monitor/branch/main/graph/badge.svg)](https://codecov.io/gh/percona/pg_stat_monitor)
[![Forum](https://img.shields.io/badge/Forum-join-brightgreen)](https://forums.percona.com/)
# pg_stat_monitor: Query Performance Monitoring Tool for PostgreSQL

View File

@ -17,6 +17,7 @@ install_data(
'pg_stat_monitor--2.0.sql',
'pg_stat_monitor--1.0--2.0.sql',
'pg_stat_monitor--2.0--2.1.sql',
'pg_stat_monitor--2.1--2.2.sql',
kwargs: contrib_data_args,
)

View File

@ -162,7 +162,8 @@ get_sources(){
source pg-stat-monitor.properties
#
tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT_FULL}.tar.gz ${PRODUCT_FULL}
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${BUILD_ID}" >> pg-stat-monitor.properties
DATE_TIMESTAMP=$(date +%F_%H-%M-%S)
echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${DATE_TIMESTAMP}/${BUILD_ID}" >> pg-stat-monitor.properties
mkdir $WORKDIR/source_tarball
mkdir $CURDIR/source_tarball
cp ${PRODUCT_FULL}.tar.gz $WORKDIR/source_tarball
@ -211,17 +212,18 @@ install_deps() {
if [ x"$RHEL" = x8 ];
then
clang_version=$(yum list --showduplicates clang-devel | grep "17.0" | grep clang | awk '{print $2}' | head -n 1)
yum install -y clang-devel-${clang_version} clang-${clang_version}
clang_version=$(yum list --showduplicates clang-devel | grep "17.0" | grep clang | awk '{print $2}' | head -n 1)
llvm_version=$(yum list --showduplicates llvm-devel | grep "17.0" | grep llvm | awk '{print $2}' | head -n 1)
yum install -y clang-devel-${clang_version} clang-${clang_version} llvm-devel-${llvm_version}
dnf module -y disable llvm-toolset
else
yum install -y clang-devel clang
yum install -y clang-devel clang llvm-devel
fi
PKGLIST="percona-postgresql${PG_RELEASE}-devel"
PKGLIST+=" git llvm-devel rpmdevtools vim wget"
PKGLIST+=" git rpmdevtools vim wget"
PKGLIST+=" perl binutils gcc gcc-c++"
PKGLIST+=" llvm-devel git rpm-build rpmdevtools wget gcc make autoconf"
PKGLIST+=" git rpm-build rpmdevtools wget gcc make autoconf"
if [[ "${RHEL}" -ge 8 ]]; then
dnf config-manager --set-enabled ol${RHEL}_codeready_builder
dnf -y module disable postgresql || true

View File

@ -0,0 +1,48 @@
/* contrib/pg_stat_monitor/pg_stat_monitor--2.1--2.2.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION pg_stat_monitor" to load this file. \quit
CREATE OR REPLACE FUNCTION get_cmd_type (cmd_type INTEGER) RETURNS TEXT AS
$$
SELECT
CASE
WHEN cmd_type = 0 THEN ''
WHEN cmd_type = 1 THEN 'SELECT'
WHEN cmd_type = 2 THEN 'UPDATE'
WHEN cmd_type = 3 THEN 'INSERT'
WHEN cmd_type = 4 THEN 'DELETE'
WHEN cmd_type = 5 AND current_setting('server_version_num')::int >= 150000 THEN 'MERGE'
WHEN cmd_type = 5 AND current_setting('server_version_num')::int < 150000 THEN 'UTILITY'
WHEN cmd_type = 6 AND current_setting('server_version_num')::int >= 150000 THEN 'UTILITY'
WHEN cmd_type = 6 AND current_setting('server_version_num')::int < 150000 THEN 'NOTHING'
WHEN cmd_type = 7 THEN 'NOTHING'
END
$$
LANGUAGE SQL PARALLEL SAFE;
-- Create new function that handles error levels across PostgreSQL versions 12-17
CREATE OR REPLACE FUNCTION decode_error_level(elevel int)
RETURNS text
AS $$
SELECT CASE
WHEN elevel = 0 THEN ''
WHEN elevel = 10 THEN 'DEBUG5'
WHEN elevel = 11 THEN 'DEBUG4'
WHEN elevel = 12 THEN 'DEBUG3'
WHEN elevel = 13 THEN 'DEBUG2'
WHEN elevel = 14 THEN 'DEBUG1'
WHEN elevel = 15 THEN 'LOG'
WHEN elevel = 16 THEN 'LOG_SERVER_ONLY'
WHEN elevel = 17 THEN 'INFO'
WHEN elevel = 18 THEN 'NOTICE'
WHEN elevel = 19 THEN 'WARNING'
WHEN elevel = 20 AND current_setting('server_version_num')::int < 140000 THEN 'ERROR'
WHEN elevel = 20 AND current_setting('server_version_num')::int >= 140000 THEN 'WARNING_CLIENT_ONLY'
WHEN elevel = 21 AND current_setting('server_version_num')::int < 140000 THEN 'FATAL'
WHEN elevel = 21 AND current_setting('server_version_num')::int >= 140000 THEN 'ERROR'
WHEN elevel = 22 AND current_setting('server_version_num')::int < 140000 THEN 'PANIC'
WHEN elevel = 22 AND current_setting('server_version_num')::int >= 140000 THEN 'FATAL'
WHEN elevel = 23 AND current_setting('server_version_num')::int >= 140000 THEN 'PANIC'
END;
$$ LANGUAGE SQL PARALLEL SAFE;

View File

@ -19,7 +19,6 @@
#include "access/parallel.h"
#include "nodes/pg_list.h"
#include "utils/guc.h"
#include <regex.h>
#include "pgstat.h"
#include "commands/dbcommands.h"
#include "commands/explain.h"
@ -37,7 +36,7 @@ typedef enum pgsmVersion
PG_MODULE_MAGIC;
#define BUILD_VERSION "2.1.0"
#define BUILD_VERSION "2.2.0"
/* Number of output arguments (columns) for various API versions */
#define PG_STAT_MONITOR_COLS_V1_0 52
@ -96,8 +95,6 @@ uint64 *nested_queryids;
char **nested_query_txts;
List *lentries = NIL;
/* Regex object used to extract query comments. */
static regex_t preg_query_comments;
static char relations[REL_LST][REL_LEN];
static int num_relations; /* Number of relation in the query */
@ -203,7 +200,7 @@ char *unpack_sql_state(int sql_state);
static pgsmEntry *pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info);
static void pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len);
static pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create);
static pgsmEntry *pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create, CmdType cmd_type);
static uint64 get_pgsm_query_id_hash(const char *norm_query, int len);
static void pgsm_cleanup_callback(void *arg);
@ -261,6 +258,18 @@ static int comp_location(const void *a, const void *b);
static uint64 get_next_wbucket(pgsmSharedState *pgsm);
/*
* To prevent deadlocks against our own backend we need to disable error
* capture while holding the LWLock. The error capture hook is resposible
* itself for re-enabling data capture when called on ERROR or above since
* then we may not have been able to call pgsm_lock_release() due to the
* statement being aborted.
*/
static bool disable_error_capture = false;
static void pgsm_lock_aquire(pgsmSharedState *pgsm, LWLockMode mode);
static void pgsm_lock_release(pgsmSharedState *pgsm);
/*
* Module load callback
*/
@ -268,8 +277,6 @@ static uint64 get_next_wbucket(pgsmSharedState *pgsm);
void
_PG_init(void)
{
int rc;
elog(DEBUG2, "[pg_stat_monitor] pg_stat_monitor: %s().", __FUNCTION__);
/*
@ -297,18 +304,8 @@ _PG_init(void)
EnableQueryId();
#endif
EmitWarningsOnPlaceholders("pg_stat_monitor");
/*
* Compile regular expression for extracting out query comments only once.
*/
rc = regcomp(&preg_query_comments, "/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/", REG_EXTENDED);
if (rc != 0)
{
elog(ERROR, "[pg_stat_monitor] _PG_init: query comments regcomp() failed, return code=(%d).", rc);
}
/*
* Install hooks.
*/
@ -724,7 +721,7 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
if (queryId != UINT64CONST(0) && queryDesc->totaltime && pgsm_enabled(nesting_level))
{
entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true);
entry = pgsm_get_entry_for_query(queryId, plan_ptr, (char *) queryDesc->sourceText, strlen(queryDesc->sourceText), true, queryDesc->operation);
if (!entry)
{
elog(DEBUG2, "[pg_stat_monitor] pgsm_ExecutorEnd: Failed to find entry for [%lu] %s.", queryId, queryDesc->sourceText);
@ -751,6 +748,8 @@ pgsm_ExecutorEnd(QueryDesc *queryDesc)
sys_info.stime = time_diff(rusage_end.ru_stime, rusage_start.ru_stime);
}
entry->counters.info.cmd_type = queryDesc->operation;
pgsm_update_entry(entry, /* entry */
NULL, /* query */
NULL, /* comments */
@ -896,7 +895,7 @@ pgsm_planner_hook(Query *parse, const char *query_string, int cursorOptions, Par
INSTR_TIME_SET_CURRENT(start);
if (MemoryContextIsValid(MessageContext))
entry = pgsm_get_entry_for_query(parse->queryId, NULL, query_string, strlen(query_string), true);
entry = pgsm_get_entry_for_query(parse->queryId, NULL, query_string, strlen(query_string), true, parse->commandType);
#if PG_VERSION_NUM >= 170000
nesting_level++;
@ -1187,7 +1186,7 @@ pgsm_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
query_text = (char *) CleanQuerytext(queryString, &location, &query_len);
entry->pgsm_query_id = get_pgsm_query_id_hash(query_text, query_len);
entry->counters.info.cmd_type = 0;
entry->counters.info.cmd_type = pstmt->commandType;
pgsm_add_to_list(entry, query_text, query_len);
@ -1729,7 +1728,7 @@ pgsm_add_to_list(pgsmEntry *entry, char *query_text, int query_len)
}
static pgsmEntry *
pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create)
pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_text, int query_len, bool create, CmdType cmd_type)
{
pgsmEntry *entry = NULL;
ListCell *lc = NULL;
@ -1766,6 +1765,7 @@ pgsm_get_entry_for_query(uint64 queryid, PlanInfo *plan_info, const char *query_
* worry about these.
*/
entry->pgsm_query_id = get_pgsm_query_id_hash(query_text, query_len);
entry->counters.info.cmd_type = cmd_type;
pgsm_add_to_list(entry, (char *) query_text, query_len);
}
@ -1967,7 +1967,7 @@ pgsm_store(pgsmEntry *entry)
* Acquire a share lock to start with. We'd have to acquire exclusive if
* we need to create the entry.
*/
LWLockAcquire(pgsm->lock, LW_SHARED);
pgsm_lock_aquire(pgsm, LW_SHARED);
shared_hash_entry = (pgsmEntry *) pgsm_hash_find(get_pgsmHash(), &entry->key, &found);
if (!shared_hash_entry)
@ -1985,7 +1985,7 @@ pgsm_store(pgsmEntry *entry)
dsa_query_pointer = dsa_allocate_extended(query_dsa_area, query_len + 1, DSA_ALLOC_NO_OOM | DSA_ALLOC_ZERO);
if (!DsaPointerIsValid(dsa_query_pointer))
{
LWLockRelease(pgsm->lock);
pgsm_lock_release(pgsm);
return;
}
@ -1996,30 +1996,25 @@ pgsm_store(pgsmEntry *entry)
query_buff = dsa_get_address(query_dsa_area, dsa_query_pointer);
memcpy(query_buff, query, query_len);
LWLockRelease(pgsm->lock);
LWLockAcquire(pgsm->lock, LW_EXCLUSIVE);
pgsm_lock_release(pgsm);
pgsm_lock_aquire(pgsm, LW_EXCLUSIVE);
/* OK to create a new hashtable entry */
PGSM_DISABLE_ERROR_CAPUTRE();
PG_TRY();
{
PG_TRY();
{
shared_hash_entry = hash_entry_alloc(pgsm, &entry->key, GetDatabaseEncoding());
}
PG_CATCH();
{
LWLockRelease(pgsm->lock);
if (DsaPointerIsValid(dsa_query_pointer))
dsa_free(query_dsa_area, dsa_query_pointer);
PG_RE_THROW();
}
PG_END_TRY();
} PGSM_END_DISABLE_ERROR_CAPTURE();
shared_hash_entry = hash_entry_alloc(pgsm, &entry->key, GetDatabaseEncoding());
}
PG_CATCH();
{
if (DsaPointerIsValid(dsa_query_pointer))
dsa_free(query_dsa_area, dsa_query_pointer);
PG_RE_THROW();
}
PG_END_TRY();
if (shared_hash_entry == NULL)
{
LWLockRelease(pgsm->lock);
pgsm_lock_release(pgsm);
if (DsaPointerIsValid(dsa_query_pointer))
dsa_free(query_dsa_area, dsa_query_pointer);
@ -2032,14 +2027,13 @@ pgsm_store(pgsmEntry *entry)
{
pgsm->pgsm_oom = true;
PGSM_DISABLE_ERROR_CAPUTRE();
{
ereport(WARNING,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("[pg_stat_monitor] pgsm_store: Hash table is out of memory and can no longer store queries!"),
errdetail("You may reset the view or when the buckets are deallocated, pg_stat_monitor will resume saving " \
"queries. Alternatively, try increasing the value of pg_stat_monitor.pgsm_max.")));
} PGSM_END_DISABLE_ERROR_CAPTURE();
disable_error_capture = true;
ereport(WARNING,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("[pg_stat_monitor] pgsm_store: Hash table is out of memory and can no longer store queries!"),
errdetail("You may reset the view or when the buckets are deallocated, pg_stat_monitor will resume saving " \
"queries. Alternatively, try increasing the value of pg_stat_monitor.pgsm_max.")));
disable_error_capture = false;
}
return;
@ -2081,8 +2075,13 @@ pgsm_store(pgsmEntry *entry)
reset, /* reset */
PGSM_STORE);
if (reset)
{
shared_hash_entry->counters.info.cmd_type = entry->counters.info.cmd_type;
}
memset(&entry->counters, 0, sizeof(entry->counters));
LWLockRelease(pgsm->lock);
pgsm_lock_release(pgsm);
}
/*
@ -2100,10 +2099,10 @@ pg_stat_monitor_reset(PG_FUNCTION_ARGS)
errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries")));
pgsm = pgsm_get_ss();
LWLockAcquire(pgsm->lock, LW_EXCLUSIVE);
pgsm_lock_aquire(pgsm, LW_EXCLUSIVE);
hash_entry_dealloc(-1, -1, NULL);
LWLockRelease(pgsm->lock);
pgsm_lock_release(pgsm);
PG_RETURN_VOID();
}
@ -2237,7 +2236,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
MemoryContextSwitchTo(oldcontext);
pgsm = pgsm_get_ss();
LWLockAcquire(pgsm->lock, LW_SHARED);
pgsm_lock_aquire(pgsm, LW_SHARED);
pgsm_hash_seq_init(&hstat, get_pgsmHash(), false);
while ((entry = pgsm_hash_seq_next(&hstat)) != NULL)
@ -2602,7 +2601,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
}
/* clean up and return the tuplestore */
pgsm_hash_seq_term(&hstat);
LWLockRelease(pgsm->lock);
pgsm_lock_release(pgsm);
}
static uint64
@ -2652,10 +2651,10 @@ get_next_wbucket(pgsmSharedState *pgsm)
/* Update bucket id and retrieve the previous one. */
prev_bucket_id = pg_atomic_exchange_u64(&pgsm->current_wbucket, new_bucket_id);
LWLockAcquire(pgsm->lock, LW_EXCLUSIVE);
pgsm_lock_aquire(pgsm, LW_EXCLUSIVE);
hash_entry_dealloc(new_bucket_id, prev_bucket_id, NULL);
LWLockRelease(pgsm->lock);
pgsm_lock_release(pgsm);
/* Allign the value in prev_bucket_sec to the bucket start time */
tv.tv_sec = (tv.tv_sec) - (tv.tv_sec % pgsm_bucket_time);
@ -2701,12 +2700,19 @@ get_pgsm_query_id_hash(const char *norm_query, int norm_len)
*/
if (*norm_q_iter == '/' && *(norm_q_iter + 1) == '*')
{
while (*norm_q_iter && *norm_q_iter != '*' && *(norm_q_iter + 1) != '/')
while (*norm_q_iter && *(norm_q_iter + 1) && (*norm_q_iter != '*' || *(norm_q_iter + 1) != '/'))
norm_q_iter++;
/* Skip the '/' if the current character is valid. */
/*
* Skip the end if the current character is valid. norm_q_iter
* points to the *, we have to skip 2 characters
*/
if (*norm_q_iter)
norm_q_iter++;
if (*norm_q_iter)
norm_q_iter++;
continue;
}
/*
@ -3754,12 +3760,12 @@ pgsm_emit_log_hook(ErrorData *edata)
if (MyProc == NULL)
goto exit;
/* Do not store */
if (PGSM_ERROR_CAPTURE_ENABLED && edata->elevel >= WARNING && IsSystemOOM() == false)
{
pgsm_store_error(debug_query_string ? debug_query_string : "",
edata);
}
if (edata->elevel >= WARNING && !disable_error_capture && IsSystemOOM() == false)
pgsm_store_error(debug_query_string ? debug_query_string : "", edata);
/* We need to make sure we re-enble error capture if query was aborted */
if (edata->elevel >= ERROR)
disable_error_capture = false;
exit:
if (prev_emit_log_hook)
prev_emit_log_hook(edata);
@ -3956,46 +3962,70 @@ get_histogram_timings(PG_FUNCTION_ARGS)
return CStringGetTextDatum(text_str);
}
static bool
append_comment_char(char *comments, size_t max_len, size_t *idx, char c)
{
if (*idx >= max_len)
return false;
comments[*idx] = c;
(*idx)++;
return true;
}
static void
extract_query_comments(const char *query, char *comments, size_t max_len)
{
int rc;
size_t nmatch = 1;
regmatch_t pmatch;
regoff_t comment_len,
total_len = 0;
const char *s = query;
size_t curr_len = 0;
const char *q_iter = query;
while (total_len < max_len)
if (!pgsm_extract_comments)
{
rc = regexec(&preg_query_comments, s, nmatch, &pmatch, 0);
if (rc != 0)
break;
comments[0] = 0;
return;
}
comment_len = pmatch.rm_eo - pmatch.rm_so;
if (total_len + comment_len > max_len)
break; /* TODO: log error in error view, insufficient
* space for comment. */
total_len += comment_len;
/* Not 1st iteration, append ", " before next comment. */
if (s != query)
while (q_iter && *q_iter)
{
/*
* multiline comments, + 1 is safe even if we've reach end of string
*/
if (*q_iter == '/' && *(q_iter + 1) == '*')
{
if (total_len + 2 > max_len)
break; /* TODO: log error in error view, insufficient
* space for ", " + comment. */
if (curr_len != 0)
{
if (!append_comment_char(comments, max_len, &curr_len, ','))
return;
if (!append_comment_char(comments, max_len, &curr_len, ' '))
return;
}
while (*q_iter && *(q_iter + 1) && (*q_iter != '*' || *(q_iter + 1) != '/'))
{
if (!append_comment_char(comments, max_len, &curr_len, *q_iter))
return;
q_iter++;
}
memcpy(comments, ", ", 2);
comments += 2;
total_len += 2;
if (*q_iter)
{
if (!append_comment_char(comments, max_len, &curr_len, *q_iter))
return;
q_iter++;
}
if (*q_iter)
{
if (!append_comment_char(comments, max_len, &curr_len, *q_iter))
return;
q_iter++;
}
}
memcpy(comments, s + pmatch.rm_so, comment_len);
comments += comment_len;
s += pmatch.rm_eo;
q_iter++;
}
comments[curr_len] = 0;
}
#if PG_VERSION_NUM < 140000
@ -4018,3 +4048,18 @@ get_query_id(JumbleState *jstate, Query *query)
return queryid;
}
#endif
static void
pgsm_lock_aquire(pgsmSharedState *pgsm, LWLockMode mode)
{
/* Disable error capturing while holding the lock to avoid deadlocks */
LWLockAcquire(pgsm->lock, mode);
disable_error_capture = true;
}
static void
pgsm_lock_release(pgsmSharedState *pgsm)
{
disable_error_capture = false;
LWLockRelease(pgsm->lock);
}

View File

@ -1,5 +1,5 @@
# pg_stat_monitor extension
comment = 'The pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL contrib module pg_stat_statements. pg_stat_monitor provides aggregated statistics, client information, plan details including plan, and histogram information.'
default_version = '2.1'
default_version = '2.2'
module_pathname = '$libdir/pg_stat_monitor'
relocatable = true

View File

@ -112,31 +112,6 @@
/* Update this if need a enum GUC with more options. */
#define MAX_ENUM_OPTIONS 6
/*
* API for disabling error capture ereport(ERROR,..) by PGSM's error capture hook
* pgsm_emit_log_hook()
*
* Use these macros as follows:
* PGSM_DISABLE_ERROR_CAPUTRE();
* {
* ... code that might throw ereport(ERROR) ...
* }PGSM_END_DISABLE_ERROR_CAPTURE();
*
* These macros can be used to error recursion if the error gets
* thrown from within the function called from pgsm_emit_log_hook()
*/
extern volatile bool __pgsm_do_not_capture_error;
#define PGSM_DISABLE_ERROR_CAPUTRE() \
do { \
__pgsm_do_not_capture_error = true
#define PGSM_END_DISABLE_ERROR_CAPTURE() \
__pgsm_do_not_capture_error = false; \
} while (0)
#define PGSM_ERROR_CAPTURE_ENABLED \
__pgsm_do_not_capture_error == false
/*
* pg_stat_monitor uses the hash structure to store all query statistics
* except the query text, which gets stored out of line in the raw DSA area.

View File

@ -27,16 +27,16 @@ DROP TABLE t2;
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | cmd_type | cmd_type_text
--------------------------------+----------+---------------
CREATE TABLE t1 (a INTEGER) | 0 |
CREATE TABLE t2 (b INTEGER) | 0 |
CREATE TABLE t1 (a INTEGER) | 5 | UTILITY
CREATE TABLE t2 (b INTEGER) | 5 | UTILITY
DELETE FROM t1 | 4 | DELETE
DROP TABLE t1 | 0 |
DROP TABLE t2 | 0 |
DROP TABLE t1 | 5 | UTILITY
DROP TABLE t2 | 5 | UTILITY
INSERT INTO t1 VALUES(1) | 3 | INSERT
SELECT a FROM t1 | 1 | SELECT
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
SELECT pg_stat_monitor_reset() | 1 | SELECT
TRUNCATE t1 | 0 |
TRUNCATE t1 | 5 | UTILITY
UPDATE t1 SET a = 2 | 2 | UPDATE
(11 rows)

View File

@ -23,16 +23,22 @@ SELECT b FROM t2 FOR UPDATE;
TRUNCATE t1;
DROP TABLE t1;
DROP TABLE t2;
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | cmd_type | cmd_type_text
--------------------------------+----------+---------------
CREATE TABLE t1 (a INTEGER) | 6 | UTILITY
CREATE TABLE t2 (b INTEGER) | 6 | UTILITY
DELETE FROM t1 | 4 | DELETE
DROP TABLE t1 | 6 | UTILITY
DROP TABLE t2 | 6 | UTILITY
INSERT INTO t1 VALUES(1) | 3 | INSERT
SELECT a FROM t1 | 1 | SELECT
SELECT b FROM t2 FOR UPDATE | 1 | SELECT
SELECT pg_stat_monitor_reset() | 1 | SELECT
TRUNCATE t1 | 6 | UTILITY
UPDATE t1 SET a = 2 | 2 | UPDATE
(6 rows)
(11 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset

View File

@ -0,0 +1,25 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 10..24 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END $$;
NOTICE: error_code: 10, error_level: DEBUG5
NOTICE: error_code: 11, error_level: DEBUG4
NOTICE: error_code: 12, error_level: DEBUG3
NOTICE: error_code: 13, error_level: DEBUG2
NOTICE: error_code: 14, error_level: DEBUG1
NOTICE: error_code: 15, error_level: LOG
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
NOTICE: error_code: 17, error_level: INFO
NOTICE: error_code: 18, error_level: NOTICE
NOTICE: error_code: 19, error_level: WARNING
NOTICE: error_code: 20, error_level: WARNING_CLIENT_ONLY
NOTICE: error_code: 21, error_level: ERROR
NOTICE: error_code: 22, error_level: FATAL
NOTICE: error_code: 23, error_level: PANIC
NOTICE: error_code: 24, error_level: <NULL>
DROP EXTENSION pg_stat_monitor;

View File

@ -0,0 +1,25 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 10..24 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END $$;
NOTICE: error_code: 10, error_level: DEBUG5
NOTICE: error_code: 11, error_level: DEBUG4
NOTICE: error_code: 12, error_level: DEBUG3
NOTICE: error_code: 13, error_level: DEBUG2
NOTICE: error_code: 14, error_level: DEBUG1
NOTICE: error_code: 15, error_level: LOG
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
NOTICE: error_code: 17, error_level: INFO
NOTICE: error_code: 18, error_level: NOTICE
NOTICE: error_code: 19, error_level: WARNING
NOTICE: error_code: 20, error_level: ERROR
NOTICE: error_code: 21, error_level: FATAL
NOTICE: error_code: 22, error_level: PANIC
NOTICE: error_code: 23, error_level: <NULL>
NOTICE: error_code: 24, error_level: <NULL>
DROP EXTENSION pg_stat_monitor;

View File

@ -2,7 +2,7 @@ CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_version();
pg_stat_monitor_version
-------------------------
2.1.0
2.2.0
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@ -0,0 +1,12 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i integer;
BEGIN
FOR i IN 10..24 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END $$;
DROP EXTENSION pg_stat_monitor;