GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.pgadmin.org — Query Tool — pgAdmin 4 9.19 documentation
This page in other versions:
Latest
(9.19) | 9.18 | 9.17 | Development
Warning: this documentation is for a pre-release version of pgAdmin 4. Contents
Query Tool¶The Query Tool is a powerful, feature-rich environment that allows you to execute arbitrary SQL commands and review the result set. You can access the Query Tool via the Query Tool menu option on the Tools menu, or through the context menu of select nodes of the Object explorer control. The Query Tool allows you to:
You can open multiple copies of the Query tool in individual tabs simultaneously. To close a copy of the Query tool, click the X of the tab. The Query Tool features two panels:
Query Tool in Workspace Layout¶The workspace layout offers a distraction-free, dedicated area for the Query Tool. When the Query Tool workspace is accessed, the Welcome page opens by default. Note: In the Workspace layout, all Query Tool and View/Edit Data tabs open within the Query Tool workspace. In the classic UI, users must connect to a database server and navigate to the database node before using the Query Tool. However, with the introduction of the Workspace layout and Welcome page, users can seamlessly connect to any ad-hoc server, even if it is not registered in the Object Explorer. Note Connecting to a server that is not registered in the Object Explorer requires the Manage Server permission (see User Management). In server mode, a user without it must select an Existing Server, and the Server Name, Host name/address, Port and Service fields cannot be changed.
After filling in all the required fields, click the Connect & Open Query Tool button to launch the Query Tool with the provided server details. If the password is not supplied, you will be prompted to enter it. Toolbar¶The toolbar is described in the following subsections. The SQL Editor Panel¶The SQL editor panel is a workspace where you can manually provide a query, copy a query from another source, or read a query from a file. The SQL editor features syntax coloring and autocompletion.
To use autocomplete, begin typing your query; when you would like the Query editor to suggest object names or commands that might be next in your query, press the Control+Space key combination. For example, type “SELECT * FROM” (without quotes, but with a trailing space), and then press the Control+Space key combination to select from a popup menu of autocomplete options.
After entering a query, select the Execute script icon from the toolbar. The complete contents of the SQL editor panel will be sent to the database server for execution. To execute only a section of the code that is displayed in the SQL editor, highlight the text that you want the server to execute, and click the Execute script icon.
You can also execute a query based on cursor position. Query tool will detect a query and underline it when cursor position changes. Now, to execute the current underlined query, hit the Execute query button on the toolbar. If a section is highlighted then it will behave like normal execute.
The warning will appear only if Underline query at cursor? is set to False and the Underlined query execute warning? switch is set to True Preferences Query tool’s Options.
The message returned by the server when a command executes is displayed on the Messages tab. If the command is successful, the Messages tab displays execution details.
Options on the Edit menu offer functionality that helps with code formatting and commenting:
You can also drag and drop certain objects from the treeview which can save time in typing long object names. Text containing the object name will be fully qualified with schema. Double quotes will be added if required. For functions and procedures, the function name along with parameter names will be pasted in the Query Tool. Query History Panel¶Use the Query History tab to review activity for the current session:
The Query History tab displays information about recent commands:
You can show or hide the queries generated internally by pgAdmin (during ‘View/Edit Data’ or ‘Save Data’ operations). You can remove a single query by selecting it and clicking on the Remove button. If you would like to remove all of the histories from the Query History tab, then click on the Remove All button. By using the Copy button, you can copy a particular query to the clipboard, and with the Copy to Query Editor button, you can copy a specific query to the Query Editor tab. During this operation, all existing content in the Query Editor is erased. Query History is maintained across sessions for each database on a per-user
basis when running in Query Tool mode. In View/Edit Data mode, history is not
retained. By default, the last 20 queries are stored for each database. This
can be adjusted in AI Assistant Panel¶The AI Assistant tab provides a chat-style interface for generating SQL queries from natural language descriptions. This feature requires an AI provider to be configured in Preferences > AI. For configuration details, see the Preferences documentation.
To use the AI Assistant:
The AI Assistant displays conversations with your messages and AI responses. When the AI generates SQL, it appears in a syntax-highlighted code block with action buttons:
The AI Assistant maintains conversation context, allowing you to refine queries iteratively. For example, you can ask for a query and then follow up with “also add a filter for active users” to modify the previous result. Tips for effective use:
Note: The AI Assistant uses database schema inspection tools to understand your database structure. It supports SELECT, INSERT, UPDATE, DELETE, and DDL statements. All generated queries should be reviewed before execution. See Data Handling and Provider Selection for details of the information that is transmitted to your configured LLM provider. The Data Output Panel¶The Data Output panel displays data and statistics generated by the most recently executed query.
The Data Output tab displays the result set of the query in a table format. You can:
A result set is updatable if:
Any columns that are renamed or selected more than once are also read-only. Editable and read-only columns are identified using pencil and lock icons (respectively) in the column headers.
The psycopg2 driver version should be equal to or above 2.8 for updatable query result sets to work. An updatable result set is identical to the Data Grid in View/Edit Data mode, and can be modified in the same way. If Auto-commit is off, the data changes are made as part of the ongoing transaction, if no transaction is ongoing a new one is initiated. The data changes are not committed to the database unless the transaction is committed. If any errors occur during saving (for example, trying to save NULL into a column with NOT NULL constraint) the data changes are rolled back to an automatically created SAVEPOINT to ensure any previously executed queries in the ongoing transaction are not rolled back. All rowsets from previous queries or commands that are displayed in the Data Output panel will be discarded when you invoke another query; open another Query Tool tab to keep your previous results available. Explain Panel¶To generate the Explain or Explain Analyze plan of a query, click on Explain or Explain Analyze button in the toolbar. More options related to Explain and Explain Analyze can be selected from the drop down on the right side of Explain Analyze button in the toolbar.
Please note that pgAdmin generates the Explain [Analyze] plan in JSON format. Note: If multiple queries are present and none is selected, Explain [Analyze] runs the query located at the cursor position. On successful generation of Explain plan, it will create three tabs/panels under the Explain panel.
Please note that EXPLAIN VERBOSE cannot be displayed graphically. Click on a node icon on the Graphical tab to review information about that item; a popup window will display on the right side with the information about the selected object. For information on JIT statistics, triggers and a summary, click on the button on top-right corner; a similar popup window will be displayed when appropriate. Use the download button on top left corner of the Explain canvas to download the plan as an SVG file. Note: Download as SVG is not supported on Internet Explorer.
Note that the query plan that accompanies the Explain analyze is available on the Data Output tab.
Table tab shows the plan details in table format, it generates table format similar to explain.depesz.com. Each row of the table represent the data for a Explain Plan Node. It may contain the node information, exclusive timing, inclusive timing, actual vs planned rows differences, actual rows, planned rows, loops. background color of the exclusive, inclusive, and Rows X columns may vary based on the difference between actual vs planned. If percentage of the exclusive/inclusive timings of the total query time is: > 90 - Red color > 50 - Orange (between red and yellow) color > 10 - Yellow color If planner mis-estimated number of rows (actual vs planned) by 10 times - Yellow color 100 times - Orange (between Red and Yellow) color 1000 times - Red color
Statistics tab shows two tables: 1. Statistics per Plan Node Type 2. Statistics per Table
The AI Insights tab provides AI-powered analysis of query execution plans, identifying performance bottlenecks and suggesting optimizations. This tab is only available when an AI provider is configured in Preferences > AI.
When you switch to the AI Insights tab, the AI analyzes the execution plan and provides: Performance Bottlenecks - Issues identified in the query plan, such as:
Recommendations - Concrete suggestions to improve query performance:
Each recommendation that includes SQL (such as CREATE INDEX statements) has action buttons to Copy the SQL to the clipboard or Insert it into the Query Editor. Click the Regenerate button to request a fresh analysis of the current plan. Note: AI analysis is generated on-demand when you first click the AI Insights tab or when a new explain plan is generated while the tab is active. The analysis provides guidance but all suggested changes should be carefully evaluated before applying to production databases. Messages Panel¶Use the Messages tab to view information about the most recently executed query:
If the server returns an error, the error message will be displayed on the Messages tab, and the syntax that caused the error will be underlined in the SQL editor. If a query succeeds, the Messages tab displays how long the query took to complete and how many rows were retrieved:
Notifications Panel¶Use the Notifications tab to view the notifications using PostgreSQL Listen/ Notify feature. For more details see PostgreSQL documentation. Example:
2. In the another Query Tool session, execute Notify command or pg_notify function to send the notification of the event together with the payload.
3. You can observe the Notification tab in the first Query Tool session where it shows the Recorded time, Event, Process ID, and the Payload of the particular channel.
Graph Visualiser Panel¶Click the Graph Visualiser button in the toolbar to generate the Graphs of the query results. The graph visualiser supports Line Charts, Stacked Line Charts, Bar Charts, Stacked Bar Charts, and Pie Charts.
Choose the type of the graph that you would like to generate.
Choose the column whose value you wish to display on X-axis from the X Axis dropdown. Select the <Row Number> option to use the number of rows as labels on the X-axis.
Choose the columns whose value you wish to display on Y-axis from the Y Axis dropdown. Users can choose multiple columns. Choose the <Select All> option from the drop-down menu to select all the columns.
Zooming is performed by clicking and selecting an area over the chart with the mouse. The Zoom to original button will bring you back to the original zoom level. Click the Download button on the button bar to download the chart.
Line Chart¶The Line Chart can be generated by selecting the ‘Line Chart’ from the Graph Type drop-down, selecting the X-axis and the Y-axis, and clicking on the ‘Generate’ button. Below is an example of a chart of employee names and their salaries.
Set Use different data point styles? option to true in the Preferences, to show data points in a different style on each graph lines. Stacked Line Chart¶The Stacked Line Chart can be generated by selecting the ‘Stacked Line Chart’ from the Graph Type drop-down, selecting the X-axis and the Y-axis, and clicking on the ‘Generate’ button.
Bar Chart¶The Bar Chart can be generated by selecting the ‘Bar Chart’ from the Graph Type drop-down, selecting the X-axis and the Y-axis, and clicking on the ‘Generate’ button.
Stacked Bar Chart¶The Stacked Bar Chart can be generated by selecting the ‘Stacked Bar Chart’ from the Graph Type drop-down, selecting the X-axis and the Y-axis, and clicking on the ‘Generate’ button.
Pie Chart¶The Pie Chart can be generated by selecting the ‘Pie Chart’ from the Graph Type drop-down, selecting the Label and Value, and clicking on the ‘Generate’ button.
Connection Status¶Use the Connection status feature to view the current connection and transaction status by clicking on the status icon in the Query Tool:
Change connection¶User can connect to another server or database from existing open session of query tool.
Macros¶Query Tool Macros enable you to execute pre-defined SQL queries with a single key press. Pre-defined queries can contain the placeholder $SELECTION$. Upon macro execution, the placeholder will be replaced with the currently selected text in the Query Editor pane of the Query Tool.
To create a macro, select the Manage Macros option from the Macros menu on the Query Tool. Select the key you wish to use, enter the name of the macro, and the query, optionally including the selection placeholder, and then click the Save button to store the macro.
To add a query to macros, write and select your query, then go to the Macros menu in the Query Tool and click Add to macros. Your query will be automatically saved to macros.
To delete a macro, select the macro on the Manage Macros dialogue, and then click the Delete button. The server will prompt you for confirmation to delete the macro.
To execute a macro, simply select the appropriate shortcut keys, or select it from the Macros menu.
Server Side Cursor¶Server-side cursors allow partial retrieval of large datasets, making them particularly useful when working with very large result sets. However, they may offer lower performance in typical, everyday usage scenarios. To enable server-side cursors:
Limitations: 1. Transaction Requirement: Server-side cursors work only in transaction mode. If enabled pgAdmin will automatically ensure queries run within a transaction.
3. Pagination Limitation: In the Result Grid, the First and Last page buttons will be disabled, as server-side cursors do not return a total row count. Consequently, the total number of rows will not be displayed after execution. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |