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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM