温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么使用PostgreSQL表空间

发布时间:2021-11-11 10:32:11 来源:亿速云 阅读:249 作者:iii 栏目:关系型数据库

这篇文章主要讲解了“怎么使用PostgreSQL表空间”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用PostgreSQL表空间”吧!

1、表空间:

可以通过表空间指定不同性能的存储上:

[root@jason1 ~]# mkdir -p /ssd/tbs_jason01

[root@jason1 ~]# chown -R postgres:postgres /ssd/tbs_jason01

[root@jason1 ~]# cd /ssd/tbs_jason01

postgres=# create tablespace tbs_jason01 LOCATION '/ssd/tbs_jason01';

CREATE TABLESPACE

#每个表空间对应一个目录

[root@jason1 tbs_jason01]# ll

total 0

drwx------. 2 postgres postgres 6 Sep 24 21:22 PG_10_201707211

[root@jason1 tbs_jason01]#

2、表空间目录下,每个库对应一个目录

postgres=# create database jason01 tablespace tbs_jason01;

CREATE DATABASE

postgres=# select oid,datname from pg_database;

  oid  |  datname 

-------+-----------

13212 | postgres

16384 | test

     1 | template1

13211 | template0

16385 | jason

16389 | jason01

(6 rows)

[root@jason1 PG_10_201707211]# ll

total 12

drwx------. 2 postgres postgres 8192 Sep 24 21:25 16389

3、在数据库中,每个表对应一个个文件,以每个文件1G的形式存储,单表最大支持量 32T。

postgres=# \c jason01

You are now connected to database "jason01" as user "postgres".

jason01=#

jason01=# create table jason01(

jason01(#     id int,

jason01(#     note text

jason01(# ) tablespace tbs_jason01;

CREATE TABLE

jason01=#

[root@jason1 16389]# pwd

/ssd/tbs_jason01/PG_10_201707211/16389

[root@jason1 16389]# ll -lrt

-rw-------. 1 postgres postgres  24576 Sep 24 21:25 13072_fsm

-rw-------. 1 postgres postgres   8192 Sep 24 21:25 13062_vm

-rw-------. 1 postgres postgres  24576 Sep 24 21:25 13062_fsm

-rw-------. 1 postgres postgres 136164 Sep 24 21:34 pg_internal.init

-rw-------. 1 postgres postgres      0 Sep 24 21:34 16408

-rw-------. 1 postgres postgres   8192 Sep 24 21:34 16413

-rw-------. 1 postgres postgres      0 Sep 24 21:34 16411

##查看表存储路径:

jason=# \c jason01

You are now connected to database "jason01" as user "postgres".

jason01=# select pg_relation_filepath('jason01');

            pg_relation_filepath            

---------------------------------------------

pg_tblspc/16388/PG_10_201707211/16389/16408

(1 row)

jason01=#

jason01=# insert into jason01 values(1,'dagagdgaaga');

INSERT 0 1

[root@jason1 16389]# ll 164*

-rw-------. 1 postgres postgres 8192 Sep 26 14:59 16408

-rw-------. 1 postgres postgres    0 Sep 24 21:34 16411

-rw-------. 1 postgres postgres 8192 Sep 24 21:34 16413

感谢各位的阅读,以上就是“怎么使用PostgreSQL表空间”的内容了,经过本文的学习后,相信大家对怎么使用PostgreSQL表空间这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI