- 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.
- AutoCAD繪圖實用速查通典
- 腦動力:C語言函數(shù)速查效率手冊
- R Data Mining
- Getting Started with MariaDB
- 圖解PLC控制系統(tǒng)梯形圖和語句表
- 大數(shù)據(jù)技術(shù)入門(第2版)
- 西門子S7-200 SMART PLC實例指導(dǎo)學(xué)與用
- DevOps:Continuous Delivery,Integration,and Deployment with DevOps
- 統(tǒng)計學(xué)習(xí)理論與方法:R語言版
- Visual Basic.NET程序設(shè)計
- Windows Server 2003系統(tǒng)安全管理
- MCGS嵌入版組態(tài)軟件應(yīng)用教程
- 走近大數(shù)據(jù)
- Mastering MongoDB 3.x
- 未來學(xué)徒:讀懂人工智能飛馳時代