數據庫系列_postgresql安裝使用

1.6.1 分配存儲

格式化磁盤vdb:mkfs –t ext4 /dev/vdb

新建文件夾:mkdir /data

掛載磁盤到/data:mount /dev/vdb /data

新建文件夾/data/pg_data:mkdir /data/pg_data

1.6.2 安裝postgresql yum源

###  安裝postgresql10
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

### 安裝最新版postgresql ,把剩餘步驟裏的版本號爲10的都改成最新版本號(目前是12)
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
或者
yum install https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

1.6.3 安裝postgresql客戶端

yum -y install postgresql10

1.6.4 安裝postgresql服務端

yum install -y postgresql10-server

1.6.4 配置postgresql環境變量

編輯配置文件:vim /etc/profile  追加以下內容

export PATH=/usr/pgsql-10/bin:$PATH

###export LD_LIBRARY_PATH=/usr/pgsql-10/lib:$LD_LIBRARY_PATH(方法1)

###export PGDATA=/data/pg_data(方法1)

使配置文件生效:source /etc/profile

編輯啓動服務配置文件: /usr/lib/systemd/system/postgresql-10.service 追加以下內容(方法2)

Environment = PGDATA=/data/pg_data

1.6.5 文件夾權限調整

修改/data/pg_data屬性:chown postgres:postgres /data/pg_data(方法2)

###修改/data權限:chmod -R 777 /data(方法1)

###修改/data/pg_data權限:chmod 700 /data/pg_data(方法1)

1.6.6 初始化數據倉庫

###切換用戶:su postgres(方法1)

###初始化數據倉庫:pg_ctl init(方法1)

初始化數據倉庫:postgresql-10-setup initdb(方法2) 如果報日誌文件找不到,根據提示目錄新建一個日誌文件,或者修改postgresql-10-setup 腳本重新指定日誌文件路徑

加入系統啓動項:systemctl enable postgresql-10(方法2)

1.6.7 修改數據庫配置

編輯基礎配置文件:postgresql.conf:

vim /data/pg_data/postgresql.conf

分別查找data_directory、port、listen_address:

/port、/listen_address

修改後結果:

port = 3343

listen_address=’*’

編輯網絡限制配置文件pg_hba.conf:

vim /data/pg_data/pg_hba.conf

IPv4 local connections添加以下內容

host     all        all         0.0.0.0/0            trust/md5

replication privilege添加以下內容

host replication     all        0.0.0.0/0            trust/md5

1.6.8 啓動/關閉/重啓數據庫

###啓動數據:pg_ctl start(方法1)

###關閉數據庫:pg_ctl stop(方法1)

###重啓數據庫:pg_ctl restart(方法1)

systemctl start/stop/restart/ postgresql-10(方法2)

修改管理員密碼:

su postgres

psql -p port

alter user postgres with password 'postgres';

 

標註方法1的是以pg_ctl命令啓動pgsql的,需要切換到postgres用戶下執行

標註方法2的是以postmaster命令啓動pgsql。方便設置爲系統啓動項,不需要用postgres用戶執行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章