PostgreSQL - Empty table

后端 未结 2 1551
傲寒
傲寒 2021-02-19 10:47

I have a table called EVENTS on my PostgreSQL DB schema.
It is empty, i.e. when I execute

SELECT * FROM EVENTS

I get an empty results set.<

相关标签:
2条回答
  • 2021-02-19 11:06

    Truncate the table:

    truncate events;
    

    From the documentation:

    TRUNCATE quickly removes all rows from a set of tables. It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables.

    If you want to immediately reclaim disk space keeping existing rows of a non-empty table, you can use vacuum:

    vacuum full events;
    

    This locks exclusively the table and rewrite it (in fact, creates a new copy and drops the old one). It is an expensive operation and generally not recommended on larger tables.

    In RDBMS some redundant usage of the disk space is a normal state. If you have a properly configured autovacuum daemon the unused space will be used when new rows are inserted.

    0 讨论(0)
  • 2021-02-19 11:13

    If you have dead rows or bloat in your table, VACUUM will not actually reclaim its memory but make it reusable and this is used when you insert data to the table next time.

    To reclaim the memory used, try

    VACUUM FULL events;

    0 讨论(0)
提交回复
热议问题