Q:

I have been trying to make our database clients pro-active about not filling up the partition on which the database they are using resides.

As all our clients are on the same host as the database manager, it should be easy enough for user-created tablespaces; the client can look up the filesystem path for the tablespace (in spclocation), and use OS calls to check how much available space is available:
 
adb=> select * from pg_tablespace;

  spcname   | spcowner |    spclocation    |       spcacl
------------+----------+-------------------+---------------------
pg_default | 10 | |
pg_global | 10 | |
adb | 2033793 | /database /adb | {adb =C/ adb}

I can't see how, from the client, to get the path to where the global tablespace is stored; an empty string is returned for it in the above query.

Unfortunately, we have many legacy systems in the field using a particular database created in the global tablespace, and it would be a monumental effort to get it moved into a user-created tablespace.

Hopefully I'm just missing something really simple.
 
 
A:

pg_default and pg_global locations are "hardcoded".

pg_default lives in:
 
test=# select setting||'/base' from pg_settings where name='data_directory';
 and pg_global lives in:
 
test=# select setting||'/global' from pg_settings where name='data_directory'; 
 
 src/backend/commands/tablespace.c  says so:
 
  * There are two tablespaces created at initdb time : pg_global ( for shared
  * tables ) and pg_default (for everything else).   For backwards compatibility
  * and to remain functional on platforms without symlinks , these tablespaces
  * are accessed specially : they are respectively
  *          $PGDATA / global/ relfilenode
  *          $PGDATA / base/ dboid /relfilenode
 
 
 
下面是代码中详细的说明:
 
 * Tablespaces in PostgreSQL are designed to allow users to determine
 * where the data file(s) for a given database object reside on the file
 * system.
 *
 * A tablespace represents a directory on the file system. At tablespace
 * creation time, the directory must be empty. To simplify things and
 * remove the possibility of having file name conflicts, we isolate
 * files within a tablespace into database-specific subdirectories.
 *
 * To support file access via the information given in RelFileNode, we
 * maintain a symbolic-link map in $PGDATA/pg_tblspc. The symlinks are
 * named by tablespace OIDs and point to the actual tablespace directories.
 * There is also a per-cluster version directory in each tablespace.
 * Thus the full path to an arbitrary file is
 *            $PGDATA/pg_tblspc/spcoid/PG_MAJORVER_CATVER/dboid/relfilenode
 * e.g.
 *            $PGDATA/pg_tblspc/20981/PG_9.0_201002161/719849/83292814
 *
 * There are two tablespaces created at initdb time: pg_global (for shared
 * tables) and pg_default (for everything else).  For backwards compatibility
 * and to remain functional on platforms without symlinks, these tablespaces
 * are accessed specially: they are respectively
 *            $PGDATA/global/relfilenode
 *            $PGDATA/base/dboid/relfilenode
 *
 * To allow CREATE DATABASE to give a new database a default tablespace
 * that's different from the template database's default, we make the
 * provision that a zero in pg_class.reltablespace means the database's
 * default tablespace.    Without this, CREATE DATABASE would have to go in
 * and munge the system catalogs of the new database.
 *
 
 

PostgreSQL: Query for location of global tablespace?的更多相关文章

  1. Distributed PostgreSQL on a Google Spanner Architecture – Query Layer

    转自:https://blog.yugabyte.com/distributed-postgresql-on-a-google-spanner-architecture-query-layer/ Ou ...

  2. Lost connection to MySQL server during query,MySQL设置session,global变量及网络IO与索引

    Navicat导出百万级数据时,报错:2013 - Lost connection to MySQL server during query 网上一番搜索,修改mysql如下几处配置文件即可: sel ...

  3. 在PostgreSQL中 pg_start_backup 做了什么?

    # 在PostgreSQL中 pg_start_backup 做了什么?HM 2019-07-30 ## pg_start_backup 做一个备份开始标记,还做了一些其他的操作,下面进行探寻. * ...

  4. Reading query string values in JavaScript

    时间 2016-01-23 13:01:14  CrocoDillon’s Blog 原文  http://crocodillon.com/blog/reading-query-string-valu ...

  5. 通过Javascript得到URL中的参数(query string)

    我们知道,"GET"请求中,通常把参数放在URL后面,比如这样http://www.cnblogs.com/season-huang/index?param=yes&art ...

  6. PostgreSQL相关的软件,库,工具和资源集合

    PostgreSQL相关的软件,库,工具和资源集合. 备份 wal-e - Simple Continuous Archiving for Postgres to S3, Azure, or Swif ...

  7. mysql状态分析之show global status(转)

    mysql> show global status;可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%';一.慢查询mysql> sh ...

  8. show global status和show variables mysql 优化

    mysql> show global status; 可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%'; 一.慢查询 mysql> ...

  9. (转)通过Javascript得到URL中的参数(query string)

    原文地址:http://www.cnblogs.com/season-huang/p/3322561.html 我们知道,"GET"请求中,通常把参数放在URL后面,比如这样htt ...

随机推荐

  1. object_c函数多个返回值

    - (void)readStr1:(NSString**)str1 andStr2:(NSString**)str2{    NSString *s1 = @"1";    NSS ...

  2. LNK1104:无法打开文件'mfc90.lib“

    检查Project->Properties->Configuration Properties->C/C++->Code Generation->Runtime Libr ...

  3. 2016 - 1 -19 初学HTML5 第一天

    1.HTML COMMANDS MHTL commands called elements.Usually, an element has a start tag and an end tag e.g ...

  4. WEB ui快速构建

    http://www.runoob.com/bootstrap/bootstrap-ui-editor.html 1http://pingendo.com/ 2http://www.layoutit. ...

  5. Linux内存管理之地址映射

    写在前面:由于地址映射涉及到各种寄存器的设置访问,Linux对于不同体系结构处理器的地址映射采用不同的方法,例如对于i386及后来的32位的Intel的处理器在页式映射时采用的是2级页表映射,而对于I ...

  6. 调用未绑定的父类方法和使用supper 函数 之间的选择.

    class New_int(int): # 定义一个新的类 继承 int 类 def __add__(self,other): # 重写 + 运算符 # __add__ 就是 int 中 + 的行为 ...

  7. ERP通用存储过程封装(三)

    一:解释      SQL Server提供了一种方法:可以将一些预先编译的SQL语句集中起来由SQL Server数据库服务器来完成以实现某个任务,这就是存储过程.存储过程常驻在SQL Server ...

  8. lower_bound和upper_bound算法

    参考:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html ForwardIter lower_bound(ForwardIte ...

  9. Unity3D ShaderLab 使用BlinnPhong高光类型

    Unity3D shaderLab 使用BlinnPhong高光类型 上一篇我们实现了自定义高光类型,这一篇,我们说Blinn高光,它是另一种计算和估算高光更高效的方式,它是通过视线防线和光线方向,所 ...

  10. nginx的压力测试

    #-----------http_load讲解------------------------------------#   Web服务器压力测试工具常见的有http_load.webbench.ab ...