PostgreSql安装指导
# 一、基础功能安装
### 1、下载所需要的数据库版本
https://yum.postgresql.org/repopackages.php
### 2、安装(13版本)
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql13-server postgresql13-contrib
### 3、初始化
/usr/pgsql-13/bin/postgresql-13-setup initdb
### 4、设置开机启动
systemctl enable postgresql-13
#启动数据库
systemctl start postgresql-13
注:修改数据文件存放路径修改
vi /usr/lib/systemd/system/postgresql-13.service
##修改
Environment=PGDATA=/data/pgdata/ (为实际存放目录)
### 5、配置远程访问
vi /var/lib/pgsql/13/data/postgresql.conf
##### 打开防火墙端口 5433
[root@localhost ~]# firewall-cmd --zone=public --add-port=5432/tcp --permanent
[root@localhost ~]# systemctl restart firewalld.service
### 6、设置访问账号权限
1. 输入su - postgres并回车,切换至用户。
1. 输入psql -U postgres并回车,登录数据库。
1. 输入ALTER USER postgres with encrypted password 'Tongyan8888!';(不要漏了“;”)并回车,设置默认用户postgre的密码,此处密码为Tongyan8888!,可自行修改。
### 7、添加访问方式,使用密码访问
host all all 0.0.0.0/0 md5 允许使用账号密码方式访问
# 二、安装postgis扩展模块
### 1、安装epel
yum -y install epel-release
### 2、安装postgis扩展包
yum install postgis3_13
### 添加扩展
#登录
[root@localhost ~]# su - postgres
-bash-4.2$ psql -U postgres
###### 执行扩展库sql命令
**注意:在哪个数据库下执行,就会扩展到相应的数据库里**
-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- Enable PostGIS Advanced 3D
-- and other geoprocessing algorithms
-- sfcgal not available with all distributions
CREATE EXTENSION postgis_sfcgal;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- rule based standardizer
CREATE EXTENSION address_standardizer;
-- example rule data set
CREATE EXTENSION address_standardizer_data_us;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;
```
#### 检查是否成功
SELECT postgis_full_version();
-- 返回查询结果
"POSTGIS=""3.1.2 cbe925d"" [EXTENSION] PGSQL=""130"" GEOS=""3.9.1-CAPI-1.14.2"" SFCGAL=""1.3.1"" PROJ=""7.2.1"" LIBXML=""2.9.1"" LIBJSON=""0.11"" TOPOLOGY"
# 三、安装Timescaledb 扩展
### 1、yum安装
sudo tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/\$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOL
#更新
sudo yum update -y
# disable builtin postgres packages on CentOs 8
if command -v dnf; then sudo dnf -qy module disable postgresql; fi
#安装
sudo yum install -y timescaledb-2-postgresql-13
### 2、配置
#postgresql.conf
shared_preload_libraries = 'timescaledb'
### 3、添加扩展
create extension timescaledb;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义