对于postgres表的存储,大家很多搞不清楚,它不像mysql哪样直观....
base 默认表空间目录,建立的表格储存在此目录中.每个 database 会在 base 目录下有一个子目录
# ll -h /data/pgsql/pgdata/base
drwx------. 2 postgres postgres 8192 12月 14 14:53 1
drwx------. 2 postgres postgres 8192 12月 14 14:53 13213
drwx------. 2 postgres postgres 8192 1月 15 09:19 13214
drwx------. 2 postgres postgres 8192 1月 15 09:57 16438
drwx------. 2 postgres postgres 8192 1月 15 12:04 16454
base 目录里的每一个数字目录对于一个 database 的 oid:
postgres=# select oid,datname from pg_database;
oid | datname
-------+-----------
13214 | postgres
16438 | ppp
1 | template1
13213 | template0
16454 | ooo -- 用这个库来验证
(5 rows)
postgres=# \c ooo
ooo=# create table user_info(id int primary key, info text, crt_time timestamp);
ooo=# insert into user_info select generate_series(1,500000), md5(random()::text), clock_timestamp();CREATE TABLE
每张表对应的 base 目录(视图没有)
ooo=# select pg_relation_filepath('user_info');
pg_relation_filepath
----------------------
base/16454/24629
(1 row)
ooo=# SELECT pg_size_pretty(pg_total_relation_size('user_info'));
ooo=# \dt+ user_info;
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-----------+-------+----------+-------+-------------
public | user_info | table | postgres | 37 MB |
(1 row)
# ll -h /data/pgsql/pgdata/base/16454/24629
-rw-------. 1 postgres postgres 37 MB 1月 20 11:08 /data/pgsql/pgdata/base/16454/24629
大小也一致足够说明 24629 就是表 user_info
至于用户又是啥?
ooo=# select u.usename,u.usesysid,c.relowner,c.relfilenode,c.oid,c.relname
from pg_user u,pg_class c where relname='user_info' and u.usesysid=c.relowner;
usename | usesysid | relowner | relfilenode | oid | relname
----------+----------+----------+-------------+-------+-----------
postgres | 10 | 10 | 24629 | 24629 | user_info
(1 row)