2019独角兽企业重金招聘Python工程师标准>>>

查看表空间的语法帮助
postgres=# \h create tablespace
Command:     CREATE TABLESPACE
Description: define a new tablespace
Syntax:
CREATE TABLESPACE tablespace_name[ OWNER { new_owner | CURRENT_USER | SESSION_USER } ]LOCATION 'directory'[ WITH ( tablespace_option = value [, ... ] ) ]
创建表空间

连接coordinator:

create tablespace tst_tbs location '/home/shboss/antdb/data/tablespace';

需要在集群涉及到的主机上都存在location指定的目录,否则报错:

postgres=# create tablespace tst_tbs location '/home/shboss/antdb/data/tablespace';
ERROR:  Fail to process utility query on remote node.
DETAIL:  ERROR:  directory "/home/shboss/antdb/data/tablespace" does not exist

在各个主机上创建目录:

remote_cmd  "mkdir -p /home/shboss/antdb/data/tablespace"

再次连接coordinator创建表空间:

postgres=# create tablespace tst_tbs location '/home/shboss/antdb/data/tablespace';
CREATE TABLESPACE
查看表空间信息

数据库级别:

postgres=# \dbList of tablespacesName    | Owner  |              Location
------------+--------+------------------------------------pg_default | shboss | pg_global  | shboss | tst_tbs    | shboss | /home/shboss/antdb/data/tablespace
(3 rows)postgres=# select * from pg_tablespace ;spcname   | spcowner | spcacl | spcoptions
------------+----------+--------+------------pg_default |       10 |        | pg_global  |       10 |        | tst_tbs    |       10 |        |
(3 rows)

文件系统:

coord节点:

[shboss@localhost1 pg_tblspc]$ pwd
/home/shboss/antdb/data/coord/pg_tblspc

datanode 节点:

lrwxrwxrwx 1 shboss shboss 34 Jul 23 15:25 164514 -> /home/shboss/antdb/data/tablespace
[shboss@localhost1 pg_tblspc]$ pwd
/home/shboss/antdb/data/db1/pg_tblspc

表空间路径:

[shboss@localhost1 pg_tblspc]$ cd /home/shboss/antdb/data/tablespace
[shboss@localhost1 tablespace]$ ll
total 12
drwx------ 2 shboss shboss 4096 Jul 23 15:25 PG_9.6_201608131_coord1
drwx------ 2 shboss shboss 4096 Jul 23 15:25 PG_9.6_201608131_coord5
drwx------ 2 shboss shboss 4096 Jul 23 15:25 PG_9.6_201608131_db1_2
[shboss@localhost1 tablespace]$ tree .
.
├── PG_9.6_201608131_coord1
├── PG_9.6_201608131_coord5
└── PG_9.6_201608131_db1_2
在表空间内建表
create table test_tbs (id int) tablespace tst_tbs;

查看表空间中的数据文件:

[shboss@localhost1 tablespace]$ tree .
.
├── PG_9.6_201608131_coord1
│   └── 13603
│       └── 476507
├── PG_9.6_201608131_coord5
│   └── 13603
│       └── 18025
└── PG_9.6_201608131_db1_2└── 13597└── 164515

使用其他普通用户在tst_tbs 表空间下创建表:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs;
ERROR:  permission denied for tablespace tst_tbs
bmsql5=>

解决办法1:给普通用户赋权

postgres=# grant create on tablespace tst_tbs to bmsql5_ora_fdw;
GRANT

再次建表成功:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs;
CREATE TABLE
bmsql5=> \d+ test_tbsTable "bmsql5_ora_fdw.test_tbs"Column |  Type   | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------id     | integer |           | plain   |              |
Tablespace: "tst_tbs"
Distribute By: HASH(id)
Location Nodes: ALL DATANODESbmsql5=>

在创建之前,可以查询当前用户表空间tst_tbs 是否有权限:

bmsql5=> select has_tablespace_privilege('tst_tbs','create');has_tablespace_privilege
--------------------------t
(1 row)

revoke权限后再次查询:

-- superuser
postgres=# revoke create on tablespace tst_tbs from bmsql5_ora_fdw;
REVOKE
-- 普通用户
bmsql5=> select has_tablespace_privilege('tst_tbs','create');has_tablespace_privilege
--------------------------f
(1 row)

解决办法2:修改表空间的属主为表的创建用户

alter tablespace tst_tbs owner to bmsql5_ora_fdw;

再次建表成功:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs;
CREATE TABLE
bmsql5=>

解决办法3:修改数据库的默认表空间

alter database bmsql5 set tablespace tst_tbs;postgres=# alter database bmsql5 set tablespace tst_tbs;
ALTER DATABASE
Time: 323772.143 ms
postgres=#
postgres=# \l+ List of databasesName    | Owner  | Encoding | Collate | Ctype | Access privileges |  Size   | Tablespace |                Description
-----------+--------+----------+---------+-------+-------------------+---------+------------+--------------------------------------------bmsql5    | shboss | UTF8     | C       | C     |                   | 26 GB   | tst_tbs    | db1       | shboss | UTF8     | C       | C     |                   | 1529 MB | pg_default | postgres  | shboss | UTF8     | C       | C     |                   | 43 MB   | pg_default | default administrative connection databasetemplate0 | shboss | UTF8     | C       | C     | =c/shboss        +| 30 MB   | pg_default | unmodifiable empty database|        |          |         |       | shboss=CTc/shboss |         |            | template1 | shboss | UTF8     | C       | C     | =c/shboss        +| 30 MB   | pg_default | default template for new databases|        |          |         |       | shboss=CTc/shboss |         |            | testdb    | shboss | UTF8     | C       | C     |                   | 108 MB  | pg_default |
(6 rows)

这个操作的耗时取决于数据库的大小和磁盘的性能。且在数据文件移动过程中,该数据库无法连接

[shboss@localhost1 tablespace]$ psql -d bmsql5
psql: FATAL:  database "bmsql5" does not exist
DETAIL:  It seems to have just been dropped or renamed.

再次建表成功:

bmsql5=> create table test_tbs (id int) tablespace tst_tbs;
CREATE TABLE
bmsql5=> drop table test_tbs;
DROP TABLE
bmsql5=> create table test_tbs (id int);
CREATE TABLE

碰到的问题:

更改的数据库上有连接的时候,没法修改:

postgres=# alter database bmsql5 set tablespace tst_tbs;
ERROR:  database "bmsql5" is being accessed by other users
DETAIL:  There is 1 other session using the database.

连接到修改的数据库上也无法执行修改操作:

bmsql5=# alter database bmsql5 set tablespace tst_tbs;
ERROR:  cannot change the tablespace of the currently open database

如果修改的数据库中已经有对象在目标表空间中,也无法执行操作:

postgres=# alter database bmsql5 set tablespace tst_tbs;
ERROR:  some relations of database "bmsql5" are already in tablespace "tst_tbs"
HINT:  You must move them back to the database's default tablespace before using this command.

查找指定表空间中的对象:

select relname,reltype,spcname
from pg_class c, pg_tablespace tbs
where c.reltablespace=tbs.oid
and tbs.spcname='tst_tbs';
查看表的表空间
postgres=# \d test_tbsTable "public.test_tbs"Column |  Type   | Modifiers
--------+---------+-----------id     | integer |
Tablespace: "tst_tbs"

如果表没有使用所在数据库的默认表空间,则会在\d 的时候显示。

修改表的表空间
bmsql5=# select pg_relation_filepath('bmsql_stock');pg_relation_filepath
----------------------base/27636/461935
(1 row)bmsql5=# alter table bmsql_stock set tablespace tst_tbs;
ALTER TABLE
bmsql5=# select pg_relation_filepath('bmsql_stock');pg_relation_filepath
-------------------------------------------------------pg_tblspc/476505/PG_9.6_201608131_coord1/27636/476515
(1 row)bmsql5=#

表很大的话,会比较耗时,是个挪动文件的过程,同时发现filenode是变了的。

查看表空间大小
postgres=# select pg_tablespace_size('tst_tbs');pg_tablespace_size
--------------------36757504
(1 row)postgres=# select pg_size_pretty(pg_tablespace_size('tst_tbs'));pg_size_pretty
----------------35 MB
(1 row)
删除表空间
postgres=# drop tablespace tst_tbs;
ERROR:  tablespace "tst_tbs" is not empty

如果表空间中有对象删除,则无法删除。

根据上面提供的查找指定表空间中的对象 语句找出对象移走或删除后,再进行删除:

postgres=# drop tablespace tst_tbs;
DROP TABLESPACE

查看主机上的文件:

[shboss@localhost1 tablespace]$ tree .
.0 directories, 0 files
[shboss@localhost1 tablespace]$ pwd
/home/shboss/antdb/data/tablespace

目录已经为空。

转载于:https://my.oschina.net/yafeishi/blog/1861567

AntDB上使用表空间相关推荐

  1. linux svn磁盘空间满,Linux svn checkout时候总报设备上没有空间

    但是df -h查看磁盘 [[email protected] data]# df -h 文件系统 容量  已用 可用 已用% 挂载点 /dev/sda3 19G  2.1G   16G  12% / ...

  2. python – IOError:[Errno 28] pip install 设备上没有空间

    python – IOError:[Errno 28]安装pytorch时设备上没有空间 参考:https://blog.csdn.net/weixin_37340613/article/detail ...

  3. 通过从备份中排除这些文件夹来节省Time Machine驱动器上的空间

    Are you getting notifications about a full Time Machine drive? Do you feel like your backups are tak ...

  4. SAP使用表空间传输异构系统迁移

    SAP使用表空间传输异构系统迁移 此文档乃原创总结,仅适用于oracle数据库.此方法特点,速度快.停机时间短,配合RMAN使用甚至可以做到不停机.在线迁移并可以支持裸设备和ASM.以次方法做迁移,在 ...

  5. linux清理磁盘空间的脚本,在Ubuntu和Linux Mint上释放空间的7种简单方法

    Linux系统空间不足?您可以通过以下几种方式清理系统,释放Ubuntu和其他基于Ubuntu的Linux发行版上的空间. 随着时间的流逝,随着添加和删除程序,任何操作系统都可能变得混乱.如果您拥有T ...

  6. linuxdeploy ubuntu 更新gui_在Ubuntu和Linux Mint上释放空间的7种简单方法

    Linux系统空间不足?您可以通过以下几种方式清理系统,释放Ubuntu和其他基于Ubuntu的Linux发行版上的空间. 随着时间的流逝,随着添加和删除程序,任何操作系统都可能变得混乱.如果您拥有T ...

  7. mac 上格式化移动硬盘出现MediaKit报告设备上的空间不足以执行请求的解决办法

    突发奇想的想用自己的移动硬盘给Mac电脑做备份,但是硬盘格式不对,就手贱点了抹掉.后来提示mac 上格式化移动硬盘出现MediaKit报告设备上的空间不足以执行请求的解决办法.网上找了好久没有找到解决 ...

  8. 无法为立即文档创建临时文件: 设备上没有空间(centos root 目录爆满)

    qingli-bash: 无法为立即文档创建临时文件: 设备上没有空间: df 查看磁盘空间,发现根目录爆满 使用du -sh * 查看是哪个文件占用了这么大的空间,结果并没有找到大文件,那就可能是隐 ...

  9. 上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间

    1. 问题 SpringBoot上传文件时,服务器报错 2022-06-27 10:58:00.941 ERROR 12700 --- [nio-8900-exec-1] o.a.c.c.C.[.[. ...

最新文章

  1. 003小插曲之变量和字符串
  2. storyboard放大与缩小
  3. Eclipse使用新手教程
  4. [Java网络编程]UDP通信程序练习
  5. 论文浅尝 | 利用问题生成提升知识图谱问答
  6. 边打工边研究数学 泸州“农民数学家”出版15本著作
  7. 晨哥真有料丨我们要为了对方改变自己吗?
  8. Everything本地文件检索 快速搜索/共享神器
  9. 哔哩哔哩如何提取封面_如何正确提取视频封面
  10. 今世缘前三季考卷:江苏市场贡献超九成,3流通股东减持197.6万股
  11. Process finished with exit code -1073740791 (0xC0000409)
  12. 配置ssh使用socks代理
  13. 适配器模式实战场景和本质
  14. Word撰写文章时EndNote引文作者-年份格式的几种显示形式
  15. Latex中编译时出现File `xxx.sty‘ not found.错误的解决方法
  16. docx转换为doc格式,公式变成图片问题,word2016
  17. Adobe Flash Player
  18. C#调用打印机,打印图片
  19. 读书是为了谋心 -- 易中天
  20. 简述企业信息化的主要工作内容

热门文章

  1. spring bean 小记
  2. 云端的SRE发展与实践
  3. java中VO、PO、DTO 、DO、POJO、BO、TO
  4. nginx中文件路径表示方法
  5. 物流英语与计算机操作,《物流英语与计算机模拟题及正确答案.doc
  6. 字节码是java虚拟机的指令组_JVM??
  7. 计算机科学与技术专业的课程体系,基于业务的计算机科学与技术专业课程体系...
  8. ObjectFactory 的create()方法什么时候被调用?
  9. MyBatis 源码解读-loadCustomLogImpl(settings)
  10. 对称加密-DES加密