如何判断Postgresql表空间中的内容?

问题描述:

我创建了一个名为indexes的新表空间,我试图删除旧表空间indexes_old,它用来包含一些表和索引。当我尝试删除表空间,我得到:如何判断Postgresql表空间中的内容?

=> drop tablespace indexes_old; 
ERROR: tablespace "indexes_old" is not empty 

但是,当我尝试看看里面有什么了,似乎没有表生活在一个表空间:

=> select * from pg_tables where tablespace = 'indexes_old'; 
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers 
------------+-----------+------------+------------+------------+----------+------------- 
(0 rows) 

=> select * from pg_indexes where tablespace = 'indexes_old'; 
schemaname | tablename | indexname | tablespace | indexdef 
------------+-----------+-----------+------------+---------- 
(0 rows) 

那么,什么是在表空间,防止我放弃它?

万一它很重要,我已经使用pg_upgrade工具从Pg 8.4迁移到Pg 9.0。

的表空间是这样的:

Name  | Owner | Location  | Access privileges | Description 
-------------+----------+-----------------+-------------------+------------- 
indexes  | nobody | /data/pgindex90 |     | 
indexes_old | nobody | /data/pgindex84 |     | 

和/数据/ pgindex84的内容包括所有的旧8.4索引,加上pg_upgrade自动创建

# sudo ls -al /data/pgindex84/PG_9.0_201008051/11874 
total 8280 
drwx------ 2 postgres postgres 4096 Feb 9 14:58 . 
drwx------ 3 postgres postgres 4096 Feb 11 09:28 .. 
-rw------- 1 postgres postgres 40960 Feb 9 14:58 10462602 
-rw------- 1 postgres postgres 40960 Feb 9 14:58 10462604 
-rw------- 1 postgres postgres 4644864 Feb 9 14:58 10462614 
-rw------- 1 postgres postgres 3727360 Feb 9 14:58 10462616 
+0

我有这个问题在Windows和它原来是,我有一个数据库连接打开。 – Neoheurist 2017-06-24 16:30:55

检查pg_class里看到什么位于其中:

SELECT 
    c.relname, 
    t.spcname 
FROM 
    pg_class c 
    JOIN pg_tablespace t ON c.reltablespace = t.oid 
WHERE 
    t.spcname = 'indexes_old'; 
+1

也返回0行。我开始认为这是pg_upgrade如何迁移我的问题。 – 2011-02-11 16:01:09

在PostgreSQL这个新的9.0指数,任何PostgreSQL数据库都可以使用表空间。 (只要请求的用户有足够的权限,这是)我觉得这个查询

SELECT spcname, spclocation FROM pg_tablespace; 

会告诉你,index_old通过使用9.1在PostgreSQL的版本文件系统的目录。在那里徘徊,看看你的方式是否有真正的东西。不过,除了使用PostgreSQL的界面之外,我会非常谨慎地尝试删除其中的任何内容。

在9.2+,尝试

select spcname, pg_tablespace_location(oid) from pg_tablespace; 
+1

Postgres从版本9.2删除了spclocation – Alvin 2014-07-07 19:58:57

+1

@Alvin:谢谢。更新了答案。 – 2014-07-07 20:27:56

我们是在谈论的PGSQL接口?

列表架构(表空间)是这样的:

\dn 

列表中的所有表的模式(表)里面是这样的:

\dn <table_space>.* 

使用

\? 

了更多的选择

在第10页,并可能早一点,这似乎已经演变到:

SELECT tablename from pg_tables WHERE tablespace = ‘foo’;