PostgreSQL表空间创建、删除
来源:互联网 发布:泳衣淘宝网 编辑:程序博客网 时间:2024/06/06 09:56
表空间:字面上理解就是表存储的物理空间,其实包括数据库的表、索引、序列等。
可以将表空间创建在服务器的不同分区,这样做的好处有:
一、如果初始化集群所在分区已经用光,可以方便的其他分区上创建表空间已达到扩容的目的。
二、对于频繁访问的数据可以存储在性能较高、较快的磁盘分区上,而不常用的数据存储在便宜的较慢的磁盘分区上。
语法:
postgres=# \h create tablespace
Command: CREATE TABLESPACE
Description: define a new tablespace
Syntax:
CREATE TABLESPACE tablespace_name
[ OWNER user_name ]
LOCATION 'directory'
[ WITH ( tablespace_option = value [, ... ] ) ]
用户必须有表空间所在目录访问权限,所以在创建表空间之前需要在对应分区下创建相应的目录,并为其分配权限。
[root@localhost ~]# mkdir /usr/local/pgdata
[root@localhost ~]# chown postgres:postgres /usr/local/pgdata/
创建表空间示例:
postgres=# create tablespace tbs_test owner postgres location '/usr/local/pgdata';CREATE TABLESPACE
创建表空间成功后,可在数据库集群目录下看到一个新增的目录pg_tblspc下有一个连接文件51276,指向到/usr/local/pgdata下
[root@localhost ~]# ll /mnt/syncdata/pgsql941/data/pg_tblspc/total 0lrwxrwxrwx. 1 postgres postgres 17 Aug 30 02:06 51276 -> /usr/local/pgdata
[root@localhost ~]# ll /usr/local/pgdata/total 4drwx------. 2 postgres postgres 4096 Aug 30 02:06 PG_9.4_201409291
在此表空间内创建表:
postgres=# create table test(a int) tablespace tbs_test;CREATE TABLE
现在在表空间目录下就会新增一个test表对应的文件:
[root@localhost ~]# ll /usr/local/pgdata/PG_9.4_201409291/13003/51277
-rw-------. 1 postgres postgres 0 Aug 30 02:15 /usr/local/pgdata/PG_9.4_201409291 /13003/51277
其中51277对应的是test表的relfilenode,13003是数据库postgres的oid。
postgres=# select oid,datname from pg_database where datname = 'postgres'; oid | datname -------+---------- 13003 | postgres(1 row)postgres=# select relname,relfilenode from pg_class where relname='test'; relname | relfilenode ---------+------------- test | 51277(1 row)
删除表空间:
postgres=# \h drop tablespace
Command: DROP TABLESPACE
Description: remove a tablespace
Syntax:
DROP TABLESPACE [ IF EXISTS ] name
删除表空间前必须要删除该表空间下的所有数据库对象,否则无法删除。
如:
postgres=# drop tablespace if exists tbs_test;ERROR: tablespace "tbs_test" is not empty
删除刚才在此表空间创建的表test,然后再删除表空间。
postgres=# drop table if exists test;DROP TABLEpostgres=# drop tablespace if exists tbs_test;DROP TABLESPACE
- PostgreSQL表空间创建、删除
- PostgreSQL创建表空间出错
- PostgreSQL 创建表空间测试
- postgresql创建空间数据库
- PostgreSQL数据库创建/删除
- 创建和删除表空间
- 创建/删除 表空间/用户
- PostgreSQL数据库创建、删除方法
- PostgreSQL数据库创建、删除方法
- PostgreSQL 创建和删除角色
- postgresql数据库创建、修改、删除
- Oracle创建删除用户、角色、表空间
- oracle创建和删除表空间
- ORACLE表空间的创建修改删除
- Oracle表空间的创建和删除
- oracle表空间的查看创建删除
- oralce表空间创建修改删除
- (二)创建,修改,删除表空间
- 手机安装burpsuit证书截取https请求
- 云计算复习笔记一
- 阿里云直播服务 sdk demo php
- 安装chardet 问题
- mysql 5.7 版本后数据没有字段 password 所以修改 root 密码 需要
- PostgreSQL表空间创建、删除
- Leetcode 85. Maximal Rectangle (Hard) (cpp)
- C#多线程同步(二)【Mutex】
- 公共子序列(lcs)
- 连续合数探求
- shell使用命令计算md5
- Android studio 图片加载框架Glide介绍及使用
- 修改centos 7.0 的yum源优先级priority
- ArcGIS Engine控件运行许可学习总结