postgresql数据操作

windows下操作postgresql

删除数据库:
dropdb.exe -U postgres 数据库名称

创建数据库
createdb.exe -U postgres lilei_db1
--lilei_db1为数据库名称

导出表数据
pg_dump.exe -U postgres -t tab1 -d postgis_24_sample > tab1.sql
pg_dump.exe --help 查看帮助信息
-U 用户名
-t 表名称
-d 数据库名称

导入数据
psql -d lilei_db1 -U postgres -f all_db.sql
-f sql文件

关闭自动提交
begin;
scripts;
commit;

获取表的列结构
select * from information_schema.columns where table_name='link';

查询当前正在执行sql的会话
select * from pg_stat_activity where state!='idle';

获取表存储空间占用
select pg_size_pretty(pg_relation_size('link'));

select pg_relation_size('link');

获取几何线长度
select st_length(st_setsrid(geom,4326),false) from link5 where id=20357;
--添加参数false,否则是平面距离

 

附属帮助
\l 显示所有数据库
\d 显示当前库所有表、序列、视图
\dt 显示当前库所有表
\d admin_face 显示admin_face表结构

\set autocommit off 关闭自动提交

posted on 2018-03-16 15:41  李雷  阅读(292)  评论(0编辑  收藏  举报

导航