Skip to content

antony@notes:~/suse$ cat "擴充-SUSE-Manager-Database-儲存空間.md"

擴充 SUSE Manager Database 儲存空間

2023-11-23· suse ·SUSE Manager

擴充 SUSE Manager Database 儲存空間

Preface

SUSE Manager 要升級時,遇到 PostgrasSQL 使用的/var/lib/pgsql 目錄區空間不夠辣。

本篇會介紹,如何擴充 LVM 做出來的 /var/lib/pgsql 目錄區的空間。

可以透過點擊以下目錄,選擇想看的內容,跳轉至特定章節

:::warning

:::spoiler {state=“open”} 目錄

[TOC]

:::

Step1: 環境準備

  1. 檢查 /var/lib/pgsql 在哪一顆 Disk 上
$ lsblk

螢幕輸出 :

NAME                     MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                        8:0    0  600G  0 disk
├─sda1                     8:1    0    8M  0 part
└─sda2                     8:2    0  500G  0 part
...中間省略
  ├─system-var_lib_pgsql 254:4    0   60G  0 lvm  /var/lib/pgsql
...以下省略
  • 由以上訊息得知,/var/lib/pgsql/dev/sda 這顆硬碟上
  • 目前 /var/lib/pgsql 這個目錄的 SIZE 是 60G,目標要擴充至 110G
  1. 關機
  2. /dev/sda 這顆硬碟空間
  3. 對整台虛擬機建立 SnapShot
  4. 開機
  5. 將 SUSE Manager 的所有 Service 關閉
$ sudo spacewalk-service stop
  1. 檢查是否 Service 是否都關閉
$ sudo spacewalk-service status

Step2: Resize Disk Partition

$ sudo fdisk /dev/sda

# 輸入 p 顯示當前 Disk 的 Partition 資訊
Command (m for help): p
...
Device     Start        End    Sectors  Size Type
/dev/sda1   2048      18431      16384    8M BIOS boot
/dev/sda2  18432 1048575966 1048557535  500G Linux LVM

# 輸入 d 刪除 Partition,並輸入 2 指定刪除第 2 個 Partition
Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

# 輸入 n 新增 Partition,並輸入 2 指定新增第 2 個 Partition
## First sector 以及 Last sector 直接按 Enter 使用預設值
Command (m for help): n
Partition number (2-128, default 2):
First sector (18432-1258291166, default 18432):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (18432-1258291166, default 1258291166):

Created a new partition 2 of type 'Linux filesystem' and of size 600 GiB.
Partition #2 contains a LVM2_member signature.

# 輸入 N (大寫),不要刪除 signature
Do you want to remove the signature? [Y]es/[N]o: N

# 輸入 p 顯示當前 Disk 的 Partition 資訊,檢查 /dev/sda2 已 RESIZE 為 600G
Command (m for help): p
...中間省略

Device     Start        End    Sectors  Size Type
/dev/sda1   2048      18431      16384    8M BIOS boot
/dev/sda2  18432 1258291166 1258272735  600G Linux filesystem

# 輸入 w ,將以上動作寫入儲存
Command (m for help): w
The partition table has been altered.
Syncing disks.

Step3: 將 PV RESIZE

  1. 檢查 /var/lib/pgsql 在哪個 PV

1.1 要先檢查在哪個 LV

$ sudo lvscan

螢幕輸出 :

...
  ACTIVE            '/dev/system/var_lib_pgsql' [60.00 GiB] inherit
...

1.2 再查看使用哪個 VG

$ sudo lvdisplay /dev/system/var_lib_pgsql

螢幕輸出 :

...以上省略

  VG Name                system

...以下省略

1.3 最後再檢查使用哪個 PV

$ sudo pvscan

螢幕輸出 :

  PV /dev/sda2   VG system          lvm2 [499.99 GiB / 7.99 GiB free]
  Total: 1 [499.99 GiB] / in use: 1 [499.99 GiB] / in no VG: 0 [0   ]
  1. /dev/sda2 這個 PV RESIZE
$ sudo pvresize /dev/sda2

螢幕輸出 :

  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
  1. 檢查 PV 是否有 RESIZE 成功
$ sudo pvdisplay /dev/sda2

螢幕輸出 :

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               system
  PV Size               599.99 GiB / not usable 1.98 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              153597
  Free PE               27645
  Allocated PE          125952
  PV UUID               1rnqQf-hgXH-mNCO-ZLSU-nOPY-xsfd-kzi1Nc
  • PV SIZE 已從 500 GiB RESIZE 為 600 GiB
  1. 檢查 VG 是否已經擴充
$ sudo vgdisplay system

螢幕輸出 :

  --- Volume group ---
  VG Name               system
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                6
  Open LV               6
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               599.99 GiB
  PE Size               4.00 MiB
  Total PE              153597
  Alloc PE / Size       125952 / 492.00 GiB
  Free  PE / Size       27645 / 107.99 GiB
  VG UUID               o1Ru8g-QiEv-grT3-wyfv-s7MB-2lsY-zp8A0W
  • PV SIZE 已從 500 GiB RESIZE 為 600 GiB

Step4: 將 LV 擴充 50% 可用空間

  1. 執行以下命令
$ sudo lvresize -l +50%FREE /dev/system/var_lib_pgsql

螢幕輸出 :

  Size of logical volume system/var_lib_pgsql changed from 60.00 GiB (15360 extents) to 114.00 GiB (29183 extents).
  Logical volume system/var_lib_pgsql successfully resized.
  1. 檢查是否擴充成功
$ sudo lvdisplay /dev/system/var_lib_pgsql

螢幕輸出 :

  --- Logical volume ---
  LV Path                /dev/system/var_lib_pgsql
  LV Name                var_lib_pgsql
  VG Name                system
  LV UUID                2SuUkw-6TjW-78l2-48KQ-vNUM-km4B-AX8CaE
  LV Write Access        read/write
  LV Creation host, time suma, 2023-10-06 13:45:16 +0800
  LV Status              available
  # open                 1
  LV Size                114.00 GiB
  Current LE             29183
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     1024
  Block device           254:4

Step5: 擴展 XFS 檔案系統

  1. 執行以下命令
$ sudo xfs_growfs /dev/system/var_lib_pgsql

螢幕輸出 :

meta-data=/dev/mapper/system-var_lib_pgsql isize=512    agcount=4, agsize=3932160 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=0, rmapbt=0
         =                       reflink=0    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=15728640, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=7680, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 15728640 to 29883392
  1. 檢查
$ df -hT /var/lib/pgsql

螢幕輸出 :

Filesystem                       Type  Size  Used Avail Use% Mounted on
/dev/mapper/system-var_lib_pgsql xfs   114G   29G   86G  26% /var/lib/pgsql

補充資料