Vertica数据库常用管理命令汇总

1.查询数据库是否有等待

select * from resource_queues where node_name=(select node_name from nodes order by node_name limit 1) order by queue_entry_timestamp desc;

2.查当前数据库执行的sql(包含在队列里等待的)

select substr(current_statement, 1, 200), count(1) 
from sessions 
where not current_statement is null and (transaction_id, statement_id)<>(current_trans_id(), current_statement()) 
group by 1; 

3.资源池
3.1查询当前资源池的设置情况

SELECT name, memorysize, maxmemorysize, priority, runtimepriority,QUEUETIMEOUT,runtimeprioritythreshold, runtimecap, maxconcurrency 
FROM V_CATALOG.RESOURCE_POOLS;

3.2查询当前资源池的使用状态

select node_name,pool_name,running_query_count as running,memory_size_kb,memory_inuse_kb,general_memory_borrowed_kb,query_budget_kb 
from resource_pool_status 
where running_query_count > 0 
order by pool_name,node_name;

4.数据是否持久化到磁盘,DIFF=0

select latestepoch-earliestepoch as DIFF,epochmap,earliestepoch,latestepoch,ahmepoch from vs_epoch_map;

5.查询Tuple Mover状态(dbadmin执行)

select node_name,service_name,service_interval_sec as period,is_enabled,last_run_start,last_run_end 
from system_services 
where service_name like 'TM%' 
order by last_run_end desc,last_run_start desc,service_name;

6.手动将数据持久化(Moveout)

select do_tm_task('moveout','');

7.导出建表语句

select export_objects('/tmp/all.sql','');

8.查看license信息

SELECT DISPLAY_LICENSE();

9.最大连接数

SELECT CURRENT_VALUE FROM CONFIGURATION_PARAMETERS WHERE parameter_name='MaxClientSessions';
SELECT SET_CONFIG_PARAMETER ('MaxClientSessions', 300);

10.查询SQL

--正在执行的SQL(不包含队列等待的)
select substr(current_statement, 1, 200), count(1)
from sessions
where current_statement is not null and (transaction_id, statement_id)<>(current_trans_id(), current_statement())
and (transaction_id, statement_id) not in (select transaction_id, statement_id from resource_queues)
group by 1 order by 2 desc;

select substr(current_statement, 1, 200), s.*
from sessions s
where current_statement is not null and (transaction_id, statement_id)<>(current_trans_id(), current_statement())
and (transaction_id, statement_id) not in (select transaction_id, statement_id from resource_queues)
order by node_name, statement_start;

--在队列中等待的SQL
select substr(current_statement, 1, 200), count(1)
from sessions
where not current_statement is null and (transaction_id, statement_id)<>(current_trans_id(), current_statement())
and (transaction_id, statement_id) in (select transaction_id, statement_id from resource_queues)
group by 1 order by 2 desc;

select substr(current_statement, 1, 200), s.*
from sessions s
where not current_statement is null and (transaction_id, statement_id)<>(current_trans_id(), current_statement())
and (transaction_id, statement_id) in (select transaction_id, statement_id from resource_queues)
order by node_name, statement_start;
This entry was posted in Vertica and tagged . Bookmark the permalink.