官术网_书友最值得收藏!

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 TABLESPACEDROP 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.

To facilitate good software practices, we can include several separately coded modules from our source control system into a single deployment transaction.
主站蜘蛛池模板: 河源市| 化隆| 大田县| 河池市| 宜昌市| 定南县| 台中县| 曲松县| 双牌县| 岱山县| 湟中县| 江油市| 威宁| 岑溪市| 三门县| 潮州市| 都安| 于田县| 彭泽县| 垫江县| 教育| 松桃| 昔阳县| 邛崃市| 扎囊县| 神木县| 建湖县| 佳木斯市| 佛冈县| 陆河县| 莱州市| 通山县| 湖南省| 安吉县| 大港区| 固原市| 金乡县| 二连浩特市| 宁陵县| 三门县| 化隆|