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 actions default dark actions default light 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
Select the Run SQL action

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
The Run SQL action form

Enter a database name in the pop-up window and click Apply.

Specify a database name
Specify a database name

Click the SQL query field to add SQL query text.

Open a window to add an SQL query
Open a window to add an SQL query

Enter an SQL query text in the pop-up window and click Apply.

Specify an SQL query text
Specify an SQL query text

Click Run.

Run the SQL query
Run the SQL query

Confirm the action in the opened pop-up window.

Confirm the action
Confirm the action

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
The "Jobs" page with action results

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
The SQL query result

The query result contains SQL query,rc, stdout, and stderr fields described in the table below.

Query result fields
Field name Description

SQL query

SQL query text

rc

Contains the psql exit status:

  • 0 — the command is executed successfully without any errors.

  • 1 — a psql fatal error occurs (e.g., out of memory, file not found).

  • 2 — the connection to the server is bad and the session is not interactive.

  • 3 — an error occurs in a script and the ON_ERROR_STOP variable is set.

stdout

Contains the psql output with the query result

stderr

Contains an error message if an error occurs during the query execution

Found a mistake? Seleсt text and press Ctrl+Enter to report it