CentOS7 PostgresSQL 설치
1. yum을 통한 설치
- yum update
# yum update -y
- postgresql 설치 가능 리스트
# yum list postgresql*
- postgresql server 설치
# yum -y install postgresql-server.x86_64
- 설치 후 rpm 명령어로 확인
# rpm -qa | grep postgresql

| RPM Query -q, --query 옵션은 패키지의 정보를 질의하는 메인 명령어이다. 여러 가지 하위 옵션이 있으므로 다양한 질의를 사용할 수 있다. 시스템에 설치된 전체 패키지의 목록을 보려면 -a 옵션을 추가 |
2. DB 생성
- Postgresql 설정 확인
# vi /usr/lib/systemd/system/postgresql.service
| # Port number for server to listen on Environment=PGPORT=5432 # Location of database directory Environment=PGDATA=/var/lib/pgsql/data |
- Postgresql DB 생성 및 초기화
# cd /usr/bin/
# postgresql-setup initdb
| Initializing database ... OK |
- Postgresql 서비스 상태 확인
# systemctl status postgresql
* disabled : OS 재부팅 시 Pogresql DB 자동 실행 설정 상태
* inactive : 현재 Postgresql 실행 상태
| ● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) Active: inactive (dead) |
# ps -ef | grep postgres
| root 9023 8843 0 03:14 pts/0 00:00:00 grep --color=auto postgres |
- Postgresql 서비스 실행
# systemctl start postgresql // postgresql 실행
# systemctl enable postgresql // 재부팅 시 자동 실행
![]() |
# ps -ef | grep postgres
| postgres 8966 1 0 03:12 ? 00:00:00 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432 postgres 8967 8966 0 03:12 ? 00:00:00 postgres: logger process postgres 8969 8966 0 03:12 ? 00:00:00 postgres: checkpointer process postgres 8970 8966 0 03:12 ? 00:00:00 postgres: writer process postgres 8971 8966 0 03:12 ? 00:00:00 postgres: wal writer process postgres 8972 8966 0 03:12 ? 00:00:00 postgres: autovacuum launcher process postgres 8973 8966 0 03:12 ? 00:00:00 postgres: stats collector process root 9012 8843 0 03:14 pts/0 00:00:00 grep --color=auto postgres |
- Postgresql 계정 패스워드 설정
# passwd postgres
- Postgresql DB 접속
# su - postgres
bash-4.2$ psql
postgres=#
- Postgresql 간단 명령어
\h : DB 명령어
\dS : 시스템 카탈로그 테이블
\l : DB 리스트
\q : DB 종료
