PostgreSQL: Query for location of global tablespace?

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.
 *

参考:

http://dba.stackexchange.com/questions/9603/postgresql-query-for-location-of-global-tablespace

src /backend/commands/tablespace.c

时间: 2024-11-25 15:13:02

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

mysql状态分析之show global status

公司的nagios监控服务器长期对内网用MySQL数据库发出ctritical报警,因为我将其他同事的手机短信报警也开通了,搞得整个系统组的同事都怨声载道(呵呵)这时候就需要根据其status对其Mysql数据库进行优化了,这时候可以等MySQL服务器稳定运行了一段时间后运行,根据服务器的"状态"进行优化.mysql> show global status;可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%';一.慢查询mys

?Postgres-XL:基于PostgreSQL的开源可扩展数据库集群

?Postgres-XL:基于PostgreSQL的开源可扩展数据库集群 最近这一年业界去"IOE"越叫越响,很多传统企业也把去"IOE"计划摆上了桌面.我老是想不明白这些非互联网企业(比如:银行)做这种事的动力何在? 高大上的"自主可控"."振兴民族科技"等空洞口号先不去管,真正的动力在哪里? "安全"."成本"."互联网架构".......等等.等等, 唯一看起来

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

mysql> show global status;可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%';一.慢查询mysql> show variables like '%slow%';+------------------+-------+| Variable_name | Value |+------------------+-------+| log_slow_queries | ON || slow_launch_time | 2

Memcached缓存瓶颈分析

Memcached缓存瓶颈分析 获取Memcached的统计信息 Shell: # echo "stats" | nc 127.0.0.1 11211 PHP: $mc = new Memcached(); $mc->addServer('127.0.0.1',11211); $stats = $mc->getStats(); Memcached缓存瓶颈分析的一些指标 Posted in Memcached, Performance analysis & tunin

MYSQL术语表

MYSQL术语表 http://dev.mysql.com/doc/refman/5.6/en/glossary.html MySQL Glossary These terms are commonly used in information about the MySQL database server. This glossary originated as a reference for terminology about the InnoDB storage engine, and th

[MySQL Reference Manual] 8 优化

8.优化 8.优化... 1 8.1 优化概述... 1 8.2 优化SQL语句... 1 8.2.1 优化SELECT语句... 1 8.2.1.1 SELECT语句的速度... 1 8.2.1.2 WHERE子句优化... 1 8.2.1.3 Range优化... 1 8.2.1.4 索引合并(Index Merge)优化... 1 8.2.1.5 引擎Pushdown条件优化... 1 8.2.1.6 索引条件Pushdown优化... 1 8.2.1.7 使用索引扩展... 1 8.2.

Temporary Segments: What Happens When a Sort Occurs (文档 ID 102339.1)

APPLIES TO: Oracle Database - Enterprise Edition - Version 8.1.7.4 to 11.2.0.1 [Release 8.1.7 to 11.2]Information in this document applies to any platform.***Checked for relevance on 03-Nov-2014*** PURPOSE This article describes what happens when a s

Innodb引擎配置优化

简单介绍InnoDB给MySQL提供了具有提交,回滚和崩溃恢复能力的事务安全(ACID兼容)存储引擎.InnoDB锁定在行级并且也在SELECT语句提供一个Oracle风格一致的非锁定读.这些特色增加了多用户部署和性能.没有在InnoDB中扩大锁定的需要,因为在InnoDB中行级锁定适合非常小的空间.InnoDB也支持FOREIGN KEY强制.在SQL查询中,你可以自由地将InnoDB类型的表与其它MySQL的表的类型混合起来,甚至在同一个查询中也可以混合. 2.之所以选用innodb作为存储

BOM DOM

http://www.cnblogs.com/yexiaochai/archive/2013/05/28/3102674.html DOM Document Object Model 文档对象模型 一个Window对象有一个document属性引用了Document对象 Document对象表示窗口内容,他是一个巨大的API中的核心对象,他代表操作文档的内容 BOM 浏览器对象模型 Browser Object Model 说白点就是window这个东东:表示浏览器的一个实例,是访问浏览器窗口的