PostgreSQL CloudSQL具有较高的存储使用率,但直接查询数据库返回的数据较少

时间:2018-11-08 18:50:31

标签: google-cloud-platform google-cloud-sql postgresql-9.6

在我们的主要Cloud SQL实例上,我们显示出1.4 TB的利用率。当我运行

之类的查询时
WITH sizes AS (SELECT
             nspname,
             relname,
             pg_relation_size(c.oid) AS "size"
           FROM pg_class c LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
           WHERE nspname NOT IN ('pg_catalog', 'information_schema')
           ORDER BY pg_relation_size(c.oid) DESC)

SELECT pg_size_pretty(sum(size))
FROM sizes

我将获得700 GB的存储空间。

这与我们以前的利用率保持一致。

最近,我们尝试添加一些索引,这似乎与数据膨胀有关。此后,我们已经删除了该表和所有关联的索引(我很确定)。但是实例仍显示大量使用情况。

此查询似乎可以确认表+索引也低于所示的1.4 TB。

SELECT
   table_name,
   pg_size_pretty(table_size) AS table_size,
   pg_size_pretty(indexes_size) AS indexes_size,
   pg_size_pretty(total_size) AS total_size
FROM (
SELECT
    table_name,
    pg_table_size(table_name) AS table_size,
    pg_indexes_size(table_name) AS indexes_size,
    pg_total_relation_size(table_name) AS total_size
 FROM (
    SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name
        FROM information_schema.tables
    ) AS all_tables
    ORDER BY total_size DESC
) AS pretty_sizes;

关于这些额外数据可以存储在哪里以及如何删除这些数据的任何想法?

0 个答案:

没有答案