- Mastering PostgreSQL 12
- Hans Jürgen Sch?nig
- 276字
- 2021-08-20 10:00:21
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's structure) inside a transaction block. In a typical commercial system, a DDL will implicitly commit the current transaction. This does not occur 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 advantage 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
No relations found.
In this example, a table has been created and modified, and the entire transaction has been aborted. As you can see, there is no implicit COMMIT command 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 content management system (CMS). If a new version is released, you'll want to upgrade. Running the old version would still be OK; running the new version would also be OK, but you really don't want a mixture of old and new. Therefore, deploying an upgrade in a single transaction is highly beneficial as it upgrades an atomic operation.
- Project 2007項目管理實用詳解
- Oracle SOA Governance 11g Implementation
- SCRATCH與機器人
- Learning Microsoft Azure Storage
- 一本書玩轉數據分析(雙色圖解版)
- Dreamweaver CS3網頁設計50例
- Python Data Science Essentials
- Practical Big Data Analytics
- 水晶石影視動畫精粹:After Effects & Nuke 影視后期合成
- Oracle 11g Anti-hacker's Cookbook
- 渲染王3ds Max三維特效動畫技術
- ROS Robotics By Example(Second Edition)
- 巧學活用Photoshop
- Photoshop CS6白金手冊
- Mastering Microsoft Dynamics 365 Customer Engagement