- 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.
- 輕松學C語言
- 21小時學通AutoCAD
- 最簡數(shù)據(jù)挖掘
- 深度學習中的圖像分類與對抗技術(shù)
- Creo Parametric 1.0中文版從入門到精通
- 機器學習流水線實戰(zhàn)
- 機器人編程實戰(zhàn)
- PVCBOT機器人控制技術(shù)入門
- 邊緣智能:關(guān)鍵技術(shù)與落地實踐
- Azure PowerShell Quick Start Guide
- 基于企業(yè)網(wǎng)站的顧客感知服務(wù)質(zhì)量評價理論模型與實證研究
- 深度學習與目標檢測
- Dreamweaver CS6中文版多功能教材
- Bayesian Analysis with Python
- 計算機組成與操作系統(tǒng)