Kenny's Blog
https://blog.kennycoder.io/icon.png
這是Kenny's technology blog,歡迎交流_(:3」∠)_
2024-03-10T14:06:01.535Z
https://blog.kennycoder.io/
KennyChen
Hexo
PostgreSQL performance tips you have never seen before - 筆記
https://blog.kennycoder.io/2024/03/03/PostgreSQL-performance-tips-you-have-never-seen-before-%E7%AD%86%E8%A8%98/
2024-03-03T07:28:19.000Z
2024-03-10T14:06:01.535Z
<img src="/2024/03/03/PostgreSQL-performance-tips-you-have-never-seen-before-%E7%AD%86%E8%A8%98/cover.webp" class="" title="cover">
<p>幾天前看到了這個<a href="https://www.youtube.com/watch?v=m8ogrogKjXo">影片</a>,是有名的 <code>CYBERTEC</code> 公司的 CEO 在 <code>Citus Con</code> 的演講。<code>CYBERTEC</code> 公司寫的有關 PostgreSQL 的相關技術文章品質是很高的,值得收藏看。</p>
<p>這個影片主要是分享不常見的 performance tips for PostgreSQL,所以我也來筆記一下。</p>
Postgres - rotate password with zero downtime
https://blog.kennycoder.io/2024/02/17/Postgres-rotate-password-with-zero-downtime/
2024-02-17T13:24:43.000Z
2024-03-10T14:06:01.543Z
<img src="/2024/02/17/Postgres-rotate-password-with-zero-downtime/cover.webp" class="" title="cover">
<p>為了資安安全性的問題,定期的 rotate password 是該做的事情,但問題是:rotate password 要如何避免 application 有 downtime?</p>
<p>以下紀錄 PostgreSQL 如何快速 rotate password with zero downtime。</p>
Postgres - 常見的 schema change 問題
https://blog.kennycoder.io/2023/12/31/Postgres-%E5%B8%B8%E8%A6%8B%E7%9A%84-schema-change-%E5%95%8F%E9%A1%8C/
2023-12-31T09:44:13.000Z
2024-03-10T14:06:01.559Z
<img src="/2023/12/31/Postgres-%E5%B8%B8%E8%A6%8B%E7%9A%84-schema-change-%E5%95%8F%E9%A1%8C/cover.png" class="" title="cover">
<p>幾年前我發了 <a href="https://blog.kennycoder.io/2021/07/24/Postgres-zero-downtime-migration-%E8%A9%B2%E6%B3%A8%E6%84%8F%E7%9A%84%E7%B4%B0%E7%AF%80/?highlight=zero+do">Postgres - zero-downtime migration 該注意的細節</a>,而這幾天又看到了這篇<a href="https://postgres.ai/blog/20220525-common-db-schema-change-mistakes#case-5-acquire-an-exclusive-lock--wait-in-transaction">文章</a>,讓我多學習到 schema change 需要注意的細節,因此另外開一篇新文章寫一下筆記。</p>
少為人知 PostgreSQL 的功能
https://blog.kennycoder.io/2023/12/30/%E5%B0%91%E7%82%BA%E4%BA%BA%E7%9F%A5-PostgreSQL-%E7%9A%84%E5%8A%9F%E8%83%BD/
2023-12-30T09:59:28.000Z
2024-03-10T14:06:01.643Z
<img src="/2023/12/30/%E5%B0%91%E7%82%BA%E4%BA%BA%E7%9F%A5-PostgreSQL-%E7%9A%84%E5%8A%9F%E8%83%BD/cover.png" class="" title="cover">
<p>今天的文章筆記來自 <a href="https://hakibenita.com/postgresql-unknown-features">Lesser Known PostgreSQL Features</a>,主要是在講一些 PostgreSQL 比較少人會用到的功能,自己也覺得滿有趣的。主要是紀錄自己不知道或是沒想過的功能。</p>
淺談 PostgreSQL 與 MySQL 的差異
https://blog.kennycoder.io/2023/11/18/%E8%AB%87%E8%AB%87-Postgres-%E8%88%87-MySQL-%E7%9A%84%E5%B7%AE%E7%95%B0/
2023-11-18T15:02:10.000Z
2024-03-10T14:06:01.651Z
<img src="/2023/11/18/%E8%AB%87%E8%AB%87-Postgres-%E8%88%87-MySQL-%E7%9A%84%E5%B7%AE%E7%95%B0/cover.png" class="" title="cover">
<p>今天來筆記一下 MySQL 與 PostgreSQL 的差異,這篇文章是我很久以前就想講的主題,另外多年前 Uber 也出了這篇 <a href="https://www.uber.com/en-TW/blog/postgres-to-mysql-migration/">Why Uber Engineering Switched from Postgres to MySQL</a>,我會根據這篇文章提到的內容來探討一下,MySQL 與 PostgreSQL 在怎樣的情境下的各自優缺點為何。</p>
How We Achieved Minimal Downtime During Our PostgreSQL Database Upgrade (English Version)
https://blog.kennycoder.io/2023/08/19/How-We-Achieved-Minimal-Downtime-During-Our-PostgreSQL-Database-Upgrade-English-version/
2023-08-19T08:03:31.000Z
2024-03-10T14:06:01.507Z
<img src="/2023/08/19/How-We-Achieved-Minimal-Downtime-During-Our-PostgreSQL-Database-Upgrade-English-version/cover.jpeg" class="" title="cover">
<p>Hello everyone, I’m Kenny, a Backend Engineer from <a href="https://about.dcard.tw/">Dcard</a>.</p>
<p><a href="https://about.dcard.tw/">Dcard</a> is a social networking platform that allows everyone to share ideas with confidence, regardless of background, age, or interest. It is Taiwan’s largest anonymous communication platform.</p>
<p>Recently, we upgraded the primary PG 9.6 Cluster of Dcard’s services to the 11 version, managing to limit write downtime within ten minutes, and successfully rebuilt the OfflineDB and CDC services within an hour. In this article, we will share how we accomplished this challenging task.</p>
How We Achieved Minimal Downtime During Our PostgreSQL Database Upgrade (Chinese Version)
https://blog.kennycoder.io/2023/08/19/How-We-Achieved-Minimal-Downtime-During-Our-PostgreSQL-Database-Upgrade-%E4%B8%AD%E6%96%87%E7%89%88/
2023-08-19T07:44:55.000Z
2024-03-10T14:06:01.507Z
<img src="/2023/08/19/How-We-Achieved-Minimal-Downtime-During-Our-PostgreSQL-Database-Upgrade-%E4%B8%AD%E6%96%87%E7%89%88/cover.jpeg" class="" title="cover">
<p>前陣子,我們將 Dcard 服務主要的 PG Cluster 進行主版本的升級,並且控制寫入 downtime 在十分鐘內,在一小時內重建完成 OfflineDB 與 CDC 服務。因此透過這篇文章來分享我們是如何完成這項艱困的任務。</p>
<p>以下文章內容跟公司發佈在 <a href="https://dcardlab.medium.com/how-we-achieved-minimal-downtime-during-our-postgresql-database-upgrade-6f6571800dd2">medium</a> 內容一樣,也算是紀錄自己做這大專案的嘔心歷程 XD</p>
<p>然後之後會再發一篇英文版的文章,也算是想分享給外國朋友,因為做這升級的規劃時,也上網看了不少其他國外公司的升級文章,所以我也想把我的升級過程翻譯成英文分享出去。</p>
Postgres - 一文看懂 physical replication 及 logical replication 概念
https://blog.kennycoder.io/2023/05/01/Postgres-%E4%B8%80%E6%96%87%E7%9C%8B%E6%87%82-physical-replication-%E5%8F%8A-logical-replication-%E6%A6%82%E5%BF%B5/
2023-05-01T05:26:05.000Z
2024-03-10T14:06:01.547Z
<p>今天這篇文章,是因應公司讀書會整理出來 Postgres 從 physical replication 到 logical replication 的相關概念。從歷史演化來看,並且理解 backup & recovery 概念後,再來理解何謂 physical replication,而 physical replication 本身功能已經發展多年,從 PG 10 開始發展 logical replication 並且到 PG 15 這之間做了不少 logical replication 的加強。</p>
pgcapture - DDL 捕捉
https://blog.kennycoder.io/2023/03/26/pgcapture-DDL-%E6%8D%95%E6%8D%89/
2023-03-26T07:30:27.000Z
2024-03-10T14:06:01.635Z
<img src="/2023/03/26/pgcapture-DDL-%E6%8D%95%E6%8D%89/cover.jpeg" class="" title="cover">
<p>延續上一篇講 pgcapture 的架構介紹與使用方式,接下來會開一系列文章講解 pgcapture 重要的實作細節。今天這篇文章先來講講 pgcapture 是如何做到 DDL 捕捉的。</p>
pgcapture - 介紹與示範
https://blog.kennycoder.io/2023/03/12/pgcapture-%E4%BB%8B%E7%B4%B9%E8%88%87%E7%A4%BA%E7%AF%84/
2023-03-12T08:19:40.000Z
2024-03-10T14:06:01.635Z
<img src="/2023/03/12/pgcapture-%E4%BB%8B%E7%B4%B9%E8%88%87%E7%A4%BA%E7%AF%84/cover.jpeg" class="" title="cover">
<p>上次我們講到如何透過 pgoutput plugin 加上 pgx 來實作我們自己的 CDC 功能,但是其缺點是無法複製 DDL 且直到 pg 14 才支援 pgoutput 有 binary format 的功能。</p>
<p>因此今天來介紹我前同事開發的 pgcapture 是如何去解決以上提到的兩個缺點的,且如何使用。</p>
Postgres - 使用 Golang 及 pgx 實現 CDC
https://blog.kennycoder.io/2023/02/27/Postgres-%E4%BD%BF%E7%94%A8-Golang-%E5%8F%8A-pgx-%E5%AF%A6%E7%8F%BE-CDC/
2023-02-27T09:27:32.000Z
2024-03-10T14:06:01.559Z
<img src="/2023/02/27/Postgres-%E4%BD%BF%E7%94%A8-Golang-%E5%8F%8A-pgx-%E5%AF%A6%E7%8F%BE-CDC/cover.jpeg" class="" title="cover">
<p>上一篇文章我們知道 logical decoding 的概念,這次我們來示範如何用 golang + pgx 來實現 CDC 的效果。我們知道從 Postgres 10 開始支援用 pub & sub 這種 logical replication 的方式,因此也提供 pgoutput 的 plugin 來實現 logical decoding。</p>
<p>因此這邊文章是使用 pgoutput + golang client 實現 logical replication 進而實現捕捉 CDC Event 的效果。</p>
介紹 postgres logical decoding 的概念與示範
https://blog.kennycoder.io/2023/02/12/%E4%BB%8B%E7%B4%B9-postgres-logical-decoding-%E7%9A%84%E6%A6%82%E5%BF%B5%E8%88%87%E7%A4%BA%E7%AF%84/
2023-02-12T06:49:52.000Z
2024-03-10T14:06:01.639Z
<img src="/2023/02/12/%E4%BB%8B%E7%B4%B9-postgres-logical-decoding-%E7%9A%84%E6%A6%82%E5%BF%B5%E8%88%87%E7%A4%BA%E7%AF%84/cover.jpeg" class="" title="cover">
<p>在之前的<a href="https://blog.kennycoder.io/2022/09/25/Postgres-logical-replication-%E7%A4%BA%E7%AF%84/">文章</a>有介紹過 <strong>logical replication</strong> 的概念,但其實 logical 這個概念是從 Postgres 9.4 開始提供 <strong>logical decoding</strong> 功能而來的,也是因為在 9.4 提供這個功能後,開始能夠利用這個特性實現自己的 <strong>logical replication</strong>。因此今天來介紹一下,什麼是 <strong>logical decoding</strong>,它的運作原理是什麼以及示範一下用法。</p>
pgpool-ll stream replication 架設教學
https://blog.kennycoder.io/2023/01/08/pgpool-ll-stream-replication-%E6%9E%B6%E8%A8%AD%E6%95%99%E5%AD%B8/
2023-01-08T02:45:01.000Z
2024-03-10T14:06:01.639Z
<img src="/2023/01/08/pgpool-ll-stream-replication-%E6%9E%B6%E8%A8%AD%E6%95%99%E5%AD%B8/cover.jpeg" class="" title="cover">
<p>延續上次 Postgres Stream Replication 的筆記,這次來講講 pgpool-ll,這個東西可以想成是 postgres 的 proxy,並且可以做到 load balance 的效果。</p>
<p>在升級 Postgres 的版本之前,如果你的 Postgres 前面有掛 pgpool-ll,那麼升級後,就必須去更改 pgpool-ll 的設定,因此這邊決定會先來幾篇文章講講 pgpool-ll 的相關設定。</p>
2022 年筆記回顧紀念
https://blog.kennycoder.io/2023/01/02/2022%E5%B9%B4%E7%AD%86%E8%A8%98%E5%9B%9E%E9%A1%A7%E7%B4%80%E5%BF%B5/
2023-01-02T12:32:43.000Z
2024-03-10T14:06:01.443Z
<p>今年是 2023 年,想說來回顧一下,去年 2022 年的寫筆記到現在的回顧。</p>
Postgres - 設定 physical replication 教學
https://blog.kennycoder.io/2022/12/11/Postgres-%E8%A8%AD%E5%AE%9A-physical-replication-%E6%95%99%E5%AD%B8/
2022-12-11T06:23:02.000Z
2024-03-10T14:06:01.567Z
<img src="/2022/12/11/Postgres-%E8%A8%AD%E5%AE%9A-physical-replication-%E6%95%99%E5%AD%B8/cover.jpeg" class="" title="cover">
<p>上次提到 pg_upgrade 可以快速 upgrade 單台的 Postgres Server,最後結尾有提到要如何針對 PG Cluster 做升級。這篇先不講,先來記錄一下如何快速在 PG 建立起 cluster 並且採用 physical replication。</p>
<p>這樣下篇文章才可以來講講如何快速針對 PG Cluster 做升級。</p>
透過 pg_upgrade 快速升級 Postgres
https://blog.kennycoder.io/2022/11/27/%E9%80%8F%E9%81%8E-pg-upgrade-%E5%BF%AB%E9%80%9F%E5%8D%87%E7%B4%9A-Postgres/
2022-11-27T02:11:33.000Z
2024-03-10T14:06:01.691Z
<img src="/2022/11/27/%E9%80%8F%E9%81%8E-pg-upgrade-%E5%BF%AB%E9%80%9F%E5%8D%87%E7%B4%9A-Postgres/cover.jpeg" class="" title="cover">
<p>最近在研究如何快速對 Postgres 進行升版,之前有聽過透過 Logical Replication 的方式來進行升版,但後來發現 Postgres 官方有推出 pg_upgrade 工具可以 in place 的快速升級 Postgres,並且保證盡可能向下相容,且支援跨主版本的升級。</p>
<p>因此這篇文章就來講講 pg_upgrade 這個工具怎麼使用。</p>
AlloyDB for PostgreSQL under the hood - 筆記
https://blog.kennycoder.io/2022/10/30/AlloyDB-for-PostgreSQL-under-the-hood-%E7%AD%86%E8%A8%98/
2022-10-30T14:09:48.000Z
2024-03-10T14:06:01.443Z
<img src="/2022/10/30/AlloyDB-for-PostgreSQL-under-the-hood-%E7%AD%86%E8%A8%98/cover.png" class="" title="cover">
<p>在今年 2022 Google I/O 上, Google 宣佈了新的 AlloyDB For Postgres 新產品,AlloyDB 是與 Postgres 完全相容的 database,是拿 Postgres 的 Source Code 加以改良性能,使得可以應付 <strong>enterprise-grade transactional and analytical workloads</strong>。</p>
<p>該篇文章的筆記是來自於閱讀 <a href="https://cloud.google.com/blog/products/databases/alloydb-for-postgresql-intelligent-scalable-storage">AlloyDB intelligent, database-aware storage</a> 與 <a href="https://cloud.google.com/blog/products/databases/alloydb-for-postgresql-columnar-engine">AlloyDB Columnar engine</a> 兩篇文章的。</p>
Postgres - logical replication 示範
https://blog.kennycoder.io/2022/09/25/Postgres-logical-replication-%E7%A4%BA%E7%AF%84/
2022-09-25T07:28:47.000Z
2024-03-10T14:06:01.543Z
<img src="/2022/09/25/Postgres-logical-replication-%E7%A4%BA%E7%AF%84/cover.jpeg" class="" title="cover">
<p>今天來記錄一下 logical replication 實際 demo 的方式,之後會先出一系列實際架設各種 Postgres 內的功能來玩玩。</p>
Kubernetes best practices: How and why to build small container images 筆記
https://blog.kennycoder.io/2022/09/25/Kubernetes-best-practices-How-and-why-to-build-small-container-images-%E7%AD%86%E8%A8%98/
2022-09-25T04:20:31.000Z
2024-03-10T14:06:01.523Z
<img src="/2022/09/25/Kubernetes-best-practices-How-and-why-to-build-small-container-images-%E7%AD%86%E8%A8%98/cover.png" class="" title="cover">
<p>今天來講講 Google Cloud 之前發布的一系列文章:Kubernetes best practices,我也是無意中看到,但我覺得寫得滿好的,也是值得筆記的。<a href="https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-how-and-why-to-build-small-container-images">這篇文章</a>的主題是關於為什麼 build small container images 這件事情很重要且它的好處是什麼。</p>
<p>以下的 build image 的 example 都放在 GitHub 上:<a href="https://github.com/KennyChenFight/build-small-image">https://github.com/KennyChenFight/build-small-image</a></p>
Golang - test package 在內跟在外的差別
https://blog.kennycoder.io/2022/09/10/Golang-test-package-%E5%9C%A8%E5%85%A7%E8%B7%9F%E5%9C%A8%E5%A4%96%E7%9A%84%E5%B7%AE%E5%88%A5/
2022-09-10T06:32:16.000Z
2024-03-10T14:06:01.495Z
<img src="/2022/09/10/Golang-test-package-%E5%9C%A8%E5%85%A7%E8%B7%9F%E5%9C%A8%E5%A4%96%E7%9A%84%E5%B7%AE%E5%88%A5/cover.png" class="" title="cover">
<p>今天要談談的是 golang test file 的 package 要在 internal 還是要放在 external 上?所謂的 internal 跟 external 指的是,你的 test file 是否要放在你要測試的程式碼的同一個 package 下,還是應該放在另外一個 package 上,例如 xxx_test package。</p>
<p>這兩者選擇時機點有點不太一樣,有什麼好處跟壞處呢?今天就來探討一下。</p>