跳到主要內容

發表文章

目前顯示的是有「PostgreSQL」標籤的文章

PostgreSQL相關文章列表

PostgreSQL是BSD license的open source關聯式資料庫,會接觸到它是因為工作的關係。本區會分享紀錄有使用到的技術與遇到的問題。 Unattended installation on windows Data Alignment in PostgreSQL Resource: 神人的筆記 initdb linux只允許non-root "root" execution not permitted. and busybox

PostgreSQL - Unattended installation on windows

Introduction 要將別人軟體包裝到自己軟體中,不可或缺的東西就是Unattended installation。以Unattended installation來說,我們可以選擇透過Installer的silent mode安裝,也可以透過把目標軟體做成portable的版本。本篇文章分享這兩種方法,教導大家如何將PostgreSQL透過Unattended installation方式安裝到目標系統成為service。 Note. 本篇以PostgreSQL 10.7為例。 Install with installer Tips 安裝程式或反安裝程式的參數,除了可以直接上官網搜尋Installation User Guide以外,也可以直接使用help參數查詢: postgresql- 10.7 - 2 -windows-x64.exe --help Windows安裝程式主要有EnterpriseDB與BigSQL兩種。BigSQL版本安裝元件是透過網路下載且支援參數不如EnterpriseDB版本多,以我們需求來說,我們傾向於使用EnterpriseDB版本。接下來分享給大家安裝與反安裝方法。 Installation @ echo off set INSTALL_DIR =C:\postgres10 set INSTALLER =postgresql- 10.7 - 2 -windows-x64.exe   rem options for installation set SSMDB_SERVICE =postgresql- 10 set MODE =--unattendedmodeui none --mode unattended   set DB_PASSWD =--superpassword postgres set DB_PORT =--serverport 5432   set SERVICE_NAME =--servicename % SSMDB_SERVICE %   set PREFIX =--prefix "%INSTALL_DIR%" set DATA_DIR =--datadir "%INSTALL_DIR%\data"   set OPTIO...

Data Alignment in PostgreSQL

Problem 一年前開始處理千萬級資料時,考慮到migration速度與資料儲存空間的使用,才知道資料庫也有alignment的機制。64位元作業系統是8 bytes的對齊,取自 link 的範例,對齊前: CREATE TABLE t1 ( , a char , b int2 -- 1 byte of padding after a , c char , d int4 -- 3 bytes of padding after c , e char , f int8 -- 7 bytes of padding after e ); 對齊後,可節省11位元組空間,不管是儲存空間還是CPU使用效率都會有所提升。 CREATE TABLE t1 ( , f int8 , d int4 , b int2 , a char , c char , e char ); 我的問題是,各種型態所需的數據對齊方式該怎查呢? How to? 根據 這篇 實驗結果,欄位規則如下: 消除tuple PADDING, 字段顺序规则: 1、优先使用定长类型(例如numeric, decimal如果业务上不需要无限精度, 那么请使用定长的整型或浮点型代替) 2、定长字段(从大到小) 3、变长字段 因此我們必須知道哪些是屬於可變長的型態與型態所需要的對齊方式。此 link 提供了一個SQL,讓你可以列出所有type的typalign與typlen。其中typalign用於決定所需要的對齊方式;typlen為-1則代表為可變長的型態: SELECT typname , typbyval , typlen , typalign FROM pg_type; 假如我要找某一種特定type,加入where限制條件即可: SELECT typname , typbyval , typlen , typalign FROM pg_type WHERE typname = 'int2' ; 結果如下,可以發現typalign的字元有多種: 接下來就是去 link 中搜尋typalign, typalign char typalign is the alignment required when storing a value of this ...