select version();
select pg_postmaster_start_time();
select pg_conf_load_time();
show timezone;
psql -l
select user;
select current_user;
select session_user;
8>获取会话客户端地址及端口
select inet_client_addr(),inet_server_port();
select inet_server_addr(),inet_server_port();
10>获取当前会话服务进程
select pg_backend_pid();
11>获取当前参数配置
show shared_buffer;
select current_setting('shared_buffers');
12>修改会话参数配置
set maintenance_work_mem to '32m';
select set_confit('maintenance_work_mem','32m',false);
select pg_clogfile_name(pg_current_xlog_location());
14>获取没写到磁盘的WAL buffer
selectpg_xlog_location_diff(pg_current_xlog_insert_location(),pg_current_xlog_location());
15>获取实例中当前进行的备份
select pg_is_in_backup(),pg_backup_start_time();
16>获取当前实例的角色状态(primary or standby)
select pg_is_in_recovery();
17>获取数据库大小
selectpg_database_size('mydb'),pg_size_pretty(pg_database_size('mydb'));
18>获取表大小
--表
select pg_size_pretty(pg_relation_size('mytab'));
--表及索引
selectpg_size_pretty(pg_total_relation_size('mytab'));
--获取索引大小
select pg_size_pretty(pg_indexes_size('mytab'));
--获取表空间大小
select pg_size_pretty(pg_tablespace_size('my_tbs'));
--获取表中每个数据块的自由空间
select pg_freespace('mytab');
--获取表中每个数据块中自由空间比例
SELECT (100 * (upper - lower) / pagesize::float8)::integer ASfree_pct
FROM page_header(get_raw_page('mytab',11));
select pg_relation_filepath('mytab');
--重新加载配置文件
pg_ctl reload
select pg_reload_conf();
--切换log文件
select pg_rotate_logfile();
--切换xlog文件
select pg_rotate_xlog();
--手工产生检查点
checkpoint;
--取消正在执行的sql
select pg_cancel_backend(pid);
--终止后台服务进程
select pg_terminate_backend(pid);
--获取正在执行的sql
select pid,username,query_start,query from pg_stat_activity;
--获取Combo Command Ids
SELECT t_xmin AS xmin,
t_xmax::text::int8 AS xmax,
t_field3::text::int8 AS cmin_cmax,
(t_infomask::integer & X'0020'::integer)::bool ASis_combocid
FROM heap_page_items(get_raw_page('mytab',0))
ORDER BY 2 DESC,3;
--创建获取某数据块元组原型视图
CREATE VIEW t1_page0 AS
SELECT '(0,'|| lp || ')' AS ctid,
CASE lp_flags
WHEN 0 THEN 'Unused'
WHEN 1 THEN 'Normal'
WHEN 2 THEN 'Redirect to '|| lp_off
WHEN 3 THEN 'Dead'
END,
t_xmin::text::int8 AS xmin,
t_ctid
FROM heap_page_items(get_raw_page('t1',0))
ORDER BY lp;
select * from t1_page0;