日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Cenots7?離線安裝部署PostgreSQL?的詳細過程_PostgreSQL

作者:我的院子 ? 更新時間: 2022-11-30 編程語言

1 PostgreSQL源碼包下載并復制

1.1PostgreSQL源碼包下載:

訪問PostgreSQL官網

選擇所需版本進行下載,本次下載安裝版本為v14.5

1.2復制源碼包至服務器

使用SSH終端工具,遠程連接服務器,并使用終端工具提供的上傳工具,把postgresql-14.5.tar.gz 上傳至服務器/usr/local/postgres14.5/src 文件夾下

建目錄文件夾的命令

[root@localhost local]# mkdir -p /usr/local/postgres14.5/src

2基于PostgreSQL源碼安裝

2.1解壓縮源碼

切換到源碼目錄

[root@localhost local]# cd /usr/local/postgres14.5/src

解壓gz

[root@localhost src]# gunzip postgresql-14.5.tar.gz

解壓tar

[root@localhost src]# tar -xf postgresql-14.5.tar

2.2檢查環境 指定安裝路徑

檢查環境,指定安裝目錄和服務端口

[root@localhost postgresql-14.5]# ./configure --prefix=/usr/local/pgsql-14.5 --with-pgport=5435

注意:使用configure腳本檢查,無錯誤或警告提示方可進行下一步編譯操作,若有錯誤或警告提示需根據提示進行相關操作。

2.3編譯

[root@localhost postgresql-14.5]# make

2.4安裝

[root@localhost postgresql-14.5]# make install

安裝位置在2.2 由 --prefix=/usr/local/pgsql-14.5中指定

3.postgresql的配置

提示:在本文檔的描述的安裝過程前,系統已經安裝有其它版本的PostgreSQL,本次安裝非升級安裝。

3.1創建用戶和組

創建組

[root@localhost ~]# groupadd postgres

創建用戶并加入組

[root@localhost pgsql-14.5]#useradd -g postgres postgres

3.2創建數據庫庫文件存儲目錄、給postgres賦予權限

創建數據庫庫文件存儲目錄data

[root@localhost DISK-8T]# mkdir -p /run/media/postgres/data

data目錄授權給postgres.postgres

[root@localhost DISK-8T]# chown postgres.postgres /run/media/postgres/data

3.3初始化數據庫目錄

切換用戶

[root@localhost bin]# su – postgres

初始化數據 -D指定初始化創建的數據庫的文件路徑

-bash-4.2$ /usr/local/pgsql-14.5/bin/initdb -D /run/media/postgres/data

提示:紅框中標注為postgres14.5的啟動方式

/usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile start

3.4啟動停止postgres14.5

3.4.1啟動

切換用戶 PG是禁止使用超級管理員來運行該命令的

[root@localhost lib]# su postgres

啟動數據庫

-bash-4.2$ /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile start

3.4.2停止

切換到postgres用戶

[root@localhost pgsql]# su - postgres

上一次登錄:三 10月 19 13:31:02 CST 2022pts/0 上

-bash-4.2$ /usr/local/pgsql-14.5/bin/pg_ctl -D /run/media/postgres/data -l logfile stop

3.4.3權限不足的解決方法

切換到postgres用戶,運行數據庫啟動命令報logfile: 權限不夠,可按下列方法解決:
編輯sudoers配置文件 ,按下圖紅框所示,給postgres用戶添加提升權限的配置

[root@localhost bin]# vi /etc/sudoers

3.4.4修改管理員密碼

說明:因服務器存在多個版本的PG,因此先在/ usr / bin中創建一個postgre14.5版本對應的psql鏈接

[root@localhost psql]# ln -s /usr/local/pgsql-14.5/bin/psql /usr/bin/psql145

切換用戶

[root@localhost psql]# su - postgres

上一次登錄:三 10月 19 14:08:33 CST 2022pts/0 上

運行postgre14.5 對應的psql

-bash-4.2$ psql145
psql145 (14.5)
Type "help" for help.
postgres=#
修改管理員密碼
\q再exit退出

postgres=# alter role postgres with password '123';

3.5開啟遠程訪問

3.5.1開啟遠程訪問

切換到數據庫目錄

[root@localhost pgsql]# cd /run/media/postgres/data

修改postgresql.conf 配置文件,開啟遠程訪問

把listen_addresses = 'localhost',修改成 listen_addresses = '*'

可在此文件中修改服務端口

[root@localhost postgre14.5Data]# vi postgresql.conf

3.5.2配置認證方式

修改pg_hba.conf 添加遠程訪問的認證方式
未尾添加 host all all 0.0.0.0/0 md5

[root@localhost postgre14.5Data]# vi pg_hba.conf

3.5.3測試連接

使用Navicat測試數據庫連接

原文鏈接:https://www.cnblogs.com/starxing/p/16816122.html

欄目分類
最近更新