关于pg_database系统表中的oid列

本文展示了如何使用PostgreSQL查询数据库信息,并通过具体示例详细解释了数据库OID的作用及其实现方式,同时给出了数据库目录结构与OID之间的对应关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

postgres=# select oid,* from pg_database;
  oid  |  datname  | datdba | encoding | datcollate  |  datctype   | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | datminmxid | dattablespace |                         datacl    
                     
-------+-----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+------------+---------------+--------------------------------------------------------
 13212 | postgres  |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | f             | t            |           -1 |         13211 |          548 |          1 |          1663 | 
 16384 | nasa      |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | f             | t            |           -1 |         13211 |          548 |          1 |          1663 | 
     1 | template1 |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | t             | t            |           -1 |         13211 |          548 |          1 |          1663 | {=c/postgres,postgres=CTc/postgres}
 13211 | template0 |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | t             | f            |           -1 |         13211 |          548 |          1 |          1663 | {=c/postgres,postgres=CTc/postgres}
 24838 | db_nasa   |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | f             | t            |           -1 |         13211 |          548 |          1 |          1663 | {=Tc/postgres,postgres=CTc/postgres,u_nasa=C/postgres}
(5 rows)

postgres=# \q
[postgres@pgserver ~]$ cd $PGDATA
[postgres@pgserver data]$ ls
base    logfile       pg_dynshmem  pg_ident.conf  pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc    PG_VERSION  pg_xact               postgresql.conf  postmaster.pid
global  pg_commit_ts  pg_hba.conf  pg_logical     pg_notify     pg_serial    pg_stat       pg_subtrans  pg_twophase  pg_wal      postgresql.auto.conf  postmaster.opts
[postgres@pgserver data]$ cd base
[postgres@pgserver base]$ ls -lrt
total 60
drwx------. 2 postgres postgres 8192 Aug  7  2017 1
drwx------. 2 postgres postgres 8192 Aug  7  2017 13211
drwx------. 2 postgres postgres 8192 Feb 24 11:52 13212
drwx------. 2 postgres postgres 8192 Feb 24 11:52 16384
drwx------  2 postgres postgres 8192 Feb 24 11:53 24838 ---->>>注意这5个目录名字与上面的“select oid,* from pg_database”查询结果中 oid列 之间的关系
[postgres@pgserver base]$ pwd
/usr/local/pgsql/data/base
[postgres@pgserver base]$ 

OID列是隐藏属性(https://www.postgresql.org/docs/10/static/catalog-pg-database.html),

select * from pg_database是查不出来的,必须select oid  from pg_database 这么明确的指定oid

关于OID的更多知识,请参考 《PostgreSQL数据库内核分析》一书第15页。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值