728x90
반응형
CentOS 8 시스템에 PostgreSQL을 설치해보도록 하자.
1. yum 명령어를 통해서 패키지 설치
- $ yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
[root@localhost ~]# yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
마지막 메타 데이터 만료 확인 : 0:00:06 전에 2020년 06월 20일 (토) 오후 01시 53분 32초.
Dependencies resolved.
==============================================================================================================
Package Architecture Version Repository Size
==============================================================================================================
Installing:
libpq-devel x86_64 12.1-3.el8 AppStream 98 k
postgresql x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 1.5 M
postgresql-contrib x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 805 k
postgresql-docs x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 12 M
postgresql-server x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 5.1 M
Installing dependencies:
libpq x86_64 12.1-3.el8 AppStream 195 k
uuid x86_64 1.6.2-42.el8 AppStream 63 k
Enabling module streams:
postgresql 10
Transaction Summary
==============================================================================================================
설치 7 Packages
Total download size: 20 M
Installed size: 63 M
Is this ok [y/N]: y
패키지 다운로드중:
(1/7): libpq-12.1-3.el8.x86_64.rpm 2.6 MB/s | 195 kB 00:00
(2/7): libpq-devel-12.1-3.el8.x86_64.rpm 1.1 MB/s | 98 kB 00:00
(3/7): postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64.rpm 4.8 MB/s | 1.5 MB 00:00
(4/7): postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x86_64.rpm 2.3 MB/s | 805 kB 00:00
(5/7): uuid-1.6.2-42.el8.x86_64.rpm 1.1 MB/s | 63 kB 00:00
(6/7): postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64.rpm 5.1 MB/s | 5.1 MB 00:01
(7/7): postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_64.rpm 5.7 MB/s | 12 MB 00:02
--------------------------------------------------------------------------------------------------------------
합계 7.3 MB/s | 20 MB 00:02
트랜잭션 점검 실행 중
트랜잭션 검사가 성공했습니다.
트랜잭션 테스트 실행 중
트랜잭션 테스트가 완료되었습니다.
거래 실행 중
준비 중입니다 : 1/1
Installing : libpq-12.1-3.el8.x86_64 1/7
Installing : postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64 2/7
Installing : uuid-1.6.2-42.el8.x86_64 3/7
스크립틀릿 실행: uuid-1.6.2-42.el8.x86_64 3/7
Installing : postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x86_64 4/7
Installing : postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_64 5/7
스크립틀릿 실행: postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64 6/7
Installing : postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64 6/7
스크립틀릿 실행: postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64 6/7
Installing : libpq-devel-12.1-3.el8.x86_64 7/7
스크립틀릿 실행: libpq-devel-12.1-3.el8.x86_64 7/7
확인 중 : libpq-12.1-3.el8.x86_64 1/7
확인 중 : libpq-devel-12.1-3.el8.x86_64 2/7
확인 중 : postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64 3/7
확인 중 : postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x86_64 4/7
확인 중 : postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_64 5/7
확인 중 : postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64 6/7
확인 중 : uuid-1.6.2-42.el8.x86_64 7/7
설치됨:
libpq-devel-12.1-3.el8.x86_64
postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64
libpq-12.1-3.el8.x86_64
uuid-1.6.2-42.el8.x86_64
완료되었습니다!
[root@localhost ~]#
2. PostgreSQL Initdb 설정
- $ postgresql-setup initdb
[root@localhost ~]# postgresql-setup initdb
WARNING: using obsoleted argument syntax, try --help
WARNING: arguments transformed to: postgresql-setup --initdb --unit postgresql
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
[root@localhost ~]#
3. 시스템 재부팅시 자동 구동 설정
- $ systemctl enable postgresql.service
[root@localhost ~]# systemctl enable postgresql.service
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
[root@localhost ~]#
4. PostgreSQL 실행 및 확인
- $ systemctl start postgresql.service
- $ systemctl status postgresql
[root@localhost ~]# systemctl start postgresql.service
[root@localhost ~]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-06-20 13:59:35 KST; 11s ago
Process: 27330 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 27333 (postmaster)
Tasks: 8 (limit: 26213)
Memory: 16.6M
CGroup: /system.slice/postgresql.service
├─27333 /usr/bin/postmaster -D /var/lib/pgsql/data
├─27334 postgres: logger process
├─27336 postgres: checkpointer process
├─27337 postgres: writer process
├─27338 postgres: wal writer process
├─27339 postgres: autovacuum launcher process
├─27340 postgres: stats collector process
└─27341 postgres: bgworker: logical replication launcher
6월 20 13:59:35 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.084 KST [27333] 로그: IPv6, 주>
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.084 KST [27333] 로그: IPv4, 주>
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.092 KST [27333] 로그: "/var/ru>
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.109 KST [27333] 로그: "/tmp/.s>
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.123 KST [27333] 로그: 서버 로 >
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.123 KST [27333] 힌트: 이제부터>
6월 20 13:59:35 localhost.localdomain systemd[1]: Started PostgreSQL database server.
[root@localhost ~]#
5. PostgreSQL 중지 및 확인
- $ systemctl stop postgresql
- $ systemctl status postgresql
[root@localhost ~]# systemctl stop postgresql
[root@localhost ~]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sat 2020-06-20 14:02:08 KST; 7s ago
Process: 27333 ExecStart=/usr/bin/postmaster -D ${PGDATA} (code=exited, status=0/SUCCESS)
Process: 27330 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 27333 (code=exited, status=0/SUCCESS)
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.084 KST [27333] 로그: IPv6, 주소: "::1", 포트 5432 번으로 접속을 >
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.084 KST [27333] 로그: IPv4, 주소: "127.0.0.1", 포트 5432 번으로 접>
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.092 KST [27333] 로그: "/var/run/postgresql/.s.PGSQL.5432" 유닉스 >
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.109 KST [27333] 로그: "/tmp/.s.PGSQL.5432" 유닉스 도메인 소켓으로 >
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.123 KST [27333] 로그: 서버 로그를 로그 수집 프로세스로 보냅니다.
6월 20 13:59:35 localhost.localdomain postmaster[27333]: 2020-06-20 13:59:35.123 KST [27333] 힌트: 이제부터 서버 로그는 "log" 디렉토리에 보관됩>
6월 20 13:59:35 localhost.localdomain systemd[1]: Started PostgreSQL database server.
6월 20 14:02:07 localhost.localdomain systemd[1]: Stopping PostgreSQL database server...
6월 20 14:02:08 localhost.localdomain systemd[1]: postgresql.service: Killing process 27334 (postmaster) with signal SIGKILL.
6월 20 14:02:08 localhost.localdomain systemd[1]: Stopped PostgreSQL database server.
6. PostgreSQL 접속
먼저 postgresql를 설치하게 되면, postgres 계정이 생성된다.
최초에는 postgres 계정으로 전환 후 psql 명령을 통해 설정을 하도록 하자
- $ su - postgres
- $ id
- $ psql
- # select version();
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ id
uid=26(postgres) gid=26(postgres) groups=26(postgres) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[postgres@localhost ~]$ psql
psql (10.6)
도움말을 보려면 "help"를 입력하십시오.
postgres=# select version();
version
------------------------------------------------------------------------------------------------------------
PostgreSQL 10.6 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 8.2.1 20180905 (Red Hat 8.2.1-3), 64-bit
(1개 행)
postgres=#
7. PostgreSQL 접근 설정
패스워를 통해서 접근을 하기 위해 해당 계정에 패스워드 설정을 하고, 접근 확인을 해보도록 하자
PostgreSQL 10 Version 부터는 패스워드 Hash가 sha-256을 지원 함에 따라, 기본 설정인 md5 보다는 sha-256으로 변경 하여 사용 하자.
- # SET password_encryption = 'scram-sha-256';
- # ALTER USER postgres WITH PASSWORD 'xxxx';
postgres=# SET password_encryption = 'scram-sha-256';
SET
postgres=# ALTER USER postgres WITH PASSWORD 'xxxx';
PostgreSQL 내에서 패스워드 Hash 및 패스워드 설정 후 패스워드로 접속을 하기 위해 "pg_hba.conf" 파일을 수정 하도록 하자.
- $ vi /var/lib/pgsql/data/pg_hba.conf
[root@localhost ~]# vi /var/lib/pgsql/data/pg_hba.conf
....
local all postgres scram-sha-256
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
8. PostgreSQL 접근 확인
이제 PostgreSQL을 접근 해보도록 하자
- psql -U postgres -W
[root@localhost ~]# psql -U postgres -W
postgres 사용자의 암호:
psql (10.6)
도움말을 보려면 "help"를 입력하십시오.
postgres=# select version();
version
------------------------------------------------------------------------------------------------------------
PostgreSQL 10.6 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 8.2.1 20180905 (Red Hat 8.2.1-3), 64-bit
(1개 행)
postgres=#
728x90
반응형
'+ DataBase > PostgreSQL' 카테고리의 다른 글
[Info] PPAS vs PostgreSQL 차이점은? (1) | 2020.11.24 |
---|---|
[PostgreSQL] 테이블 Index Rebuild (0) | 2020.04.09 |
[PostgreSQL] Port(포트) 변경 방법 (2) | 2019.12.19 |
[PostgreSQL] 원격 접속(Remote) 허용 하는 방법 (0) | 2019.12.19 |
[PostgreSQL] pg_hba.conf 설명 (0) | 2019.08.12 |
댓글