Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2733854
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: Mysql/postgreSQL

2016-06-01 10:07:53

一、新建表空间
[postgres@db2 ~]$ mkdir -p /usr/local/pg9.3/data/pg_tblspc/tank  //注意Postgres权限

ghan=# create tablespace tank location '/usr/local/pg9.3/data/pg_tblspc/tank';
CREATE TABLESPACE
ghan=# \! ls -l
total 4
lrwxrwxrwx 1 postgres postgres   36 May 30 21:46 16388 -> /usr/local/pg9.3/data/pg_tblspc/tank
drwx------ 3 postgres postgres 4096 May 30 21:46 tank
ghan=# create table emp(id int,first_name text);
CREATE TABLE

二、新建表
ghan=# create table dept(id int,first_name text) tablespace tank;
CREATE TABLE
ghan=# select pg_relation_filepath('emp');
 pg_relation_filepath 
----------------------
 base/16384/16389
(1 row)


ghan=# select pg_relation_filepath('dept');
             pg_relation_filepath             
----------------------------------------------
 pg_tblspc/16388/PG_9.3_201306121/16384/16395
(1 row)


ghan=# select tablename,tablespace from pg_tables where tablename in ('emp','dept');
 tablename | tablespace 
-----------+------------
 emp       | 
 dept      | tank
(2 rows)

四、修改数据库默认表空间
ghan=# alter database ghan set default_tablespace='tank';
ALTER DATABASE
ghan=# \q
[postgres@rhel5-01 pg_tblspc]$ createuser tank
[postgres@rhel5-01 pg_tblspc]$ psql -d ghan
psql (9.3.2)
Type "help" for help.

五、修改用户默认表空间
ghan=# alter user tank set default_tablespace='tank';
ALTER ROLE


ghan=# alter user tank password 'tank';
ALTER ROLE
ghan=# \c ghan
You are now connected to database "ghan" as user "postgres".


ghan=# \c -  tank
You are now connected to database "ghan" as user "tank".
ghan=> create table tank (id int);
ERROR:  permission denied for tablespace tank

五、赋权用户使用表间
ghan=> \c - postgres
You are now connected to database "ghan" as user "postgres".

ghan=# grant postgres to tank;
GRANT ROLE
ghan=# \c -  tank
You are now connected to database "ghan" as user "tank".
ghan=> create table tank (id int);
CREATE TABLE
ghan=> select tablename,tablespace from pg_tables where tablename in ('tank');
 tablename | tablespace 
-----------+------------
 tank      | tank
(1 row)


ghan=> 
阅读(2792) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~