可见性映射表文件


db03=# create table t2(id int,name varchar(20));
CREATE TABLE
db03=# create table t3(id int,name text);
CREATE TABLE

db03=# select relname,reltablespace,relfilenode,relkind,reltoastrelid from pg_class
db03-# where relname in ('t2','t3');
  relname | reltablespace | relfilenode | relkind | reltoastrelid
---------+---------------+-------------+---------+---------------
  t2      |             0 |       16713 | r       |             0
  t3      |             0 |       16716 | r       |         16719
(2 rows)
--t3的name 列类型是text,reltoastrelid就不是0;toast类似oracle里的lob
db03=# select pg_relation_filepath('t2');
  pg_relation_filepath
----------------------
  base/16639/16713
(1 row)

db03=# select pg_relation_filepath('t3');
  pg_relation_filepath
----------------------
  base/16639/16716
(1 row)

[postgres@ogg2 16639]$ ls -l 16713*
-rw------- 1 postgres postgres 0 Nov  5 20:33 16713
[postgres@ogg2 16639]$ ls -l 16716*
-rw------- 1 postgres postgres 0 Nov  5 20:34 16716
--都没有fsm文件

[postgres@ogg2 16639]$ psql
psql (11.2)
Type "help" for help.

postgres=# \c db03
You are now connected to database "db03" as user "postgres".
db03=# \d
         List of relations
  Schema | Name | Type  |  Owner  
--------+------+-------+----------
  public | t1   | table | postgres
  public | t2   | table | postgres
  public | t3   | table | postgres
(3 rows)

db03=# vacuum t2;
VACUUM
db03=# vacuum t3;
VACUUM
db03=# \q

[postgres@ogg2 16639]$ ls -l 16713*
-rw------- 1 postgres postgres 0 Nov  5 20:33 16713
[postgres@ogg2 16639]$ ls -l 16716*
-rw------- 1 postgres postgres 0 Nov  5 20:34 16716

--vacuum完成后,还是没有fsm文件,因为我两个表都是0行数据

db03=# select * from t3;
  id | name
----+------
(0 rows)

db03=# select * from t2;
  id | name
----+------
(0 rows)

db03=# \d+ t2
                                             Table "public.t2"
  Column |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description
--------+-----------------------+-----------+----------+---------+----------+--------------+-------------
  id     | integer               |           |          |         | plain    |              |
  name   | character varying(20) |           |          |         | extended |              |

db03=# \d+ t3
                                      Table "public.t3"
  Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
  id     | integer |           |          |         | plain    |              |
  name   | text    |           |          |         | extended |              |


--插入数据后,在vacuum后就有了
db03=# insert into t2 values(1,'xxxx'),(2,'yyyy');
INSERT 0 2
db03=# insert into t3 values(1,'xxxxxxxxxxxxxxxxxxx'),(2,'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy');
INSERT 0 2
db03=# vacuum t2;
VACUUM
db03=# vacuum t3;
VACUUM

[postgres@ogg2 16639]$ ls -l 16713*
-rw------- 1 postgres postgres  8192 Nov  6 11:00 16713
-rw------- 1 postgres postgres 24576 Nov  6 11:00 16713_fsm
-rw------- 1 postgres postgres  8192 Nov  6 11:00 16713_vm
[postgres@ogg2 16639]$ ls -l 16716*
-rw------- 1 postgres postgres  8192 Nov  6 11:00 16716
-rw------- 1 postgres postgres 24576 Nov  6 11:00 16716_fsm
-rw------- 1 postgres postgres  8192 Nov  6 11:00 16716_vm
[postgres@ogg2 16639]$ ls -l 16719*
-rw------- 1 postgres postgres 0 Nov  5 20:34 16719



VACUUM有两种方式,一种被称为“Lazy VACUUM”,另一种被称为”Full VACUUM”,VM文件仅在Lazy VACUUM中使用,Full VACUUM操作则需要对整个数据文件进行扫描。

posted @ 2022-11-06 12:34  gwgwgw  阅读(30)  评论(0)    收藏  举报