CentOS安裝PostgreSQL

準備工作,使用yum安裝gcc,這一步是可選的。

yum -y install gcc gcc-c++ kernel-devel //安裝gcc、c++編譯器以及內核文件

PostgreSQL安裝

PostgreSQL的安裝,按照官網(https://www.postgresql.org/download/linux/redhat/)步驟進行即可。

1、選擇版本信息

2、安裝rpm文件

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

3、安裝客戶端

yum install postgresql96

4、安裝服務端

yum install postgresql96-server

5、初始化,設置自動啓動並且啓動postgresql服務

/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl enable postgresql-9.6
systemctl start postgresql-9.6

需要說明的是,安裝完成後,自動爲操作系統建立了一個名爲postgres的用戶,密碼爲空;同時也自動爲數據庫建立了一個postgres的用戶,密碼也爲空。

6、修改默認生成的數據庫用戶postgres的密碼。

su - postgres
psql -U postgres
alter user postgres with encrypted password 'pw';

7、創建數據庫

su - postgres
psql
create database scgis owner postgres;                 // 創建數據庫
grant all privileges on database scgis to postgres;   // 授權
\q // 退出psql

8、開啓遠程訪問

修改配置文件

vim /var/lib/pgsql/9.6/data/postgresql.conf

修改配置文件

vim /var/lib/pgsql/9.6/data/pg_hba.conf

9、重啓服務

切換到root用戶,重啓postgresql服務

systemctl restart postgresql-9.6

10、遠程連接測試,使用客戶端GUI工具進行遠程連接測試。

 

補充:服務啓動、關閉、重啓、查看狀態命令

systemctl start postgresql-9.6.service     // 啓動服務
systemctl stop postgresql-9.6.service      // 關閉服務
systemctl restart postgresql-9.6.service   // 重啓服務
systemctl status postgresql-9.6.service    // 查看狀態

 https://www.cnblogs.com/marsprj/archive/2013/02/08/2909413.html

https://www.cnblogs.com/giser-s/p/11195419.html

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