PostgreSQL Tutorial: Tablespaces

When storing data, the data must fall on the disk. Based on the construction tablespace, the physical address where the data is stored on the disk is specified.

If you do not design the tablespace yourself, PGSQL will automatically specify a location as the default storage point.

You can use a function to check the disk path where the physical data of the table is stored.

-- 查询表存储的物理地址
select pg_relation_filepath('student');

image.png

This location is the storage address after $PG_DATA.

$PG_DATA == /var/lib/pgsql/12/data/

41000 is actually the physical file that stores data.


Build a table space and specify the data storage location

image.png

-- 构建表空间,构建表空间需要用户权限是超级管理员,其次需要指定的目录已经存在
create tablespace tp_test location '/var/lib/pgsql/12/tp_test';

image.png

Build the database and tables and assign them to this table space

image.png

In fact, after specifying the storage location of the table space, PGSQL will store a copy in the $PG_DATA directory. At the same time, when we build the tablespace, a copy will also be stored in the specified path.

The files under these two absolute paths all store data information in the table.

/var/lib/pgsql/12/data/pg_tblspc/41015/PG_12_201909212/41016/41020
/var/lib/pgsql/12/lz_tp_test/PG_12_201909212/41016/41020

You will further find that in fact, in the default directory of PGSQL, a link is stored, a connection file, similar to a shortcut

image.png

Guess you like

Origin blog.csdn.net/a772304419/article/details/132928463