Sql 相当于Oracle的Postgres';s DBA_可用空间和DBA_数据文件

Sql 相当于Oracle的Postgres';s DBA_可用空间和DBA_数据文件,sql,postgresql,postgresql-9.1,postgresql-9.3,postgresql-9.2,Sql,Postgresql,Postgresql 9.1,Postgresql 9.3,Postgresql 9.2,这是sql查询。我需要转换成postgres查询 SELECT a.tablespace_name, a.maxbytes, a.mbytes, (a.maxbytes - a.mbytes), ROUND(((a.maxbytes - a.mbytes) / a.maxbytes)*100,2) AS fieldvalues FROM ( SELECT tablespace_name, SUM(maxbytes /

这是sql查询。我需要转换成postgres查询

SELECT a.tablespace_name,
       a.maxbytes,
       a.mbytes,
       (a.maxbytes - a.mbytes),
       ROUND(((a.maxbytes - a.mbytes) / a.maxbytes)*100,2) AS fieldvalues
FROM (
  SELECT tablespace_name,
         SUM(maxbytes / 1024 / 1024) maxbytes,
         SUM(bytes / 1024 / 1024) mbytes
  FROM dba_data_files
  WHERE tablespace_name IN (SELECT tablespace_name
                            FROM dba_segments
                            WHERE OWNER = 'TEST')
  GROUP BY tablespace_name
) a,
  (SELECT tablespace_name,
         SUM(bytes / 1024 / 1024) mbytes
  FROM dba_free_space
  WHERE tablespace_name IN (SELECT tablespace_name
                            FROM dba_segments
                            WHERE OWNER = 'TEST')
  GROUP BY tablespace_name
) b
WHERE a.tablespace_name = b.tablespace_name
ORDER BY a.tablespace_name

简短回答:Postgres中没有等价的查询


Postgres中的表空间概念与Oracle的表空间概念完全不同。Postgres没有容器文件。每个表都存储在特定于该表的一个(或多个文件)中。表空间只是硬盘上的一个目录

正因为如此,Postgres中不存在(或不需要)DBA\u FREE\u SPACE这样的东西

要计算单个数据库的大小,可以使用

select pg_database_size('my_database_name');
要计算架构中所有表的大小,请使用

select table_schema,
       table_name,
       pg_size_pretty(pg_total_relation_size (format('%I.%I', table_schema, table_name)))
from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog')
order by pg_total_relation_size(format('%I.%I', table_schema, table_name)) desc;

我需要将上面提到的SQL查询转换为Postgres查询什么阻止了你?我们不是一个免费的代码转换服务(虽然我有时想知道…),你想让我们怎么做?因此,这不是编码服务。你有什么问题吗?我需要dba_空闲空间,dba_数据文件,dba_段,postgres中的等效表名