Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

postgresql - postgres db files - which file represents the specific table/index?

when i go into sql-8.2/base/ to check how much space does my table take, there are plenty of files named by a number. how can i find the specific file which stores my specific table and index for that table?

for example, i ordered the files by date (newest first) but there are several at that particular period:

-rw-------  1 postgres sql  1.0G Dec  4 13:41 15426233
-rw-------  1 postgres sql  149M Dec  4 13:41 15426233.4
-rw-------  1 postgres sql  1.0G Dec  4 13:41 15426233.3
drwx------  3 postgres sql   75K Dec  4 13:40 .
-rw-------  1 postgres sql  1.0G Dec  4 13:34 15426233.2
-rw-------  1 postgres sql  1.0G Dec  4 13:28 15426233.1
-rw-------  1 postgres sql  3.6M Dec  4 11:23 1249
-rw-------  1 postgres sql  584K Dec  4 11:23 2659
-rw-------  1 postgres sql  672K Dec  4 11:23 2663
-rw-------  1 postgres sql  136K Dec  4 11:23 2662
-rw-------  1 postgres sql  848K Dec  4 11:23 2608
-rw-------  1 postgres sql  2.6M Dec  4 11:23 2658
-rw-------  1 postgres sql  600K Dec  4 11:23 2674
-rw-------  1 postgres sql   56K Dec  4 11:23 2679
-rw-------  1 postgres sql  632K Dec  4 11:23 2673
-rw-------  1 postgres sql   72K Dec  4 11:23 2678
-rw-------  1 postgres sql  1.8M Dec  4 11:22 2619
-rw-------  1 postgres sql  112K Dec  4 11:21 2696
-rw-------  1 postgres sql 1007M Dec  4 11:21 15426228.5
-rw-------  1 postgres sql  1.0G Dec  4 11:19 15426228.4
-rw-------  1 postgres sql  1.0G Dec  4 11:19 15426228.3
-rw-------  1 postgres sql  1.0G Dec  4 11:18 15426228.2
-rw-------  1 postgres sql  1.0G Dec  4 11:17 15426228.1
-rw-------  1 postgres sql  1.0G Dec  4 11:16 15426228
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Each directory represents a database (created via create database). The number is the oid of the database. To see the oid and its name, run the following statement:

select oid, datname
from pg_database;

Inside each directory each file corresponds to the an entry in pg_class where the oid matches the number of the file in the directory:

You can see the oids and to which relation they relate by running the statement:

select cl.relfilenode, nsp.nspname as schema_name, cl.relname, cl.relkind
from pg_class cl
  join pg_namespace nsp on cl.relnamespace = nsp.oid;

You might also want to check out the manual

Btw: if you are really still running 8.2 you should upgrade as soon as possible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...