跳到主要内容
版本:1.0.14

数据库对象操作

以下所有命令,请在用psql登录数据库后执行。

创建用户
create user sa with password 'sadmin';
或者
create role sa with password 'sadmin' login;

创建超级用户
create user sa with password 'sadmin' superuser;

修改用户密码
alter user sa with password 'sa';

禁止用户登录
alter user sa with nologin;

删除用户
drop user sa;

创建数据库
create database test;

创建和用户同名的 schema
create schema sa authorization sa;

schema 的所有权限给另外一个用户
grant usage on schema sa to test;

修改表的 schema
alter table test set schema sa;

创建数据库
create database test;

删除数据库
drop database test;

创建表空间
create tablespace tbs_data owner halo location '/u01/data/tbs1';

删除表空间
drop tablespace tbs_data;

表添加字段
alter table test add col1 int;

表删除字段
alter table test drop col1;

表更改字段类型
alter table test alter column col1 type varchar(10);

将表数据导出成csv文件
copy test to '/home/halo/test.csv';

将csv文件导入到表
copy test from '/home/halo/test.csv' delimiter ',' csv header;