KEMBAR78
老司機帶你上手 PostgreSQL 關聯式資料庫系統 | PDF
老司機帶你上手 PostgreSQL 關聯式資料庫系統
Kewang, Funliday
Kewang
●
王慕羣 Kewang
●
Java / JavaScript
●
HBase / PostgreSQL / MongoDB / Elasticsearch
●
Git / DevOps
●
熱愛開源
Linkedin
Linkedin kewangtw
kewangtw
SlideShare
SlideShare kewang
kewang
Gmail
Gmail cpckewang
cpckewang
Facebook
Facebook Kewang 的資訊進化論
Kewang 的資訊進化論
devopsday taipei
devopsday taipei '17
'17
hadoopcon
hadoopcon '14 '15
'14 '15
jcconf
jcconf '16 '17 '18
'16 '17 '18
modernweb
modernweb '18 '19 '20
'18 '19 '20
GitHub
GitHub kewang
kewang
Funliday
Funliday kewang
kewang
mopcon
mopcon '14 '20
'14 '20
coscupcoscup '20'21'20'21
coscup
coscup '20 '21
'20 '21
4
本日大綱
5
本日大綱
6
本日大綱
1. Migration 資料庫版本管理
7
本日大綱
1. Migration 資料庫版本管理
2. Node.js 整合
8
本日大綱
1. Migration 資料庫版本管理
2. Node.js 整合
3. PostGIS 實務應用
9
本日大綱
1. Migration 資料庫版本管理
2. Node.js 整合
3. PostGIS 實務應用
4. DB 儲存資料用
10
本日大綱
1. Migration 資料庫版本管理
2. Node.js 整合
3. PostGIS 實務應用
4. DB 儲存資料用
5. Blurhash 顯示
11
開始
12
安裝 PostgreSQL - 主角
13
安裝 PostgreSQL - 主角
14
安裝 pgAdmin 4 - 管理介面
15
安裝 pgAdmin 4 - 管理介面
16
安裝 flyway - 資料庫版本管理
17
安裝 flyway - 資料庫版本管理
18
Migration 資料庫版本管理
19
Flyway
20
Flyway
1.資料庫版本管理
21
Flyway
1.資料庫版本管理
2.慣例優於設定
22
Flyway
1.資料庫版本管理
2.慣例優於設定
3.所有 DDL 都要版本管理
23
Flyway
1.資料庫版本管理
2.慣例優於設定
3.所有 DDL 都要版本管理
4.支援各種 RDBMS
24
conf/flyway.conf
25
conf/flyway.conf
26
flyway migrate
27
flyway migrate
28
flyway_schema_history
29
flyway_schema_history
30
DEMO 一下
31
Node.js 整合
32
node-postgres
33
node-postgres
1. Node.js 的 PostgreSQL client
34
node-postgres
1. Node.js 的 PostgreSQL client
2.支援 Promise (async/await)
35
慣例寫法
36
慣例寫法
37
慣例寫法
所有機密資料記得從 .env 取得
38
慣例寫法
所有機密資料記得從 .env 取得
application_name 方便識別
39
慣例寫法
所有機密資料記得從 .env 取得
操作 DB 都寫成 object 管理
application_name 方便識別
40
一次查詢多筆資料
41
一次查詢多筆資料
42
一次查詢多筆資料
使用 ANY 及 array 處理
43
一次查詢多筆資料
使用 ANY 及 array 處理
使用 array 帶入參數
44
取得 aggregate 內容
45
取得 aggregate 內容
46
取得 aggregate 內容
row 及 array_agg 組成 aggregation 內容
47
取得 aggregate 內容
row 及 array_agg 組成 aggregation 內容
array_to_json 讓 node-postgres 直接轉換 JSON
48
新增多筆資料
49
新增多筆資料
50
新增多筆資料
unnest 將 array 轉換為 row
51
新增多筆資料
unnest 將 array 轉換為 row
使用 array 寫入多筆資料
52
DEMO 一下
53
PostGIS 實務應用
54
PostGIS
55
PostGIS
1.讓 PostgreSQL 變成地理空間資料庫
56
PostGIS
1.讓 PostgreSQL 變成地理空間資料庫
2.可以使用各種 ST 函式操作空間資料
57
找出特定座標最近的 10 個景點
58
找出特定座標最近的 10 個景點
59
找出特定座標最近的 10 個景點
KNN 算法
60
找出特定座標的所在行政區
61
找出特定座標的所在行政區
62
找出特定座標的所在行政區
ST_Contains 算出包含特定座標的 geometry
63
DEMO 一下
64
DB 儲存資料用
65
DB 儲存資料用
66
DB 儲存資料用
1.使用者的行為,看文遠大於發文
67
DB 儲存資料用
1.使用者的行為,看文遠大於發文
2.硬碟便宜,空間換取時間
68
DB 儲存資料用
1.使用者的行為,看文遠大於發文
2.硬碟便宜,空間換取時間
3.單一動作多 table 操作,需加上 transaction
69
當做 cache
70
當做 cache
client AP Redis
DB
71
當做 cache
client AP Redis
DB
run
72
當做 cache
client AP Redis
DB
run get cache
73
當做 cache
client AP Redis
DB
run get cache
return cache
74
當做 cache
client AP Redis
DB
run get cache
return cache
if hits, get cache
75
當做 cache
client AP Redis
DB
run get cache
return cache
if hits, get cache
return cache
76
當做 cache
client AP Redis
DB
run get cache
return cache
if hits, get cache
return cache
if misses, store cache
77
當做 cache
client AP Redis
DB
run get cache
return cache
if hits, get cache
return cache
if misses, store cache
store OK
78
當做 cache
client AP Redis
DB
run get cache
return cache
if hits, get cache
return cache
done
if misses, store cache
store OK
79
不要重複計算 count
80
不要重複計算 count
舊設計
81
不要重複計算 count
舊設計
新設計
82
不要重複計算 count - 語法
83
不要重複計算 count - 語法
84
Blurhash 顯示
85
Blurhash
86
Blurhash
●
別讓你的 designer 笑你笨
87
Blurhash
●
別讓你的 designer 笑你笨
●
用有意義的色塊顯示在畫面上
88
Blurhash
●
別讓你的 designer 笑你笨
●
用有意義的色塊顯示在畫面上
●
別讓你的 DBA 笑你笨
89
Blurhash
●
別讓你的 designer 笑你笨
●
用有意義的色塊顯示在畫面上
●
別讓你的 DBA 笑你笨
●
用極短 (20 bytes) 的字串存入 DB
90
Blurhash
●
別讓你的 designer 笑你笨
●
用有意義的色塊顯示在畫面上
●
別讓你的 DBA 笑你笨
●
用極短 (20 bytes) 的字串存入 DB
91
Blurhash encode diagram
92
Blurhash encode diagram
client
CDN
S3
MQ
origin
DB
93
Blurhash encode diagram
client
CDN
S3
1. get image from CDN
MQ
origin
DB
94
Blurhash encode diagram
client
CDN
S3
1. get image from CDN
MQ
origin
2. get image from origin
DB
95
Blurhash encode diagram
client
CDN
S3
1. get image from CDN
MQ
origin
2. get image from origin
3
.
g
e
t
i
m
a
g
e
f
r
o
m
S
3
DB
96
Blurhash encode diagram
client
CDN
S3
1. get image from CDN
MQ
origin
2. get image from origin
4.push
im
age id
to
M
Q
3
.
g
e
t
i
m
a
g
e
f
r
o
m
S
3
DB
97
Blurhash encode diagram
client
CDN
S3
1. get image from CDN
MQ 5. get image from S3
origin
2. get image from origin
4.push
im
age id
to
M
Q
3
.
g
e
t
i
m
a
g
e
f
r
o
m
S
3
DB
98
Blurhash encode diagram
client
CDN
S3
1. get image from CDN
MQ 5. get image from S3
6. store blurhash to DB
origin
2. get image from origin
4.push
im
age id
to
M
Q
3
.
g
e
t
i
m
a
g
e
f
r
o
m
S
3
DB
99
Blurhash encode package
100
Blurhash encode package
101
Blurhash encode package
High performance Node.js image processing
102
Blurhash encode package
High performance Node.js image processing
A very compact representation of a placeholder for an image
103
Blurhash encode source code
104
Blurhash encode source code
105
Blurhash encode source code
轉成 jpeg 降低檔案大小
106
Blurhash encode source code
轉成 jpeg 降低檔案大小
縮小尺寸降低檔案大小
107
Blurhash encode source code
轉成 jpeg 降低檔案大小
縮小尺寸降低檔案大小
加入透明度確保 encode 不會失敗
108
Blurhash encode source code
轉成 jpeg 降低檔案大小
縮小尺寸降低檔案大小
加入透明度確保 encode 不會失敗
轉成 bitmap
109
Blurhash encode source code
轉成 jpeg 降低檔案大小
縮小尺寸降低檔案大小
加入透明度確保 encode 不會失敗
轉成 bitmap
Blurhash encode
110
Blurhash encode source code
轉成 jpeg 降低檔案大小
縮小尺寸降低檔案大小
加入透明度確保 encode 不會失敗
轉成 bitmap
Blurhash encode
將 blurhash 存入資料庫
111
Blurhash decode diagram
112
Blurhash decode diagram
client
server
CDN
DB
113
Blurhash decode diagram
client
server
1. send API request to server
CDN
DB
114
Blurhash decode diagram
client
server
1. send API request to server
CDN
DB
2. get blurhash & data from DB
115
Blurhash decode diagram
client
server
1. send API request to server
CDN
DB
2. get blurhash & data from DB
3. get image from CDN
116
DEMO 一下
117
講完了
118
想看更多
119
想看更多
●
https://www.facebook.com/kewang.information
●
https://techblog.funliday.com
120
工商時間
121
工商時間
https://hahow.in/cr/kewang-backend https://bit.ly/3AueOxt
122

老司機帶你上手 PostgreSQL 關聯式資料庫系統