postgresql資料庫常用命令
select version();
--獲取資料庫啟動時間
select pg_postmaster_start_time();
--獲取配置檔案最近load時間
select pg_conf_load_time();
--獲取當前資料庫時區
show timezone;
--獲取當前例項中所有資料庫
psql -l
--獲取當前資料庫使用者
select user;
select current_user;
--獲取當前會話使用者
select session_user;
--獲取會話客戶端地址及埠
select inet_client_addr(),inet_client_port();
--獲取當前資料庫伺服器地址及埠
select inet_server_addr(),inet_server_port();
--獲取當前會話服務程式
select pg_backend_pid();
--獲取當前引數配置
show shared_buffer;
select current_setting('shared_buffers');
--修改會話引數配置
set maintenance_work_mem to '32m';
select set_confit('maintenance_work_mem','32m',false);
--獲取當前WAL檔案
select pg_xlogfile_name(pg_current_xlog_location());
--獲取沒寫到磁碟的WAL buffer
select pg_xlog_location_diff(pg_current_xlog_insert_location(),pg_current_xlog_location());
--獲取例項中當前進行的備份
select pg_is_in_backup(),pg_backup_start_time();
--獲取當前例項的角色狀態(primary or standby)
select pg_is_in_recovery();
--獲取資料庫大小
select pg_database_size('mydb'),pg_size_pretty(pg_database_size('mydb'));
--獲取表大小
--表
select pg_size_pretty(pg_relation_size('mytab'));
--表及索引
select pg_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 AS free_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 AS is_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_xmax::text::int8 AS xmax,
t_ctid
FROM heap_page_items(get_raw_page('t1',0))
ORDER BY lp;
select * from t1_page0;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8484829/viewspace-2120392/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【PG常用命令】postgresql資料庫統計物件大小SQL資料庫物件
- postgresql 資料庫基本操作SQL資料庫
- postgresql資料庫利用方式SQL資料庫
- MYSQL資料庫常用命令MySql資料庫
- Rust 連線 PostgreSQL 資料庫RustSQL資料庫
- PostgreSQL:資料庫的選擇SQL資料庫
- PostgreSQL關係型資料庫SQL資料庫
- postgresql資料庫鎖介紹SQL資料庫
- postgresql資料庫初始化SQL資料庫
- PostgreSQL 資料庫學習 - 0. 資料庫安裝SQL資料庫
- mysql 資料庫常用命令大全MySql資料庫
- Postgresql10資料庫之更改資料庫的名稱SQL資料庫
- PostgreSQL:資料庫連結測試SQL資料庫
- MySQL和PostgreSQL資料庫安全配置MySql資料庫
- postgresql資料庫怎麼備份SQL資料庫
- 1. PostgreSQL 資料庫安裝SQL資料庫
- PostgreSQL:表空間-->資料庫-->表SQL資料庫
- 資料庫比較 PostgreSQL vs MongoDB資料庫SQLMongoDB
- PostgreSQL常用命令SQL
- 【資料庫】MySQL入門常用命令資料庫MySql
- 常用命令--資料庫備份--mysqdump資料庫
- 如何保護PostgreSQL資料庫安全? | goteleportSQL資料庫Go
- 【PG管理】postgresql資料庫管理相關SQL資料庫
- postgresql備份與恢復資料庫SQL資料庫
- PostgreSQL:資料庫的建立與刪除SQL資料庫
- Oracle & MySQL & PostgreSQL資料庫恢復支援OracleMySql資料庫
- Spring Boot中使用PostgreSQL資料庫Spring BootSQL資料庫
- PostgreSQL資料庫連線保持設定SQL資料庫
- postgresql資料庫重要引數說明SQL資料庫
- 備份和恢復postgreSQL資料庫SQL資料庫
- PostgreSQL學習手冊(資料庫管理)SQL資料庫
- 安裝PostgreSQL資料庫(Linux篇)SQL資料庫Linux
- 【PG結構】Postgresql資料庫資料目錄說明SQL資料庫
- PostgreSQL常用命令大全SQL
- PostgreSql資料庫的備份和恢復SQL資料庫
- Postgresql 31條資料庫開發規範SQL資料庫
- PostgreSQL資料庫toast表損壞解決SQL資料庫AST
- PostgreSQL學習手冊(資料庫維護)SQL資料庫