PostgreSql 常用sql



查詢正在執行的SQL 

SELECT 
    procpid, 
    start, 
    now() - start AS lap, 
    current_query 
FROM 
    (SELECT 
        backendid, 
        pg_stat_get_backend_pid(S.backendid) AS procpid, 
        pg_stat_get_backend_activity_start(S.backendid) AS start, 
       pg_stat_get_backend_activity(S.backendid) AS current_query 
    FROM 
        (SELECT pg_stat_get_backend_idset() AS backendid) AS S 
    ) AS S 
WHERE 
   current_query <> '<IDLE>' 
ORDER BY 
   lap DESC;

------------------------------------------------------------------------------------------------
刪除表中所有數據(同mysql)
delete from tablename --寫入日誌
Truncate Table tablename --不寫入日誌
------------------------------------------------------------------------------------------------
創建用戶
create user xxx with password 'xxxxxx';
更改用戶密碼
alter user xxx with password 'yyyy';
------------------------------------------------------------------------------------------------
更改表名稱
alter table smallint rename to integer;


更改表列名
alter table integer rename column id to id1;
------------------------------------------------------------------------------------------------
顯示日期
show datestyle;
發佈了30 篇原創文章 · 獲贊 6 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章