데이터베이스

PostgreSQL 외장스토리지 연결

열공하는 엔지니어 2024. 10. 10. 16:10

PostgreSQL을 외장스토리지 (SAN,NAS,iSCSI  등)으로 연결하기

<연결확인>

[root@centos1 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 908M     0  908M   0% /dev
tmpfs                    920M   28K  920M   1% /dev/shm
tmpfs                    920M  9.0M  911M   1% /run
tmpfs                    920M     0  920M   0% /sys/fs/cgroup
/dev/mapper/centos-root   55G  2.7G   53G   5% /
/dev/sda1               1014M  155M  860M  16% /boot
tmpfs                    184M     0  184M   0% /run/user/0
192.168.0.155:/vol1       95G  256K   95G   1% /Database-nas

<데이터베이스 저장위치 확인>
psql -U postgres -c "SHOW data_directory;"

Password for user postgres:
     data_directory
------------------------
 /var/lib/pgsql/14/data
(1 row)

<데이터베이스 서비스종료>
systemctl stop postgresql-14
systemctl status postgresql-14

● postgresql-14.service - PostgreSQL 14 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2024-10-10 06:36:42 UTC; 13s ago
     Docs: https://www.postgresql.org/docs/14/static/
  Process: 16352 ExecStart=/usr/pgsql-14/bin/postmaster -D ${PGDATA} (code=exited, status=0/SUCCESS)
  Process: 16346 ExecStartPre=/usr/pgsql-14/bin/postgresql-14-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 16352 (code=exited, status=0/SUCCESS)

Oct 10 05:14:58 centos1.demo.netapp.com systemd[1]: Stopped PostgreSQL 14 database server.
Oct 10 05:14:58 centos1.demo.netapp.com systemd[1]: Starting PostgreSQL 14 database server...
Oct 10 05:14:58 centos1.demo.netapp.com postmaster[16352]: 2024-10-10 05:14:58.565 UTC [16352] LOG:  redirecting log output to logging collector process
Oct 10 05:14:58 centos1.demo.netapp.com postmaster[16352]: 2024-10-10 05:14:58.565 UTC [16352] HINT:  Future log output will appear in directory "log".
Oct 10 05:14:58 centos1.demo.netapp.com systemd[1]: Started PostgreSQL 14 database server.
Oct 10 06:36:42 centos1.demo.netapp.com systemd[1]: Stopping PostgreSQL 14 database server...
Oct 10 06:36:42 centos1.demo.netapp.com systemd[1]: Stopped PostgreSQL 14 database server.

<데이터마이그레이션>
cp -r  /var/lib/pgsql/14/data /Database-nas/

/var/lib/pgsql/14/data 의 파일정보

/Database-nas/data 의 파일정보

< postgresql.conf 저장위치 변경>

     42 data_directory = '/Database-nas/data'           # use data in another directory
     43                                                         # (change requires restart)
     44 #hba_file = 'ConfigDir/pg_hba.conf'     # host-based authentication file

<외장스토리지 권한변경>
chown -R postgres:postgres /Database-nas/data
chmod -R 700 /Database-nas/data

[root@centos1 data]# ll /Database-nas/data
total 132
drwx------ 6 postgres postgres  4096 Oct 10 06:42 base
-rw------- 1 postgres postgres    30 Oct 10 06:59 current_logfiles
drwx------ 2 postgres postgres  8192 Oct 10 06:59 global
drwx------ 2 postgres postgres  4096 Oct 10 06:42 log
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_commit_ts
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_dynshmem
-rwx------ 1 postgres postgres  4566 Oct 10 06:42 pg_hba.conf
-rwx------ 1 postgres postgres  1636 Oct 10 06:42 pg_ident.conf
drwx------ 4 postgres postgres  4096 Oct 10 06:42 pg_logical
drwx------ 4 postgres postgres  4096 Oct 10 06:42 pg_multixact
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_notify
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_replslot
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_serial
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_snapshots
drwx------ 2 postgres postgres  4096 Oct 10 06:59 pg_stat
drwx------ 2 postgres postgres  4096 Oct 10 06:59 pg_stat_tmp
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_subtrans
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_tblspc
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_twophase
-rwx------ 1 postgres postgres     3 Oct 10 06:42 PG_VERSION
drwx------ 3 postgres postgres  4096 Oct 10 06:42 pg_wal
drwx------ 2 postgres postgres  4096 Oct 10 06:42 pg_xact
-rwx------ 1 postgres postgres    88 Oct 10 06:42 postgresql.auto.conf
-rwx------ 1 postgres postgres 28737 Oct 10 06:42 postgresql.conf
-rwx------ 1 postgres postgres    58 Oct 10 06:59 postmaster.opts
-rw------- 1 postgres postgres    88 Oct 10 06:59 postmaster.pid

<서비스 시작>
만일, 권한설정이 누락된경우 systemctl start 명령어가 오류 발생.
systemctl start postgresql-14

<저장위치 확인>
psql -U postgres -c "SHOW data_directory;"

Password for user postgres:
   data_directory
--------------------
 /Database-nas/data
(1 row)

 

'데이터베이스' 카테고리의 다른 글

PostgreSQL 사용을 위한 DBeaver 설치 및 설정  (6) 2024.10.10
PostgreSQL 설치  (2) 2024.10.10
데이터베이스 용어  (0) 2024.02.27