PostgreSQL系统函数:pg_relation_filepath

本文详细介绍了在PostgreSQL中如何创建和使用表空间,包括创建表空间的方法、查看表空间和数据库信息,以及如何指定表的物理文件存储位置。通过具体示例,展示了表空间OID、数据库OID及表文件OID的查询方式,并解释了pg_relation_filepath函数返回的路径结构。

pg_relation_filepath:数据对象存储位置

NameReturn TypeDescription
pg_relation_filepathtextfile path name of specified relation

创建表空间

  postgres=# create tablespace tbs_test owner postgres location '/data/pgsql_5432/tbs_test';
  WARNING:  tablespace location should not be inside the data directory
  CREATE TABLESPACE

查看当前instance表空间

  postgres=\db
                  List of tablespaces
      Name    |  Owner   |         Location
  ------------+----------+---------------------------
   pg_default | postgres |
   pg_global  | postgres |
   tbs_test   | postgres | /data/pgsql_5432/tbs_test
  (3 rows)

查看instance database

  postgres=# \l
                                 List of databases
        Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
    ------------+----------+----------+---------+-------+-----------------------
     jingjing01 | postgres | UTF8     | C       | C     |
     postgres   | postgres | UTF8     | C       | C     |
     template0  | postgres | UTF8     | C       | C     | =c/postgres          +
                |          |          |         |       | postgres=CTc/postgres
     template1  | postgres | UTF8     | C       | C     | =c/postgres          +
                |          |          |         |       | postgres=CTc/postgres
    (4 rows)

切换 jingjing01 库进行进行创建table t4

  postgres=# \c jingjing01
  You are now connected to database "jingjing01" as user "postgres".
  jingjing01=#create table t4(id int) tablespace tbs_test;

查看t4的物理文件存储位置

jingjing01=# select * from pg_relation_filepath('t4');
            pg_relation_filepath
---------------------------------------------
 pg_tblspc/16400/PG_11_201809051/16385/16401

关于pg_tblspc/16400/PG_11_201809051/16385/16401 解释

pg_tblspc --表空间目录,这里其实是一个软连接
  [root@172-16-8-112 pg_tblspc]# ll
  total 0
  lrwxrwxrwx 1 postgres postgres 25 Mar 12 17:35 16400 -> /data/pgsql_5432/tbs_test
16400 --表空间oid 
  jingjing01=# select oid from pg_tablespace where spcname ='tbs_test';
    oid
  -------
  16400
  (1 row)
PG_11_201809051 --数据库版本 
16385 --当前连接的数据库oid
  jingjing01=# select oid from pg_database where datname = 'jingjing01';
    oid  
  -------
  16385
  (1 row)

16401--表文件的oid 

[root@172-16-8-112 16385]# pwd
/data/pgsql_5432/tbs_test/PG_11_201809051/16385
[root@172-16-8-112 16385]# ll
total 0
-rw------- 1 postgres postgres 0 Mar 12 17:36 16401
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值