首页 > 数据库 > PostgreSQL > postgresql笔记
db 表示数据库名称
sch 表示schema名称
tab 表示表名称
col 表示字段名称
user 表示用户
退出
\q
查看当前库
\l
切换库
\c db
查看插件
\dx
查看某个表结构
\d sch.tab
查看某个schema下面所有的表,序列,索引(包括所有者等信息)
\d
查看schema的权限FF
\dn
按列展示
\x
执行计划
explain analyze
也可以 explain
查看当前库下面的schema
SELECT * FROM information_schema.schemata limit 5;
得到当前db中所有表的信息(这里pg_tables是系统视图)
select * from pg_tables
加索引 btree concurrently
create index sys_user_role_rel_role_id_index on sch.tab (col);
加索引 jsonb
create index idx_jsonb_gin on sch.tabusing gin (col);
不锁表加索引
create index concurrently idx_co1_col2_col3 on sch.tab(col1,col2,col3);
create index idx_time_status on sch.tab (col1,col2);
jsonb 索引使用方法
explain analyze SELECT col1,col2FROM sch.tabWHERE is_deleted = false and col@> '[{"10655":"9B025FDEFD5C34EA8BB6A07D67769261"}]';
修改数组类型字段
update sch.tabset col=array['湖南省_湘潭市123','dddd'] where id=20983;
修改表的所有者 需要高权限账户操作
ALTER TABLE sch.tab OWNER TO user;
#查询会话中 未提交的事务
select * from pg_stat_activity where (state = 'idle in transaction') and xact_start is not null;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30127122/viewspace-2937852/ ,如需转载,请注明出处,否则将追究法律责任。