新聞中心
手把手教你Linux CentOS 7源碼編譯安裝PostgreSQL 9.5

鄢陵網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)于2013年開始到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
技術(shù)內(nèi)容:
PostgreSQL是一個功能強(qiáng)大的開源對象-關(guān)系型數(shù)據(jù)庫管理系統(tǒng)(ORDBMS),它以其可靠性、健壯性、靈活性和支持標(biāo)準(zhǔn)SQL的能力而著稱,在Linux環(huán)境下,我們可以通過源碼編譯的方式安裝PostgreSQL,以滿足個性化定制和優(yōu)化數(shù)據(jù)庫的需求,本文將詳細(xì)介紹如何在Linux CentOS 7系統(tǒng)上編譯安裝PostgreSQL 9.5。
準(zhǔn)備工作
1、安裝編譯工具和依賴庫
在編譯安裝PostgreSQL之前,我們需要確保系統(tǒng)中已安裝以下工具和依賴庫:
sudo yum install -y gcc make readline-devel zlib-devel openssl-devel
2、下載PostgreSQL源碼包
我們可以從PostgreSQL官方網(wǎng)站下載相應(yīng)版本的源碼包,這里以PostgreSQL 9.5為例,執(zhí)行以下命令下載源碼包:
cd /usr/local/src wget https://ftp.postgresql.org/pub/source/v9.5.25/postgresql-9.5.25.tar.bz2
3、解壓源碼包
下載完成后,解壓源碼包:
tar -jxvf postgresql-9.5.25.tar.bz2
編譯安裝PostgreSQL
1、進(jìn)入解壓后的目錄:
cd postgresql-9.5.25
2、配置編譯選項(xiàng):
./configure --prefix=/usr/local/postgresql --enable-thread-safety --with-gssapi --with-openssl --with-readline --with-zlib --with-python
參數(shù)說明:
–prefix:指定安裝目錄
–enable-thread-safety:啟用線程安全
–with-gssapi:啟用GSSAPI認(rèn)證
–with-openssl:啟用SSL加密
–with-readline:使用readline庫
–with-zlib:啟用zlib壓縮
–with-python:支持Python語言
3、編譯和安裝:
make && sudo make install
編譯過程可能需要一些時間,請耐心等待。
配置PostgreSQL
1、創(chuàng)建PostgreSQL用戶和用戶組:
sudo groupadd postgres sudo useradd -g postgres postgres
2、創(chuàng)建數(shù)據(jù)目錄并修改權(quán)限:
sudo mkdir /usr/local/postgresql/data sudo chown postgres:postgres /usr/local/postgresql/data
3、初始化數(shù)據(jù)庫:
sudo -u postgres /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data
4、配置環(huán)境變量:
編輯postgres用戶的家目錄下的.bash_profile文件:
sudo -u postgres vi /home/postgres/.bash_profile
在文件末尾添加以下內(nèi)容:
export PATH=/usr/local/postgresql/bin:$PATH export PGDATA=/usr/local/postgresql/data export PGUSER=postgres export PGPORT=5432
保存并退出,然后使環(huán)境變量生效:
source /home/postgres/.bash_profile
5、啟動PostgreSQL服務(wù):
sudo -u postgres /usr/local/postgresql/bin/pg_ctl start
測試PostgreSQL
1、登錄PostgreSQL:
sudo -u postgres psql
2、創(chuàng)建一個測試數(shù)據(jù)庫:
CREATE DATABASE test;
3、切換到測試數(shù)據(jù)庫:
c test
4、創(chuàng)建一個表并插入數(shù)據(jù):
CREATE TABLE student (id INT PRIMARY KEY, name VARCHAR(50)); INSERT INTO student (id, name) VALUES (1, '張三'), (2, '李四');
5、查詢數(shù)據(jù):
SELECT * FROM student;
6、退出psql:
q
設(shè)置PostgreSQL開機(jī)自啟
1、創(chuàng)建PostgreSQL服務(wù)文件:
sudo vi /etc/systemd/system/postgresql.service
添加以下內(nèi)容:
[Unit] Description=PostgreSQL database server After=network.target [Service] Type=forking User=postgres Group=postgres Environment=PGPORT=5432 Environment=PGDATA=/usr/local/postgresql/data ExecStart=/usr/local/postgresql/bin/pg_ctl start ExecStop=/usr/local/postgresql/bin/pg_ctl stop ExecReload=/usr/local/postgresql/bin/pg_ctl reload TimeoutSec=300 [Install] WantedBy=multi-user.target
2、啟用服務(wù)并啟動:
sudo systemctl enable postgresql sudo systemctl start postgresql
3、查看服務(wù)狀態(tài):
sudo systemctl status postgresql
至此,我們已經(jīng)成功在Linux CentOS 7系統(tǒng)上通過源碼編譯安裝了PostgreSQL 9.5,并配置了基本的環(huán)境和開機(jī)自啟服務(wù),接下來,你可以根據(jù)自己的需求進(jìn)行數(shù)據(jù)庫管理和優(yōu)化。
本文標(biāo)題:LinuxCentOS7源碼編譯安裝PostgreSQL9.5
URL標(biāo)題:http://www.dlmjj.cn/article/cdppddj.html


咨詢
建站咨詢
