pgsql 常用命令
\x 列竖排显示
\timing 开启时间
1. 查看数据库大小。
select pg_size_pretty(pg_database_size('db_name'));
2. 查看所有索引的大小。
select indexrelname,
pg_size_pretty(pg_relation_size(indexrelname))
from pg_stat_user_indexes
where schemaname = 'public'
order by pg_relation_size(indexrelname) desc;
3. 查所有表的大小。
select relname,
pg_size_pretty(pg_relation_size(relname))
from pg_stat_user_tables
where schemaname = 'public'
order by pg_relation_size(relname) desc;
4. 查看单个表的大小。
select pg_size_pretty(pg_relation_size('table_name'));
分析执行效率
EXPLAIN ANALYZE
schema 相关:
1 显示所用schema \dnS
2 显示当前schema show search_path
3 切换当前schema set search_path TO xxx
postgresql 常用命令
pgsql 五元组
psql -h host -p port -U username -W password -d db_name
范围框转图幅id
select mesh_id
from mesh_conf
where st_intersects(shape, st_geomfromtext('POLYGON((xxxx xxxxx))'));
template1=# \l 查看系统中现存的数据库
template1=# \q 退出客户端程序psql
template1=# \c 从一个数据库中转到另一个数据库中,如template1=# \c sales 从template1转到sales
template1=# \dt 查看表
template1=# \d 查看表结构
template1=# \di 查看索引
vim 关键字替换
:{作用范围}s/{目标}/{替换}/{替换标志}
例如:%s/foo/bar/g
会在全局范围(%
)查找foo
并替换为bar
,所有出现都会被替换(g
)。
当前行 :s/aa/bb/g
全文 :%s/aa/bb/g
pgsql 导出单表数据
pg_dump -h host -U username -w password -d dbname -p port -t table_name > xxx.sql
pgsql 导入单表数据
psql -h host -U username -w password -d dbname -p port < xxx.sql