{question}
Is it possible to run a procedure as a background process?
{question}
{answer}
You may need to run a stored procedure that takes a long time and don't want to occupy a session in singlestore-client or SingleStore Studio; you can use the following procedure:
Call the procedure in one machine that can access the server and has the singlestore-client tools installed.
Run the following command:
singlestore --user={userName} --password={yourPassword} --database={databaseName} --host={ddlEndpoint} -e "CALL {procedureName}();" > output.txt &
This command will create a Linux process that will be running your stored procedure. You can see the status of this process by
ps -aux | grep singlestore-client rsantos 2501 76.3 0.8 84876 72644 pts/0 R 15:42 0:16 /usr/lib/singlestore-client/singlestore-client --no-defaults --plugin-dir=/usr/lib/singlestore-client/plugin --protocol=tcp --prompt=singlestore> -u root -h 127.0.0.1 -P 3306 --database=test --host=localhost -e CALL infinity(); rsantos 2505 0.0 0.0 5424 852 pts/0 S+ 15:43 0:00 grep --color=auto singlestore-client
You can stop the process of the running procedure using the Linux command:
sudo kill -9 2501
To see more information in the database, you can execute the query:
singlestore> SELECT * FROM information_schema.MV_QUERY_ACTIVITIES WHERE DATABASE_NAME = 'test'; +----------------------------+----------------------+---------------+-------------+------------------+-----------------+--------------+--------------+-----------------+-----------------------------+-----------+--------+-----------+---------------------+-----------+---------------+---------------+---------------+-----------+ | ACTIVITY_NAME | QUERY_TEXT | DATABASE_NAME | CPU_TIME_MS | CPU_WAIT_TIME_MS | ELAPSED_TIME_MS | LOCK_TIME_MS | DISK_TIME_MS | NETWORK_TIME_MS | LOG_BUFFER_LARGE_TX_TIME_MS | NETWORK_B | DISK_B | MEMORY_BS | MEMORY_MAJOR_FAULTS | RUN_COUNT | SUCCESS_COUNT | FAILURE_COUNT | PLAN_WARNINGS | PLAN_INFO | +----------------------------+----------------------+---------------+-------------+------------------+-----------------+--------------+--------------+-----------------+-----------------------------+-----------+--------+-----------+---------------------+-----------+---------------+---------------+---------------+-----------+ | Select_t_a2c685d1f7e5bce2 | echo select * from t | test | 1104 | NULL | 1013 | 3 | NULL | 1193 | 0 | 139053512 | 785616 | 853051 | NULL | 1 | 1 | 0 | | NULL | | Call_dual_552072401fab92b9 | CALL infinity() | test | 0 | NULL | 1013 | 0 | NULL | 0 | 0 | 9 | 0 | 0 | NULL | 1 | 0 | 0 | | NULL | +----------------------------+----------------------+---------------+-------------+------------------+-----------------+--------------+--------------+-----------------+-----------------------------+-----------+--------+-----------+---------------------+-----------+---------------+---------------+---------------+-----------+ 2 rows in set, 1 warning (1.04 sec)
{answer}