|
| 1 | + |
| 2 | +:sectnums: |
| 3 | +:sectnumlevels: 5 |
| 4 | + |
| 5 | += pg_profile |
| 6 | + |
| 7 | +== Overview |
| 8 | +pg_profile is an extension tool for PostgreSQL database performance analysis. It is mainly used to collect resource-intensive activities in a target database, helping users gain in-depth insight into database runtime status, identify performance bottlenecks, and perform optimization. Its report is essentially a "delta analysis between two sample points", deriving the incremental load within the sampling interval, with sample point sequence numbers starting from 1. |
| 9 | + |
| 10 | +pg_profile hard-depends on two extensions: dblink and plpgsql (it is written entirely in SQL and PL/pgSQL and requires no external libraries or software). Additionally, it is recommended to install the pg_stat_statements extension to obtain SQL statement-level statistics in the reports. The version of pg_profile is strongly tied to the version of PostgreSQL. For the specific version support, please refer to the README in the official pg_profile github repository. |
| 11 | + |
| 12 | +Both the PG mode and Oracle compatibility mode of IvorySQL have been adapted for pg_profile. |
| 13 | + |
| 14 | +Project address: <https://github.com/zubkov-andrei/pg_profile> |
| 15 | + |
| 16 | +License: PostgreSQL License |
| 17 | + |
| 18 | +== Installation and Enabling |
| 19 | + |
| 20 | +=== Source Code Compilation |
| 21 | + |
| 22 | +Perform source code compilation and installation: |
| 23 | +[literal] |
| 24 | +---- |
| 25 | +# Build and install pg_profile and its dependent extensions |
| 26 | +make -C contrib/dblink install |
| 27 | +make -C contrib/pg_stat_statements install |
| 28 | +make -C contrib/pg_profile install |
| 29 | +---- |
| 30 | + |
| 31 | +The installation artifacts are `pg_profile.control` and `pg_profile--4.11.sql`. |
| 32 | + |
| 33 | +=== Modify Configuration |
| 34 | +The pg_stat_statements that pg_profile depends on must be loaded at server startup via `shared_preload_libraries`. |
| 35 | + |
| 36 | +Edit `ivorysql.conf` and append `pg_stat_statements` to the end of the `shared_preload_libraries` configuration item: |
| 37 | +[literal] |
| 38 | +---- |
| 39 | +# ivorysql.conf |
| 40 | +shared_preload_libraries = 'liboracle_parser, ivorysql_ora, pg_stat_statements' |
| 41 | +---- |
| 42 | + |
| 43 | +=== Restart the Service |
| 44 | +[literal] |
| 45 | +---- |
| 46 | +pg_ctl -D $PGDATA restart |
| 47 | +---- |
| 48 | + |
| 49 | +=== Install the Extension |
| 50 | +The commands are identical in both PG mode and Oracle mode sessions: |
| 51 | +[literal] |
| 52 | +---- |
| 53 | +CREATE SCHEMA profile; |
| 54 | +CREATE SCHEMA dblink; |
| 55 | +CREATE SCHEMA statements; |
| 56 | +CREATE EXTENSION dblink SCHEMA dblink; |
| 57 | +CREATE EXTENSION pg_stat_statements SCHEMA statements; |
| 58 | +CREATE EXTENSION pg_profile SCHEMA profile; |
| 59 | +
|
| 60 | +SELECT extname, extversion FROM pg_extension WHERE extname = 'pg_profile'; |
| 61 | + extname | extversion |
| 62 | +------------+------------ |
| 63 | + pg_profile | 4.11 |
| 64 | +---- |
| 65 | + |
| 66 | +== Usage Workflow |
| 67 | + |
| 68 | +=== Create Samples |
| 69 | +[literal] |
| 70 | +---- |
| 71 | +-- First sampling |
| 72 | +SELECT * FROM profile.take_sample(); |
| 73 | + server | result | elapsed |
| 74 | +--------+--------+------------- |
| 75 | + local | OK | 00:00:01.34 |
| 76 | +
|
| 77 | +-- ...after the business workload runs for a while, sample again |
| 78 | +SELECT * FROM profile.take_sample(); |
| 79 | +---- |
| 80 | + |
| 81 | +In production environments, periodic sampling via scheduled tasks is typically used (e.g., once every 30 minutes), which can be combined with pg_cron or an external crontab: |
| 82 | +[literal] |
| 83 | +---- |
| 84 | +*/30 * * * * psql -c 'SELECT profile.take_sample()' >/dev/null |
| 85 | +---- |
| 86 | + |
| 87 | +=== View Samples |
| 88 | +[literal] |
| 89 | +---- |
| 90 | +SELECT sample, sample_time, sizes_collected FROM profile.show_samples(); |
| 91 | + sample | sample_time | sizes_collected |
| 92 | +--------+------------------------+----------------- |
| 93 | + 1 | 2026-06-12 09:00:00+00 | t |
| 94 | + 2 | 2026-06-12 09:30:00+00 | t |
| 95 | +---- |
| 96 | + |
| 97 | +=== Generate Reports |
| 98 | +[literal] |
| 99 | +---- |
| 100 | +-- Generate the workload report between sample 1 and sample 2 (HTML text) |
| 101 | +\o report_1_2.html |
| 102 | +SELECT profile.get_report(1, 2); |
| 103 | +\o |
| 104 | +---- |
| 105 | + |
| 106 | +The above functions are invoked and produce identical results in an Oracle mode session (Oracle port/1521). |
0 commit comments