- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 281字
- 2021-07-09 19:57:12
Transactional DDLs
PostgreSQL has a very nice feature that is unfortunately not present in many commercial database systems. In PostgreSQL, it is possible to run DDLs (commands that change the data structure) inside a transaction block. In a typical commercial system, a DDL will implicitly commit the current transaction. Not so in PostgreSQL.
Apart from some minor exceptions (DROP DATABASE, CREATE TABLESPACE/DROP TABLESPACE, and so on), all DDLs in PostgreSQL are transactional, which is a huge plus and a real benefit to end users.
Here is an example:
test=# d
No relations found.
test=# BEGIN;
BEGIN
test=# CREATE TABLE t_test (id int);
CREATE TABLE
test=# ALTER TABLE t_test ALTER COLUMN id TYPE int8;
ALTER TABLE
test=# d t_test
Table "public.t_test"
Column | Type | Modifiers
--------+--------+-----------
id | bigint |
test=# ROLLBACK;
ROLLBACK
test=# d t_test
Did not find any relation named "t_test".
In this example, a table has been created and modified, and the entire transaction is aborted instantly. As you can see, there is no implicit COMMIT or any other strange behavior. PostgreSQL simply acts as expected.
Transactional DDLs are especially important if you want to deploy software. Just imagine running a CMS. If a new version is released, you'll want to upgrade. Running the old version would still be OK; running the new version is also OK but you really don't want a mixture of old and new. Therefore, deploying an upgrade in a single transaction is definitely highly beneficial as it makes upgrades an atomic operation.
- Microsoft Power BI Quick Start Guide
- 自動檢測與轉換技術
- Windows程序設計與架構
- DevOps:Continuous Delivery,Integration,and Deployment with DevOps
- 變頻器、軟啟動器及PLC實用技術260問
- 網絡化分布式系統預測控制
- 工業機器人運動仿真編程實踐:基于Android和OpenGL
- 電子設備及系統人機工程設計(第2版)
- 強化學習
- 生物3D打印:從醫療輔具制造到細胞打印
- C#求職寶典
- 筆記本電腦使用與維護
- 樂高創意機器人教程(中級 上冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- Getting Started with Tableau 2018.x
- 玩轉PowerPoint