对PostgreSQL中tablespace 与 database, table的理解

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

开始:

当前的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
|       `-- 139316
|           |-- 12436
|           |-- 12436_fsm
|           |-- 12436_vm
|           |-- 12438
|           |-- 12438_fsm
|           |-- 12438_vm
|           |-- 12440
|           |-- 12441
|           |-- 12442
|           |-- 12442_fsm
|           |-- 12442_vm
|           |-- 12444
|           |-- 12445
|           |-- 12446
|           |-- 12446_fsm
|           |-- 12446_vm
|           |-- 12448
|           |-- 12449
|           |-- 12454
|           |-- 12456
|           |-- 12457
|           |-- 12458
|           |-- 12458_fsm
|           |-- 12458_vm
|           |-- 12460
|           |-- 12462
|           |-- 12463
|           |-- 12464
|           |-- 12465
|           |-- 12465_fsm
|           |-- 12467
|           |-- 12468
|           |-- 12469
|           |-- 12471
|           |-- 12473
|           |-- 12474
|           |-- 12475
|           |-- 12476
|           |-- 12476_fsm
|           |-- 12476_vm
|           |-- 12478
|           |-- 12480
|           |-- 12481
|           |-- 12482
|           |-- 12483
|           |-- 12484
|           |-- 12485
|           |-- 12487
|           |-- 12488
|           |-- 12489
|           |-- 12489_fsm
|           |-- 12489_vm
|           |-- 12491
|           |-- 12492
|           |-- 12493
|           |-- 12493_fsm
|           |-- 12493_vm
|           |-- 12495
|           |-- 12496
|           |-- 12497
|           |-- 12497_fsm
|           |-- 12497_vm
|           |-- 12499
|           |-- 12500
|           |-- 12501
|           |-- 12501_fsm
|           |-- 12501_vm
|           |-- 12503
|           |-- 12504
|           |-- 12505
|           |-- 12505_fsm
|           |-- 12505_vm
|           |-- 12507
|           |-- 12508
|           |-- 12509
|           |-- 12509_fsm
|           |-- 12509_vm
|           |-- 12511
|           |-- 12512
|           |-- 12513
|           |-- 12514
|           |-- 12514_fsm
|           |-- 12514_vm
|           |-- 12516
|           |-- 12517
|           |-- 12518
|           |-- 12518_fsm
|           |-- 12518_vm
|           |-- 12520
|           |-- 12521
|           |-- 12522
|           |-- 12524
|           |-- 12525
|           |-- 12525_fsm
|           |-- 12525_vm
|           |-- 12527
|           |-- 12528
|           |-- 12528_fsm
|           |-- 12528_vm
|           |-- 12530
|           |-- 12530_fsm
|           |-- 12530_vm
|           |-- 12532
|           |-- 12533
|           |-- 12534
|           |-- 12535
|           |-- 12537
|           |-- 12539
|           |-- 12540
|           |-- 12541
|           |-- 12542
|           |-- 12543
|           |-- 12543_fsm
|           |-- 12543_vm
|           |-- 12545
|           |-- 12547
|           |-- 12548
|           |-- 12549
|           |-- 12549_fsm
|           |-- 12549_vm
|           |-- 12551
|           |-- 12552
|           |-- 12553
|           |-- 12555
|           |-- 12556
|           |-- 12557
|           |-- 12558
|           |-- 12558_fsm
|           |-- 12558_vm
|           |-- 12560
|           |-- 12561
|           |-- 12562
|           |-- 12562_fsm
|           |-- 12562_vm
|           |-- 12564
|           |-- 12565
|           |-- 12566
|           |-- 12567
|           |-- 12567_fsm
|           |-- 12567_vm
|           |-- 12569
|           |-- 12570
|           |-- 12571
|           |-- 12573
|           |-- 12608
|           |-- 12608_fsm
|           |-- 12608_vm
|           |-- 12610
|           |-- 12611
|           |-- 12612
|           |-- 12612_fsm
|           |-- 12612_vm
|           |-- 12614
|           |-- 12615
|           |-- 12615_fsm
|           |-- 12615_vm
|           |-- 12617
|           |-- 12618
|           |-- 12619
|           |-- 12619_fsm
|           |-- 12619_vm
|           |-- 12621
|           |-- 12622
|           |-- 12623
|           |-- 12623_fsm
|           |-- 12623_vm
|           |-- 12625
|           |-- 12626
|           |-- 12627
|           |-- 12627_fsm
|           |-- 12627_vm
|           |-- 12629
|           |-- 12630
|           |-- 12631
|           |-- 12633
|           |-- 12634
|           |-- 12635
|           |-- 12637
|           |-- 12638
|           |-- 12639
|           |-- 12641
|           |-- 12642
|           |-- 12644
|           |-- 12645
|           |-- 12646
|           |-- 12648
|           |-- 12650
|           |-- 12651
|           |-- 12652
|           |-- 12652_fsm
|           |-- 12652_vm
|           |-- 12654
|           |-- 12655
|           |-- 12656
|           |-- 12656_fsm
|           |-- 12656_vm
|           |-- 12658
|           |-- 12660
|           |-- 12661
|           |-- 12661_fsm
|           |-- 12661_vm
|           |-- 12663
|           |-- 12665
|           |-- 12666
|           |-- 12666_fsm
|           |-- 12666_vm
|           |-- 12668
|           |-- 12670
|           |-- 12671
|           |-- 12671_fsm
|           |-- 12671_vm
|           |-- 12673
|           |-- 12675
|           |-- 12676
|           |-- 12676_fsm
|           |-- 12676_vm
|           |-- 12678
|           |-- 12680
|           |-- 12681
|           |-- 12681_fsm
|           |-- 12681_vm
|           |-- 12683
|           |-- 12685
|           |-- 12686
|           |-- 12688
|           |-- 12690
|           |-- 139317
|           |-- 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 "139315"
./pg_tblspc/139315
[pgsql@localhost DemoDir]$ 

我的表的真实路径位于:

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

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

看实际大小:

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











相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
3月前
|
存储 关系型数据库 MySQL
在阿里云的AnalyticDB MySQL版中使用CREATE TABLE语句来创建内表
在阿里云的AnalyticDB MySQL版中使用CREATE TABLE语句来创建内表【1月更文挑战第16天】【1月更文挑战第78篇】
212 3
|
5月前
|
Oracle 关系型数据库 MySQL
MySQL复制表结构create table as与like的区别
MySQL复制表结构create table as与like的区别
|
2月前
|
存储 关系型数据库 MySQL
MySQL技能完整学习列表5、数据库操作——1、创建数据库和表——2、修改表结构(ALTER TABLE)
MySQL技能完整学习列表5、数据库操作——1、创建数据库和表——2、修改表结构(ALTER TABLE)
185 0
|
6月前
|
SQL Oracle 关系型数据库
【MySQL异常】1093 - You can‘t specify target table ‘daily_job‘ for update in FROM clause
【MySQL异常】1093 - You can‘t specify target table ‘daily_job‘ for update in FROM clause
73 0
|
4月前
|
关系型数据库 MySQL
MySQL 报错 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file
MySQL 报错 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file
333 0
|
7月前
|
关系型数据库 MySQL 数据库
对于mysql数据库delect from,truncate table,drop table, update操作的时候如何选择
对于mysql数据库delect from,truncate table,drop table, update操作的时候如何选择
67 2
|
8月前
|
SQL 存储 关系型数据库
MySQL创建数据表(CREATE TABLE语句)
MySQL创建数据表(CREATE TABLE语句)
544 0
|
6月前
|
SQL 监控 关系型数据库
Mysql主从同步报错解决:Error executing row event: Table zabbix.history-..
Mysql主从同步报错解决:Error executing row event: Table zabbix.history-..
|
3月前
|
JSON 关系型数据库 MySQL
这个问题是由于Flink的Table API在处理MySQL数据时,将MULTISET类型的字段转换为了JSON格式
【1月更文挑战第17天】【1月更文挑战第84篇】这个问题是由于Flink的Table API在处理MySQL数据时,将MULTISET类型的字段转换为了JSON格式
34 1
|
9月前
|
关系型数据库 MySQL
【问题处理】—— Mysql : You can‘t specify target table for update in FROM clause
【问题处理】—— Mysql : You can‘t specify target table for update in FROM clause
316 1