這篇文檔,只是為了初次體驗一下PostgreSQL 12
。對於
PG有一個感觀上面的認識。
目錄
1.創建postgres用戶
groupadd postgres
useradd -g postgres postgres
2.查看操作系統版本
[root@db ~]# cat /etc/issue.bak
CentOS release 6.9 (Final)
Kernel \r on an \m
3.配置yum源(對應CentOS 6)
參考文檔:https://www.postgresql.org/download/linux/redhat/
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-
repo-latest.noarch.rpm
4.安裝客戶端包
yum install postgresql12
5.安裝服務器端包
yum install postgresql12-server
6.初始化數據庫和設置自啟動服務
service postgresql-12 initdb
chkconfig postgresql-12 on
service postgresql-12 start
7.postgres用戶的bash_profile
在/home/postgres/.bash_profile中。添加如下:
PG_BIN=/usr/pgsql-12/bin
export PG_BIN
生效
source /home/postgres/.bash_profile
------------------邪惡的分割線---------------------
PG的啟停服務
從pg的啟動日志/var/lib/pgsql/12/pgstartup.log
來分析:
- 其數據目錄是
/var/lib/pgsql/12/data
- 其二進制目錄是
/usr/pgsql-12/bin/
通過ps -ef 可以看到pg是通過postmaster進程,來推動pg的運行。如下:
[root@db data]# ps -ef |grep pg
postgres 14917 1 0 10:30 ? 00:00:00 /usr/pgsql-12/bin/postmaster -D
/var/lib/pgsql/12/data
root 15042 14534 0 10:35 pts/0 00:00:00 grep pg
自啟動的方式啟停pg服務
[root@db 12]# service postgresql-12 restart
Stopping postgresql-12 service: [ OK ]
Starting postgresql-12 service: [ OK ]
[root@db 12]# service postgresql-12 stop
Stopping postgresql-12 service: [ OK ]
[root@db 12]# service postgresql-12 start
Starting postgresql-12 service: [ OK ]
使用pg_ctl
,啟停pg的服務
關閉服務
[root@db 12]# su postgres -c '/usr/pgsql-12/bin/pg_ctl stop -D /var/lib/pgsql/12/data/ -l zsdpglog'
啟動服務
[root@db 12]# su postgres -c '/usr/pgsql-12/bin/pg_ctl start -D /var/lib/pgsql/12/data/ -l zsdpglog'
使用postgres
,啟動pg的服務
[postgres@db bin]$ ./postgres -D /var/lib/pgsql/12/data/ > /home/postgres/zsdstartupPg.log 2>&1 &
如何使用和管理pg的啟停服務,看個人喜好。