您好,登錄后才能下訂單哦!
--psql功能及應用 --創建用戶,role默認沒有登錄權限 create user mydbuser with encrypted password 'mydbuser'; --or create role mydbuser with encrypted password 'mydbuser'; alter role mydbuser with login; --創建表空間 mkdir -p /pgdata/10/data/pg_tbs/tbs_mydb create tablespace tbs_mydb owner mydbuser location '/pgdata/10/data/pg_tbs/tbs_mydb'; --創建數據庫 create database mydb with owner=mydbuser template=template0 encoding='UTF8' tablespace=tbs_mydb; --賦權 grant all on database mydb to mydbuser with grant option; grant all on tablespace tbs_mydb to mydbuser; --查看角色信息 \du SELECT * FROM pg_roles; --刪除角色 revoke all on database mydb from test; drop role test; --連接 psql mydb mydbuser --列出數據庫信息 pg_database \l --表空間列表 pg_tablespace \db --查看表信息 pg_class create table test_1(id int4,name text,create_time timestamp without time zone default clock_timestamp()); alter table test_1 add primary key (id); \d test_1 \dt+ test_1 insert into test_1(id,name) select n,n ||'_francs' from generate_series(1,300000) n; insert into test_1 values(100001,'100001_francs'); --索引大小 \di+ test_1_pkey --獲取元命令 psql -E mydb mydbuser --大數據量,copy(只能超級用戶)比\copy性能高 psql mydb postgres copy table_copy from '/home/postgres/test_copy_in.txt'; copy table_copy to '/home/postgres/table_copy_in.txt'; --csv 格式 copy table_copy to '/home/postgres/table_copy_in.csv' with csv header; --A 取消格式化輸出,-t只顯示數據 psql -At -c "select oid,relname,relfilenode from pg_class limit 2" mydb mydbuser --執行相關腳本 psql mydb mydbuser -f xx.sql --查看活動會話 select pid,usename,datname,query,client_addr from pg_stat_activity where pid<>pg_backend_pid() and state='active' order by query; --查看等待事件 select pid,usename,datname,query,client_addr,wait_event_type,wait_event from pg_stat_activity where pid<>pg_backend_pid() and wait_event is not null order by wait_event_type; --查看數據庫連接數 select datname,usename,client_addr,count(*) from pg_stat_activity where pid<>pg_backend_pid group by 1,2,3 order by 1,2,4 desc; --編輯 .psqlrc \set active_session 'select pid,usename,datname,query,client_addr from pg_stat_activity where pid<>pg_backend_pid() and state=\'active\' order by query'; --執行:active_session 即可 --反復執行當前sql \watch [seconds] --查看當前時間 select now(); --psql 查看 psql --help \?
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。