引言
PostgreSQL是一個(gè)強(qiáng)大的開源關(guān)系型數(shù)據(jù)庫系統(tǒng),而PostGIS則為PostgreSQL提供了空間數(shù)據(jù)處理能力。本教程將指導(dǎo)您在Rocky Linux 9上安裝和配置這兩個(gè)軟件。
更新系統(tǒng)
開始安裝之前,請(qǐng)確保您的系統(tǒng)已更新到最新狀態(tài):
sudo dnf update -y
安裝PostgreSQL存儲(chǔ)庫
添加官方PostgreSQL存儲(chǔ)庫:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安裝PostgreSQL
安裝PostgreSQL 14及其相關(guān)組件:
sudo dnf install -y postgresql14-server postgresql14-contrib
初始化數(shù)據(jù)庫
初始化PostgreSQL數(shù)據(jù)庫:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
啟動(dòng)并啟用PostgreSQL服務(wù)
啟動(dòng)PostgreSQL服務(wù)并設(shè)置為開機(jī)自啟:
sudo systemctl start postgresql-14
sudo systemctl enable postgresql-14
安裝PostGIS
安裝PostGIS及其依賴:
sudo dnf install -y epel-release
sudo dnf install -y postgis34_14
配置PostgreSQL
切換到postgres用戶并啟動(dòng)psql:
sudo -i -u postgres
psql
創(chuàng)建數(shù)據(jù)庫并啟用PostGIS
在psql環(huán)境中,創(chuàng)建一個(gè)新數(shù)據(jù)庫并啟用PostGIS擴(kuò)展:
CREATE DATABASE gisdb;
c gisdb
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION postgis_raster;
驗(yàn)證安裝
驗(yàn)證PostGIS是否正確安裝:
SELECT PostGIS_version();
結(jié)語
至此,您已成功在Rocky Linux 9上安裝和配置了PostgreSQL和PostGIS。這為您處理空間數(shù)據(jù)和進(jìn)行地理信息系統(tǒng)(GIS)分析提供了強(qiáng)大的基礎(chǔ)。記得定期更新系統(tǒng)和數(shù)據(jù)庫以確保安全性和性能。