Skip to content

Commit d018fa6

Browse files
committed
add docs
1 parent 8577c6d commit d018fa6

13 files changed

Lines changed: 183 additions & 0 deletions

docs/en_US/developer_tools.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ PL/SQL code.
1818
erd_tool
1919
psql_tool
2020
ai_tools
21+
expl_pgsql

docs/en_US/expl_pgsql.rst

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
.. _expl_pgsql:
2+
3+
***************************
4+
`Explain PostgreSQL`:index:
5+
***************************
6+
7+
**Explain PostgreSQL** is a powerful module integrated into pgAdmin 4 that enables advanced analysis of query execution plans and beautification of SQL code. This tool helps developers and DBAs understand how PostgreSQL executes queries, identify performance bottlenecks, and optimize database workloads effectively.
8+
9+
Key Features:
10+
11+
* Visual representation of query execution plans with detailed node information.
12+
* SQL formatting and beautification capabilities for improved readability.
13+
* Integration with pgAdmin’s browser interface for seamless workflow.
14+
15+
**Requirements:**
16+
17+
Before using the Explain PostgreSQL module, ensure the following:
18+
19+
1. You are connected to a PostgreSQL server with sufficient privileges to execute commands.
20+
21+
2. Configure Explain PostgreSQL in :ref:`Preferences → Explain PostgreSQL <the-explain-postgresql-node>`.
22+
23+
**Note:**
24+
25+
* Using Explain PostgreSQL requires an active internet connection.
26+
27+
* When analyzing query plans via Explain PostgreSQL, the plan and query are sent to a third-party service
28+
(by default: https://explain.tensor.ru).
29+
30+
31+
Configuring Explain PostgreSQL
32+
******************************
33+
34+
To configure Explain PostgreSQL, navigate to *File → Preferences → Explain PostgreSQL*.
35+
36+
.. image:: images/preferences_expl_pgsql.png
37+
:alt: Explain PostgreSQL preferences
38+
:align: center
39+
40+
1. Set the **Explain Plan** switch to *True*.
41+
42+
2. Enter the *Explain PostgreSQL API* URL (default: https://explain.tensor.ru).
43+
44+
3. Set the **Format SQL** switch to *True* if you want to use the SQL formatting capability.
45+
46+
4. Set the **Private Plans** switch to *True* if you want to store plans in your personal archive.
47+
48+
After configuring, click *Save* to apply the changes.
49+
50+
51+
Using Explain PostgreSQL
52+
*************************
53+
54+
To analyze a query plan:
55+
56+
1. Open the **Query Tool** in pgAdmin.
57+
58+
2. Enter your SQL query (e.g., ``SELECT * FROM pg_stat_activity``).
59+
60+
3. Select the ``Buffers`` and ``Timing`` options from the dropdown menu next to the **Explain Analyze** button in the toolbar.
61+
62+
4. Click the **Explain Analyze** button in the toolbar (or press ``Shift+F7``) to generate the execution plan.
63+
64+
Upon successful generation, the *Explain PostgreSQL* panel will appear.
65+
66+
.. image:: images/expl_pgsql_analyze.png
67+
:alt: Example of Explain PostgreSQL output
68+
:align: center
69+
70+
71+
Understanding Execution Plans
72+
*****************************
73+
74+
Each node in the execution plan represents a step in query processing. The Explain PostgreSQL module displays:
75+
76+
* **Plan Tree** – A simplified view of the execution algorithm. Numeric indicators are displayed separately and highlighted with colors indicating load intensity.
77+
78+
Hover over nodes for tooltips with extended information. Nodes are color-coded based on performance impact:
79+
80+
* Green – Low cost
81+
* Yellow – Medium cost
82+
* Red – High cost (potential bottleneck)
83+
84+
.. image:: images/expl_pgsql_plantree.png
85+
:alt: Example of Explain PostgreSQL plan tree
86+
:align: center
87+
88+
* **Diagram** – Shows real dependencies between nodes and resource flows.
89+
90+
.. image:: images/expl_pgsql_diagram.png
91+
:alt: Example of Explain PostgreSQL diagram
92+
:align: center
93+
94+
* **Schema** – Visualizes database tables and their relationships.
95+
96+
.. image:: images/expl_pgsql_schema.png
97+
:alt: Example of Explain PostgreSQL schema
98+
:align: center
99+
100+
* **Statistics** – Summary statistics allow you to analyze large plans in aggregated form, sorted by any metric such as execution time, disk reads, cache usage, or filtered rows.
101+
102+
.. image:: images/expl_pgsql_stats.png
103+
:alt: Example of Explain PostgreSQL statistics
104+
:align: center
105+
106+
* **Pie Chart** – Helps quickly identify dominant nodes and their approximate share of resource consumption.
107+
108+
.. image:: images/expl_pgsql_piechart.png
109+
:alt: Example of Explain PostgreSQL pie chart
110+
:align: center
111+
112+
* **Tiled Visualization** – Allows compact evaluation of node connections in large plans and highlights problematic sections.
113+
114+
.. image:: images/expl_pgsql_tilemap.png
115+
:alt: Example of Explain PostgreSQL tiled visualization
116+
:align: center
117+
118+
* **Smart Recommendations** – Automatically generated based on structural and resource metrics, these provide precise guidance on resolving performance issues.
119+
120+
.. image:: images/expl_pgsql_recs.png
121+
:alt: Example of Explain PostgreSQL recommendations
122+
:align: center
123+
124+
* **Personal Archive** – Contains all the plans you've analyzed, giving you instant access regardless of whether they were published publicly.
125+
126+
.. image:: images/expl_pgsql_personal.png
127+
:alt: Example of Explain PostgreSQL personal archive
128+
:align: center
129+
130+
131+
Formatting SQL Code
132+
*******************
133+
134+
The **Format SQL** feature automatically indents and aligns SQL statements for better clarity.
135+
136+
To format the SQL query, use the *Edit* → *Format SQL* button (or press ``Ctrl+K``).
137+
138+
Example input:
139+
140+
.. code-block:: sql
141+
142+
SELECT u.name, p.title FROM users u JOIN posts p ON u.id=p.user_id WHERE u.active=true ORDER BY p.created_at DESC;
143+
144+
Formatted output:
145+
146+
.. code-block:: sql
147+
148+
SELECT
149+
u.name
150+
, p.title
151+
FROM
152+
users u
153+
JOIN
154+
posts p
155+
ON u.id = p.user_id
156+
WHERE
157+
u.active = TRUE
158+
ORDER BY
159+
p.created_at DESC;
160+
161+
162+
This makes complex queries easier to read and debug.
163+
143 KB
Loading
242 KB
Loading
41.2 KB
Loading
130 KB
Loading
302 KB
Loading
415 KB
Loading
184 KB
Loading
185 KB
Loading

0 commit comments

Comments
 (0)