EDIT: Updated to v17 (devel) - (Jan 2024).
While developing SQL based applications, it is commonplace to stumble on these 2 questions:
- What DDLs would block concurrent workload?
- Whether a DDL is going to rewrite the table (and in some cases may need ~ 2x disk space)?
Although completely answering Question 1 is beyond the scope of this post, one of the important pieces that helps answering both of these questions is whether a DDL is going to cause a relfilenode change..
For a brief background, each regular table in Postgres stores data in one or more files, each of which is referenced in the postgres catalog with a relfilenode. A simple way to check whether the current implementation is going to create / refer to another copy (file) is whether the relfilenode changes. (TRUNCATE is a standout here, which by design is going to purge the table data, so although the relfilenode would change here, in total it obviously wouldn't consume anywhere close to 2x disk-space)
The table below shows which DDLs would cause a table rewrite. As has been discussed here, we need some more info to completely answer Question 1, however meanwhile this table helps in making some concurrency / disk-usage related decisions for all Postgres versions supported today.
3 comments:
Additionally, `ALTER TABLE ALTER COLUMN TYPE TEXT` can avoid a rewrite if the old type is binary compatible. For example when increasing the length limit of VARCHAR(n), or converting VARCHAR(n) to TEXT.
@intgr - Appreciate the feedback. Updated the grid with said feedback.
Post a Comment