PostgreSQL Schema Change Guide
gist.github.com
gist.github.com
This was also published here: https://medium.com/p/20d3749ed680, and I’ve updated it there at various times (though I’ll admit it doesn’t have the new features in PG13-14 yet) but had forgotten about the Gist version with those updates.
- "Allow partitions to be detached in a non-blocking manner. The syntax is ALTER TABLE ... DETACH PARTITION ... CONCURRENTLY, and FINALIZE." I didn't cover partitioning in the guide, but this is a real improvement to DDL with partitions.
- "Allow index commands using CONCURRENTLY to avoid waiting for the completion of other operations using CONCURRENTLY." This doesn't add new lower-lock level DDL, but it does improve the speed of existing such DDL.
- "Allow vacuum to be more aggressive in removing dead rows during minimal-locking index operations. Specifically, CREATE INDEX CONCURRENTLY and REINDEX CONCURRENTLY no longer limit the dead row removal of other relations." Similarly this doesn't add new lower-lock level DDL, but it does improve the safety of existing such DDL by eliminating a case where concurrent index creation could result in performance degradation of the system as a whole.
I wouldn't want database to lookup the table/column id every time an extra lookup of the name is performed.
It's kind of surprising in some cases when I haven't seen it before (like views) but is consistent and the alternative would be a lot harder to work with.
Allow SQL-language functions and procedures to use SQL-standard function bodies (Peter Eisentraut)
Previously only string-literal function bodies were supported. When writing a function or procedure in SQL-standard syntax, the body is parsed immediately and stored as a parse tree. This allows better tracking of function dependencies, and can have security benefits.
[1]: https://www.postgresql.org/docs/14/release-14.htmlif so that's form interpretation right, you could build a powerful lisp-style macro system that way I think.
On me for not testing better, but it was some quick and dirty work in a quick and dirty environment that doesn't even have a dev instance.
Run your rename on a copy of your production schema, then run a diff tool to see what's actually changed - in this case it would show a view definition had changed and even autogenerate the replace statement you would need to add to fix the script.
The principle behind Reshape might be applicable to temporal tables though but I don't have enough experience with them to say.
Personally I would love it if it were possible to set a mode on postgres whereby access exclusive locks break other locks and cause the transactions holding them to roll back (similar to what happens with vacuums).
I am not sure this is true anymore, or at least, it was improved in v14 to only apply when "the indexes involved are partial or have columns that are not simple column references." [1]
Another thing worth noting here is that the exclusive locks taken on system catalogues during a DDL change also replicate to your replicas (necessarily, ha!) and they will have the same behavior described, i.e., they will line up behind queries. So for instance if you run long ETL queries against a replica, the DDL lock will line up behind it and no other queries can run until the ETL query is done and the DDL lock goes through.
We’re still running PG11 so I haven’t been as good about getting some of the newer stuff added to the guide.