CentOS-Linux-7에 PostgreSQL 11을 설치해 보았습니다.

CentOS-Linux-7에 PostgreSQL 11을 설치해 보았습니다.

2022-10-05 last update

12 minutes reading SQL CentOS centos7 PostgreSQL PostgreSQL11
  • 관련 기사
  • CentOS-Linux-7에 PostgreSQL 10을 설치해 보았습니다.


  • 환경


    # cat /etc/redhat-release; arch; locale | head -n1; users
    CentOS Linux release 7.6.1810 (Core) 
    x86_64
    LANG=ja_JP.utf8
    root root
    

    셋업


    root 사용자 계정에서 설치를 수행하고 자동 생성 postgres 사용자 계정에서 설정 및 동작 테스트를 수행합니다.

  • 18.1. The PostgreSQL User Account : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • 설치



    설치된 PostgreSQL이 있으면 삭제


    # yum list installed | grep postgres
    # yum remove postgresql postgresql-libs postgresql-server
    # userdel -r postgres
    

    yum 리포지토리 설정 설치


    # rpm -ivh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
    

  • PostgreSQL RPM Repository (with Yum) (영어)

  • PostgreSQL11 설치


    # yum install postgresql11 postgresql11-libs postgresql11-server
    ...
    完了しました!
    # psql --version
    psql (PostgreSQL) 11.1
    

  • psql : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • 설정 및 동작 테스트



    데이터베이스 서버 자동 시작 설정


    # systemctl enable postgresql-11.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.
    # systemctl list-unit-files -t service | grep postgres
    postgresql-11.service                         enabled
    

    postgres 사용자 계정이 등록되었는지 확인


    # cut -d: -f1 /etc/passwd | grep postgres
    postgres
    

    postgres 사용자 계정에 로그인


    # su - postgres
    

    환경 변수


    $ vim -c 'start|:set number|:2' ~/.bash_profile
    

    ~/.bash_profile
    - PGDATA=/var/lib/pgsql/11/data
    + PGCLUSTER=11/data
    + PGHOME=/usr/pgsql-${PGCLUSTER%%\/*}
    + export PATH=$PGHOME/bin:$PATH
    + export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
    + export MANPATH=$PGHOME/share/man:$MANPATH
    + PGDATA=/var/lib/pgsql/$PGCLUSTER
    
    - (2 행째)를 + 로 바꾸고 [ESC] 키 → :wq 로 저장·종료.

  • 16.5. Post-Installation Setup : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • 설정 반영


    $ . ~/.bash_profile
    $ printenv PGDATA
    /var/lib/pgsql/11/data
    

    데이터베이스 클러스터 초기화


    $ initdb --no-locale -D "$PGDATA"
    
  • --no-locale 선택사항: 로케일 사용 안함(권장)

  • 18.2. Creating a Database Cluster : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • initdb : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG


  • 데이터베이스 서버를 시작하고 현재 데이터베이스 클러스터를 확인합니다.


    $ pg_ctl start
    ...
    サーバ起動完了
    $ psql -l
                                            データベース一覧
       名前    |  所有者  | エンコーディング | 照合順序 | Ctype(変換演算子) |     アクセス権限      
    -----------+----------+------------------+----------+-------------------+-----------------------
     postgres  | postgres | SQL_ASCII        | C        | C                 | 
     template0 | postgres | SQL_ASCII        | C        | C                 | =c/postgres          +
               |          |                  |          |                   | postgres=CTc/postgres
     template1 | postgres | SQL_ASCII        | C        | C                 | =c/postgres          +
               |          |                  |          |                   | postgres=CTc/postgres
    (3 行)
    
    $ ls "$PGDATA"
    PG_VERSION        pg_commit_ts   pg_multixact  pg_stat      pg_wal                postmaster.pid
    base              pg_dynshmem    pg_notify     pg_stat_tmp  pg_xact
    current_logfiles  pg_hba.conf    pg_replslot   pg_subtrans  postgresql.auto.conf
    global            pg_ident.conf  pg_serial     pg_tblspc    postgresql.conf
    log               pg_logical     pg_snapshots  pg_twophase  postmaster.opts
    

  • 18.3. Starting the Database Server : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • pg_ctl : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG


  • 22.3. Template Databases : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • 68.1. Database File Layout : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • Hello, World! 인쇄 테스트



    스크립트 없음


    $ psql -t -A -c "SELECT 'Hello, World! '"
    Hello, World!
    

    스크립트 있음


    $ vim -c 'start|:set number' ~/hello.sql
    

    ~/hello.sql
    -- -*- mode: sql; sql-product: postgres; -*-
    SELECT 'Hello, World!';
    

    상기와 같이 입력하고, [ESC]키 → :wq 로 저장·종료.

    패턴 1


    $ psql -t -A < ~/hello.sql
    Hello, World!
    

    패턴 2


    $ psql -t -A -f ~/hello.sql
    Hello, World!
    

  • Chapter 2. The SQL Language : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG

  • SELECT : 포스그레 본가(영어)| 구판의 일본어 번역 : JPUG


  • 로그아웃


    $ logout
    

    참고



  • PostgreSQL 본가 (영어)

  • PostgreSQL 11.1 Documentation : 포스그레 본가(영어)


  • 일본 PostgreSQL 사용자회(JPUG)

  • PostgreSQL 10.5 문서 : JPUG