ubuntu22.4.1 部署Postgres12 、PostGIS、TimescaleDB

发布时间 2023-04-24 19:55:10作者: binbinx

参考文章
https://www.postgresql.org/download/linux/ubuntu/
一、postgres数据库安装
# Create the file repository configuration:
1.sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import the repository signing key:
2.wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Update the package lists:
3.sudo apt-get update
# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
4.sudo apt-get -y install postgresql-12
5.
进入数据库后
sudo -u postgres psql 更改用户密码 postgres=# ALTER USER postgres WITH PASSWORD ‘hyuhsf@er’;
6.修改配置文件
修改postgresql.conf listen_addresses='*'
修改pg_hba.conf 添加 host all all 0.0.0.0/0 trust
重启服务 sudo service postgresql restart

通过 postgres 账户执行 psql 命令:
$ sudo -u postgres psql
查询当前数据库存储路径:
postgres=# SHOW DATA_DIRECTORY;

停止 PostgreSQL 数据库服务
sudo systemctl stop postgresql


查询当前 PostgreSQL 服务状态
sudo systemctl status postgresql

修改 PostgreSQL 配置文件
$ sudo vim /etc/postgresql/12/main/postgresql.conf

data_directory = '/var/lib/postgresql/12/main'
将其注释掉,增加指向的存储位置(也可以直接修改),具体的新存储位置请根据实际情况修改
data_directory = '/data/postgresql/12/main'
保存退出

将原/旧数据库存储目录 迁移 到新的存储位置
sudo rsync -av /var/lib/postgresql /data/

归档数据库:
$ sudo mv /var/lib/postgresql/12/main /var/lib/postgresql/12/main.bak

启动服务
sudo service postgresql start

核验 DATA_DIRECTORY
sudo -u postgres psql
postgres=# SHOW DATA_DIRECTORY;
. 删除数据库归档
sudo rm -rf /var/lib/postgresql/12/main.bak
重启 PostgreSQL 服务
$ sudo systemctl restart postgresql
$ sudo systemctl status postgresql



二、PostGIS安装
sudo apt-cache search postgis
sudo apt-get install postgresql-12-postgis-3
CREATE EXTENSION postgis;
验证
SELECT ST_SetSRID(ST_Point(-87.71,43.741),4326),ST_GeomFromText('POINT(-87.71 43.741)',4326)



三、TimescaleDB安装
https://docs.timescale.com/install/latest/self-hosted/installation-debian/

添加下面PPA:
1.echo "deb https://packagecloud.io/timescale/timescaledb/ubuntu/ $(lsb_release -c -s) main" | sudo tee /etc/apt/sources.list.d/timescaledb.list

2.wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo apt-key add -

3.wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg

4.sudo apt update

5.sudo apt install timescaledb-postgresql-12

编辑postgresql.conf以加载必要的TImescaleDB库。

sudo vim /etc/postgresql/12/main/postgresql.conf

找到下面的行并更改显示的值(如果需要,取消注释):

shared_preload_libraries = 'timescaledb'

保存更改后重新启动postgresql服务:
sudo systemctl restart postgresql
使用TimescaleDB扩展数据库
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

————————————————
版权声明:本文为CSDN博主「L.傲骨雄风」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xlp789/article/details/127894089