开始:

当前的tablesapce信息

pgsql=# select * from pg_tablespace;
spcname | spcowner | spclocation | spcacl | spcoptions
------------+----------+-----------------------+--------+------------
pg_default | 10 | | |
pg_global | 10 | | |
tbs01 | 10 | /home/pgsql/tbs/tbs01 | |
(3 rows) pgsql=#

查看目录结构:

[pgsql@localhost tbs]$ tree
.
|-- dbtbs01
|-- dbtbs02
|-- tbs01
| `-- PG_9.1_201105231
`-- tbs02 5 directories, 0 files
[pgsql@localhost tbs]$

增设tablespace:

pgsql=# create tablespace dbtbs01 location '/home/pgsql/tbs/dbtbs01';
CREATE TABLESPACE
pgsql=#

创建数据,使用此tablespace:

使用上述tablespace建立数据库,在该数据库下建表:

[pgsql@localhost bin]$ ./psql
psql (9.1.2)
Type "help" for help. pgsql=# create database db1 owner pgsql tablespace dbtbs01;
CREATE DATABASE
pgsql=# \connect db1;
You are now connected to database "db1" as user "pgsql".
db1=# create table tab100(id integer);
CREATE TABLE
db1=# insert into tab100 values(generate_series(1,1000000));
INSERT 0 1000000
db1=# select pg_relation_filepath('tab100');
pg_relation_filepath
-------------------------------------------------
pg_tblspc/139315/PG_9.1_201105231/139316/139317
(1 row) db1=#
[pgsql@localhost tbs]$ pwd
/home/pgsql/tbs
[pgsql@localhost tbs]$ tree
.
|-- dbtbs01
| `-- PG_9.1_201105231
| `--
| |--
| |-- 12436_fsm
| |-- 12436_vm
| |--
| |-- 12438_fsm
| |-- 12438_vm
| |--
| |--
| |--
| |-- 12442_fsm
| |-- 12442_vm
| |--
| |--
| |--
| |-- 12446_fsm
| |-- 12446_vm
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 12458_fsm
| |-- 12458_vm
| |--
| |--
| |--
| |--
| |--
| |-- 12465_fsm
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 12476_fsm
| |-- 12476_vm
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 12489_fsm
| |-- 12489_vm
| |--
| |--
| |--
| |-- 12493_fsm
| |-- 12493_vm
| |--
| |--
| |--
| |-- 12497_fsm
| |-- 12497_vm
| |--
| |--
| |--
| |-- 12501_fsm
| |-- 12501_vm
| |--
| |--
| |--
| |-- 12505_fsm
| |-- 12505_vm
| |--
| |--
| |--
| |-- 12509_fsm
| |-- 12509_vm
| |--
| |--
| |--
| |--
| |-- 12514_fsm
| |-- 12514_vm
| |--
| |--
| |--
| |-- 12518_fsm
| |-- 12518_vm
| |--
| |--
| |--
| |--
| |--
| |-- 12525_fsm
| |-- 12525_vm
| |--
| |--
| |-- 12528_fsm
| |-- 12528_vm
| |--
| |-- 12530_fsm
| |-- 12530_vm
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 12543_fsm
| |-- 12543_vm
| |--
| |--
| |--
| |--
| |-- 12549_fsm
| |-- 12549_vm
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 12558_fsm
| |-- 12558_vm
| |--
| |--
| |--
| |-- 12562_fsm
| |-- 12562_vm
| |--
| |--
| |--
| |--
| |-- 12567_fsm
| |-- 12567_vm
| |--
| |--
| |--
| |--
| |--
| |-- 12608_fsm
| |-- 12608_vm
| |--
| |--
| |--
| |-- 12612_fsm
| |-- 12612_vm
| |--
| |--
| |-- 12615_fsm
| |-- 12615_vm
| |--
| |--
| |--
| |-- 12619_fsm
| |-- 12619_vm
| |--
| |--
| |--
| |-- 12623_fsm
| |-- 12623_vm
| |--
| |--
| |--
| |-- 12627_fsm
| |-- 12627_vm
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 12652_fsm
| |-- 12652_vm
| |--
| |--
| |--
| |-- 12656_fsm
| |-- 12656_vm
| |--
| |--
| |--
| |-- 12661_fsm
| |-- 12661_vm
| |--
| |--
| |--
| |-- 12666_fsm
| |-- 12666_vm
| |--
| |--
| |--
| |-- 12671_fsm
| |-- 12671_vm
| |--
| |--
| |--
| |-- 12676_fsm
| |-- 12676_vm
| |--
| |--
| |--
| |-- 12681_fsm
| |-- 12681_vm
| |--
| |--
| |--
| |--
| |--
| |--
| |-- 139317_fsm
| |-- PG_VERSION
| |-- pg_filenode.map
| `-- pg_internal.init
|-- dbtbs02
|-- tbs01
| `-- PG_9.1_201105231
`-- tbs02 7 directories, 231 files
[pgsql@localhost tbs]$

先看数据库信息:

db1=# select oid,datname from pg_database;
oid | datname
--------+-----------
1 | template1
12691 | template0
12699 | postgres
16384 | pgsql
16386 | tester
139316 | db1
(6 rows) db1=#

再仔细看看刚刚建立的表,位于何处:

db1=# select pg_relation_filepath('tab100');
pg_relation_filepath
-------------------------------------------------
pg_tblspc/139315/PG_9.1_201105231/139316/139317
(1 row) db1=#

我的数据库cluster根目录是 /home/pgsql/DemoDir

可以看到:

[pgsql@localhost DemoDir]$ pwd
/home/pgsql/DemoDir
[pgsql@localhost DemoDir]$ find ./ -name ""
./pg_tblspc/
[pgsql@localhost DemoDir]$

我的表的真实路径位于:

[pgsql@localhost tbs]$ pwd
/home/pgsql/tbs
[pgsql@localhost tbs]$ find ./ -name ""
./dbtbs01/PG_9.1_201105231//
[pgsql@localhost tbs]$

可以看到,pg_tblspc/139315/PG_9.1_201105231/139316/139317 是拼接出来的。

看实际大小:

[pgsql@localhost ]$ pwd
/home/pgsql/tbs/dbtbs01/PG_9.1_201105231/
[pgsql@localhost ]$ ls -l --block-size=MB -rw------- pgsql pgsql 37MB Jul :
[pgsql@localhost ]$

对PostgreSQL中tablespace 与 database, table的理解的更多相关文章

  1. Postgresql中临时表(temporary table)的特性和用法

    熟悉Oracle的人,相比对临时表(temporary table)并不陌生,很多场景对解决问题起到不错的作用,开源库Postgresql中,也有临时表的概念,虽然和Oracle中临时表名字相同,使用 ...

  2. HAWQ 官方文档创建filespace,tablespace,database,table

    1.创建Filespace 创建Filespace必须是数据库超级用户( You must be a database superuser to create a filespace.)首先创建一个f ...

  3. Hive中的数据库(Database)和表(Table)

    在前面的文章中,介绍了可以把Hive当成一个"数据库",它也具备传统数据库的数据单元,数据库(Database/Schema)和表(Table). 本文介绍一下Hive中的数据库( ...

  4. 在PostgreSQL中 pg_start_backup 做了什么?

    # 在PostgreSQL中 pg_start_backup 做了什么?HM 2019-07-30 ## pg_start_backup 做一个备份开始标记,还做了一些其他的操作,下面进行探寻. * ...

  5. Postgresql实战经验之alter table 开小差了

    Postgresql实战经验之alter table 开小差了 今天需要将一张有数据的表中一个字段varchar 类型转换为timestamp类型,但是pg的alter table 语句却开小差,出现 ...

  6. 通过arcgis在PostgreSQL中创建企业级地理数据库

    部署环境: Win7 64位旗舰版 软件版本: PostgreSQL-9.1.3-2-windows-x64 Postgis-pg91x64-setup-2.0.6-1 Arcgis 10.1 SP1 ...

  7. 数据库中Schema和Database有什么区别

    在MySQL中创建一个Schema好像就跟创建一个Database是一样的效果,在SQL Server和Orcal数据库中好像又不一样. 目前我只能理解,在mysql中 schema<==> ...

  8. PostgreSQL中关于关键字(保留字)在表名和字段名中的应用文件解决

    标识符和关键词 受限标识符或被引号修饰的标识符.它是由双引号(")包围的一个任意字符序列.一个受限标识符总是一个标识符而不会是一个关键字.因此"select"可以用于引用 ...

  9. PostgreSQL 中日期类型转换与变量使用及相关问题

    PostgreSQL中日期类型与字符串类型的转换方法 示例如下: postgres=# select current_date; date ------------ 2015-08-31 (1 row ...

随机推荐

  1. Java [Leetcode 219]Contains Duplicate II

    题目描述: Given an array of integers and an integer k, find out whether there are two distinct indices i ...

  2. POJ 1519 Digital Roots

    题意:求数根. 解法:一个数的数根就是mod9的值,0换成9,只是没想到给的是一个大数……只好先把每位都加起来再mod9…… 代码: #include<stdio.h> #include& ...

  3. golang学习遭遇错误原因分析续

    7. error: reference to field ‘Printf’ in object which has no fields or methods f.Printf("%v&quo ...

  4. android桌面小火箭升空动画

    public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceS ...

  5. 【Opencv 小工具】鼠标选区信息获取

    有时候在目标跟踪的算法初始化工作时候,需要选区一个Rect区域,来表示要跟着的目标,所以有次小工具. 使用QT和opencv 编写 项目地址 https://github.com/wzyuliyang ...

  6. SQL Server2005安装配置以及测试

    SQL Server2005有2种版本,一种是集成版的, 一种是2个文件夹形式的.这里使用后者,安装文件夹名字为:SQL Server x86,该文件夹里面有Servers和Tools文件夹以及一些其 ...

  7. js代码大全(里面啥都有)

    事件源对象event.srcElement.tagNameevent.srcElement.type 捕获释放event.srcElement.setCapture();  event.srcElem ...

  8. 2016 Multi-University Training Contest 5 1011 Two DP

    http://acm.hdu.edu.cn/showproblem.php?pid=5791 HDU5791 Two 题意 :两个数组,多少个不连续子串相等 思路: dp[i][j] :a串i结尾,b ...

  9. 《GettingThingsDone》--GTD学习笔记(二)-GTD实践指导

    一.准备阶段的建议: 高级的工作管理方法就是学会一套系统并付诸实施,直到将这套系统和方法融入你的工作和生活中. 通过行动使自己感觉良好,要比通过使自己感觉良好而进入一种较佳的行动状态容易的多. 当你在 ...

  10. 解决PHP5.3.x下ffmpeg安装配置问题

    本人的环境: OS : windows 7 64位 WAMP:2.1a PHP:5.3.3(之前是5.3.13) 项目需要用ffmpeg-php实现上传视频转码截图等功能,但是找了很多资料都没有把ff ...