查询表和数据库的oid:
方法一:
highgo=# select oid,datname,dattablespace from pg_database;
oid | datname | dattablespace
-------+-----------+---------------
1 | template1 | 1663
12872 | template0 | 1663
12877 | highgo | 1663
16411 | postgres | 1663
25169 | proxydb | 1663
(5 rows)
highgo=# select oid,relfilenode from pg_class where relname = 'tian';
oid | relfilenode
-------+-------------
16417 | 16417
(1 row)
highgo=# select * from tian;
id | name
----+------
1 | 落枫
2 | 青龙
3 | 狗蛋
4 | qqq
(4 rows)
表对应的数据文件:
highgo=# select pg_relation_filepath('tian');
pg_relation_filepath
----------------------
base/12877/16417
(1 row)
方法二:
[highgo@node1 ~]$ oid2name
All databases:
Oid Database Name Tablespace
----------------------------------
12877 highgo pg_default
16411 postgres pg_default
25169 proxydb pg_default
12872 template0 pg_default
1 template1 pg_default
[highgo@node1 ~]$ oid2name -d highgo
From database "highgo":
Filenode Table Name
----------------------
25085 data
16417 tian
【oid2name是一个postgres自带的工具,使用之前需要安装,默认放在了解压目录的contrib下
(/upload/postgresql-9.4.4/contrib/oid2name)直接make+make install即可使用】
[highgo@node1 ~]$ cd $PGDATA/base/12877/
[highgo@node1 12877]$ cp 16417 /tmp/16417
-rw-------. 1 highgo highgo 8192 Apr 10 11:35 /tmp/16417
[highgo@node1 12877]$ rm -rf 16417
[highgo@node1 12877]$ ls -l 16417
ls: cannot access 16417: No such file or directory
此时还没有退出数据库
highgo=# select * from tian;
id | name
----+------
1 | 落枫
2 | 青龙
3 | 狗蛋
4 | qqq
(4 rows)
highgo=# \q
[highgo@node1 ~]$ psql
psql (2.0.4)
Type "help" for help.
highgo=# select * from tian;
错误: 无法打开文件 "base/12877/16417": 没有那个文件或目录
【退出后重新进入报错文件不存在】
[highgo@node1 ~]$ pg_ctl restart -m f
waiting for server to shut down.... done
server stopped
server starting
但是不影响数据库启动且列表中依旧显示已经删除的表,不影响其他表的使用。
highgo=# \d
List of relations
Schema | Name | Type | Owner
----------------+------+-------+--------
oracle_catalog | dual | view | highgo
public | data | table | highgo
public | tian | table | highgo
(3 rows)