0%

Ubuntu/Debian安装PostgreSQL和TimescaleDB插件

导入pg源及签名

1
2
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

导入TimeScalaDB 源及签名
debian版

1
2
sh -c "echo 'deb [signed-by=/usr/share/keyrings/timescale.keyring] https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -c -s) main' > /etc/apt/sources.list.d/timescaledb.list"
wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /usr/share/keyrings/timescale.keyring

ubuntu

1
2
sh -c "echo 'deb [signed-by=/usr/share/keyrings/timescale.keyring] https://packagecloud.io/timescale/timescaledb/ubuntu/ $(lsb_release -c -s) main' > /etc/apt/sources.list.d/timescaledb.list"
wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /usr/share/keyrings/timescale.keyring

安装

1
apt install postgresql-14

启动pg

1
2
3
4
5
6
7
8
9
10
11
12
13
service postgresql start

apt install postgresql-14-postgis-3

apt install timescaledb-2-2.5.1-postgresql-14

create databases test;

\c test

create extension postgis;

create extension timescaledb;

创建timescaledb扩展时会报一下错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FATAL:  extension "timescaledb" must be preloaded
HINT: Please preload the timescaledb library via shared_preload_libraries.

This can be done by editing the config file at: /etc/postgresql/14/main/postgresql.conf
and adding 'timescaledb' to the list in the shared_preload_libraries config.
# Modify postgresql.conf:
shared_preload_libraries = 'timescaledb'

Another way to do this, if not preloading other libraries, is with the command:
echo "shared_preload_libraries = 'timescaledb'" >> /etc/postgresql/14/main/postgresql.conf

(Will require a database restart.)

If you REALLY know what you are doing and would like to load the library without preloading, you can disable this check with:
SET timescaledb.allow_install_without_preload = 'on';
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

根据提示修改配置文件

1
echo "shared_preload_libraries = 'timescaledb'" >> /etc/postgresql/14/main/postgresql.conf

重启pg

1
service postgresql restart

再次建立扩展

1
create extension timescaledb;

查看已安装好的扩展

1
\dx