一、安裝psql的yum源
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
二、安裝psql v12 server
sudo yum install -y postgresql12-server
三、初始化資料庫
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
四、修改配置檔案允許遠端連線(在檔案末尾新增)
vim /var/lib/pgsql/11/data/postgresql.conf
listen_addresses = '*'
vim /var/lib/pgsql/11/data/pg_hba.conf
host all all 0.0.0.0/0 trust
五、開啟自動啟動,並啟動psql
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12
六、修改資料庫賬戶postgres預設密碼
su - postgres #進去資料庫
psql #
alter user postgres password '123456' #修改密碼
七、安裝TimeScaleDB外掛
製作 timescaledb.repo 檔案
cat > /etc/yum.repos.d/timescale_timescaledb.repo <<EOL # 方式三
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/7/\$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
更新源,有時可以省略這一步
yum update -y
安裝 timescaledb-postgresql-12
yum install -y timescaledb-2-postgresql-12 #版本為2
配置 postgresql.conf 檔案,使用 postgres 啟動時載入 'timescaledb'
vim /var/lib/pgsql/12/data/postgresql.conf
shared_preload_libraries = 'timescaledb' # 不區分大小寫,也可以寫timescaleDB。
重啟資料庫服務
systemctl restart postgresql-12.service
安裝檢驗
su - postgres # 切換到 postgres 使用者。
-bash-4.2$ psql # 進入到 postgres 的命令列,即命令視窗。
postgres=# CREATE DATABASE timeseries; # 建立資料庫 timeseries
postgres=# \l # 檢視資料庫
postgres=# \c timeseries # 進入建立的資料庫 timeseries
timeseries=# create extension timescaledb; # 方式一,新增 TimescaleDB 外掛
timeseries=# CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; # 方式二,使用 TimescaleDB 擴充套件資料庫
檢視 TimescaleDB 版本
timeseries=# \dx;
timeseries=# SELECT default_version, installed_version FROM pg_available_extensions WHERE name = 'timescaledb';
問題彙總:
一、centos 錯誤: 擴充套件 "timescaledb" 沒有安裝指令碼,也沒有版本"2.3.1"的更新路徑
timeseries版本錯誤 安裝timeseries更改為2.1
yum install -y timescaledb-2-postgresql-12
二、警告:psql 版本9.2, 伺服器版本12.0
備份之前的psql檔案
mv /usr/bin/psql /usr/bin/psql.bak
重新指向12.0版本的安裝路徑下
ln -s /usr/pgsql-12/bin/psql /usr/bin/psql
三、your-timescale-extended-database-name
timescaledb版本錯誤,依照第一點修改
四、shared_preload_libraries = 'timescaledb'寫入配置檔案內報錯 ,先執行以下然後再寫入
timescaledb-tune --pg-config=/usr/pgsql-11/bin/pg_config