Use ADCM to run SQL
You can use the ADCM UI to execute SQL queries.
Execute an SQL query
To execute a query, open the Clusters page, select an ADPG cluster, and switch to the Services tab. Click
in the Actions column to display a list of possible actions. Select the Run SQL action. The Run SQL action executes SQL queries on behalf of the
postgres
superuser.
![Select the Run SQL action](../_images/connect-to-adpg/adcm-run-sql-action.png)
In the opened form, specify a database and query text. The default database for queries is postgres
. Click the Database for query field to change the database.
![The Run SQL action form](../_images/connect-to-adpg/run-sql-form.png)
Enter a database name in the pop-up window and click Apply.
![Specify a database name](../_images/connect-to-adpg/run-sql-db-name.png)
Click the SQL query field to add SQL query text.
![Open a window to add an SQL query](../_images/connect-to-adpg/run-sql-form2.png)
Enter an SQL query text in the pop-up window and click Apply.
![Specify an SQL query text](../_images/connect-to-adpg/run-sql-query-text.png)
Click Run.
![Run the SQL query](../_images/connect-to-adpg/run-sql-form3.png)
Confirm the action in the opened pop-up window.
![Confirm the action](../_images/connect-to-adpg/run-sql-confirm.png)
In the image above, the SQL query adds Leo Tolstoy
to the author
table and information about his book — "War and Peace" to the book
table. The author
and book
tables belong to the test books_store
database, the creation of which is described in the following article: Example of working with tables via psql.
View the result
To see the SQL query result, open the Jobs page and click the Run SQL action name.
![The Jobs page with action results](../_images/connect-to-adpg/job-tab.png)
In the opened form, switch to the ansible[check] tab and expand the Result SQL query item. The SQL query and its result are displayed.
![The SQL query result](../_images/connect-to-adpg/sql-query-result.png)
The query result contains SQL query
,rc
, stdout
, and stderr
fields described in the table below.
Field name | Description |
---|---|
SQL query |
SQL query text |
rc |
Contains the psql exit status:
|
stdout |
Contains the psql output with the query result |
stderr |
Contains an error message if an error occurs during the query execution |