您好,登錄后才能下訂單哦!
--psql功能及應(yīng)用 --創(chuàng)建用戶,role默認(rèn)沒有登錄權(quán)限 create user mydbuser with encrypted password 'mydbuser'; --or create role mydbuser with encrypted password 'mydbuser'; alter role mydbuser with login; --創(chuàng)建表空間 mkdir -p /pgdata/10/data/pg_tbs/tbs_mydb create tablespace tbs_mydb owner mydbuser location '/pgdata/10/data/pg_tbs/tbs_mydb'; --創(chuàng)建數(shù)據(jù)庫 create database mydb with owner=mydbuser template=template0 encoding='UTF8' tablespace=tbs_mydb; --賦權(quán) 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 --列出數(shù)據(jù)庫信息 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 --大數(shù)據(jù)量,copy(只能超級(jí)用戶)比\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只顯示數(shù)據(jù) psql -At -c "select oid,relname,relfilenode from pg_class limit 2" mydb mydbuser --執(zhí)行相關(guān)腳本 psql mydb mydbuser -f xx.sql --查看活動(dòng)會(huì)話 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; --查看數(shù)據(jù)庫連接數(shù) 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'; --執(zhí)行:active_session 即可 --反復(fù)執(zhí)行當(dāng)前sql \watch [seconds] --查看當(dāng)前時(shí)間 select now(); --psql 查看 psql --help \?
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。