顯示具有 資料庫 標籤的文章。 顯示所有文章
顯示具有 資料庫 標籤的文章。 顯示所有文章

2021年12月8日 星期三

[PostgreSQL] 資料庫的Race Condition問題與交易隔離等級

資料庫的操作會併發處理,因此也會遇到Race Condition問題

此篇文章會說明各種問題情境與解法

這裡主要是考慮使用的是 PostgreSQL 資料庫的狀況,不一樣的資料庫可能會有不同結果


- 髒寫 (Dirty Write)

在前一個寫入還沒commit前,後面的寫入覆蓋前面的值,就是 Dirty Write

範例:

DB: X = 0

Transaction A:寫入 X = 10

Transaction B:寫入 X = 5

Transaction A:COMMIT

Transaction B:COMMIT

最後 X = 5,Transaction A 的寫入被蓋掉了

2021年11月25日 星期四

[PostgreSQL] 常用SQL指令集

 

- 查詢Table的某筆資料

select "欄位名" from "表格名" where "條件"

範例:

select * from tb_customer where customer_id='xxxxxx';

select name from tb_customer where customer_id='xxxxxx' order by age asc;      (order by "欄位名" [desc, asc])