批量导入文件
psql -h localhost -d dbname -U username -f filename
1. 创建用户
CREATE USER dbuser WITH PASSWORD 'password';
2. 创建数据库
CREATE DATABASE dbname OWNER dbuser;
3. 授权
GRANT ALL PRIVILEGES ON DATABASE dbname to dbuser;
4. 修改表的所有者
alter table tablename owner to new_user;
5.添加自增主键
alter table tablename add column id serial primary key;
6.修改列名
alter table tablename rename column columnname to new_columnname;
7. 删除not null
alter table tablename alter column columnname drop not null;
8. 修改列类型
alter table tablename alter column clumnname type typename;
9. 查看所有表名
select relname as TABLE_NAME ,col_description(c.oid, 0) as COMMENTS from pg_class c
where relkind = 'r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname