如何在 Ubuntu 22.04|20.04|18.04 上安装 TimescaleDB如何在 Ubuntu 22.04|20.04|18.04 上安装 TimescaleDB如何在 Ubuntu 22.04|20.04|18.04 上安装 TimescaleDB如何在 Ubuntu 22.04|20.04|18.04 上安装 TimescaleDB
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

如何在 Ubuntu 22.04|20.04|18.04 上安装 TimescaleDB

发表 admin at 2025年2月28日
类别
  • 未分类
标签

本教程将带您完成在 Ubuntu 22.04 上安装 TimescaleDB 时序数据库的步骤|

TimescaleDB的特点

以下是使用 TimescaleDB 的好处

  • 易于使用:拥有完整的 SQL 接口,适用于 PostgreSQL 原生支持的所有 SQL(包括二级索引、非基于时间的聚合、子查询、JOIN、窗口函数)。它还支持 API 功能和优化,以及对数据保留策略的强大支持。
  • 可靠性:TimescaleDB 由 PostgreSQL 设计而成,与现有的 PostgreSQL 生态系统及其流式复制和备份等炫酷功能完全兼容。
  • 可扩展性:它具有透明的时间/空间分区,可用于纵向扩展(单节点)和横向扩展(即将推出)。高数据写入速率(包括批量提交、内存索引、事务支持、数据回填支持)。 TimescaleDB 还为您提供跨块和服务器的并行操作。

如何在 Ubuntu 22.04|20.04|18.04 上安装 TimescaleDB

按照此处提供的步骤在 Ubuntu 22.04 上启动并运行 TimescaleDB |

第 1 步:更新您的系统

确保您的系统正在运行最新的软件包。

sudo apt update && sudo apt -y full-upgrade

重新启动系统以确保一切正常

[ -f /var/run/reboot-required ] && sudo reboot -f

第2步:安装PostgreSQL

TimescaleDB 需要 PostgreSQL 9.6 或更高版本。我们需要先安装它,然后才能设置 TimescaleDB。

导入存储库签名密钥:

curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg

添加 PostgreSQL apt 存储库:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

更新软件包列表并安装 postgresql 软件包:

sudo apt update
sudo apt install postgresql-12

PostgreSQL 数据库服务器的配置文件为 /etc/postgresql/*/main/postgresql.conf

设置 PostgreSQL 管理员用户的密码

sudo su - postgres
psql -c "alter user postgres with password 'StrongDBPassw0rd'"
exit

步骤3:在Ubuntu 22.04|20.04|18.04上安装TimescaleDB

最后一步是在服务器上安装 TimescaleDB。

Ubuntu 20.04|18.04

使用以下命令将 PPA 添加到系统:

sudo add-apt-repository ppa:timescale/timescaledb-ppa

Ubuntu 22.04:

## Import GPG key ###
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 55EE6BF7698E3D58D72C0DD9ECB3980CC59E610B

## Add repo ###
sudo tee /etc/apt/sources.list.d/timescale-ubuntu-timescaledb-ppa-jammy.list<<EOF
deb https://ppa.launchpadcontent.net/timescale/timescaledb-ppa/ubuntu/ focal main
EOF

更新 APT 包索引以确认存储库是否确实已添加:

$ sudo apt update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://apt.postgresql.org/pub/repos/apt focal-pgdg InRelease
Hit:3 http://ppa.launchpad.net/timescale/timescaledb-ppa/ubuntu focal InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:5 http://nova.clouds.archive.ubuntu.com/ubuntu focal InRelease
Hit:6 http://nova.clouds.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:7 http://nova.clouds.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done

然后安装 TimescaleDB for PostgreSQL 12,如果您有 PG 11,请相应替换:

sudo apt install timescaledb-postgresql-12

接受向您显示的安装提示:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  postgresql-12 postgresql-client-12 timescaledb-loader-postgresql-12 timescaledb-tools
Suggested packages:
  postgresql-doc-12 libpq-dev
The following NEW packages will be installed:
  postgresql-12 postgresql-client-12 timescaledb-loader-postgresql-12 timescaledb-postgresql-12 timescaledb-tools
0 upgraded, 5 newly installed, 0 to remove and 60 not upgraded.
Need to get 19.8 MB of archives.
After this operation, 85.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

现在更新 TimescaleDB 的 PostgreSQL 配置设置:

sudo timescaledb-tune --quiet --yes

命令执行输出:

sing postgresql.conf at this path:
/etc/postgresql/12/main/postgresql.conf

Writing backup to:
/tmp/timescaledb_tune.backup202110271433

Recommendations based on 1.94 GB of available memory and 2 CPUs for PostgreSQL 12
shared_preload_libraries = 'timescaledb'	# (change requires restart)
shared_buffers = 508786kB
effective_cache_size = 1490MB
maintenance_work_mem = 254393kB
work_mem = 12719kB
timescaledb.max_background_workers = 8
max_worker_processes = 13
max_parallel_workers_per_gather = 1
max_parallel_workers = 2
wal_buffers = 15262kB
min_wal_size = 512MB
default_statistics_target = 500
random_page_cost = 1.1
checkpoint_completion_target = 0.9
max_connections = 20
max_locks_per_transaction = 64
autovacuum_max_workers = 10
autovacuum_naptime = 10
effective_io_concurrency = 200
timescaledb.last_tuned = '2021-10-27T14:33:21Z'
timescaledb.last_tuned_version = '0.11.0'
Saving changes to: /etc/postgresql/12/main/postgresql.conf

更改后重新启动 PostgreSQL 服务:

sudo systemctl restart postgresql 

如果没有,您需要更新编辑 postgresql.conf 以手动加载必要的 TimescaleDB 库:

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

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

shared_preload_libraries = 'timescaledb'

请参阅下面的屏幕截图

保存更改后重新启动 postgresql 服务:

sudo systemctl restart [email  

确认 postgresql 服务是否已成功重新启动且没有任何问题:

$ systemctl status [email 
● [email  - PostgreSQL Cluster 12-main
     Loaded: loaded (/lib/systemd/system/[email ; enabled-runtime; vendor preset: enabled)
     Active: active (running) since Wed 2021-10-27 14:35:58 UTC; 1min 5s ago
    Process: 7461 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 12-main start (code=exited, status=0/SUCCESS)
   Main PID: 7483 (postgres)
      Tasks: 8 (limit: 2343)
     Memory: 36.2M
     CGroup: /system.slice/system-postgresql.slice/[email 
             ├─7483 /usr/lib/postgresql/12/bin/postgres -D /var/lib/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf
             ├─7485 postgres: 12/main: checkpointer
             ├─7486 postgres: 12/main: background writer
             ├─7487 postgres: 12/main: walwriter
             ├─7488 postgres: 12/main: autovacuum launcher
             ├─7489 postgres: 12/main: stats collector
             ├─7490 postgres: 12/main: TimescaleDB Background Worker Launcher
             └─7491 postgres: 12/main: logical replication launcher

Oct 27 14:35:55 frank-ubuntu-01 systemd[1]: [email : Succeeded.
Oct 27 14:35:55 frank-ubuntu-01 systemd[1]: Stopped PostgreSQL Cluster 12-main.
Oct 27 14:35:55 frank-ubuntu-01 systemd[1]: Starting PostgreSQL Cluster 12-main...
Oct 27 14:35:58 frank-ubuntu-01 systemd[1]: Started PostgreSQL Cluster 12-main.

步骤 4:在 Ubuntu 22.04|20.04|18.04 上测试 TimescaleDB 安装

现在,我们可以通过创建新的空数据库或转换现有 PostgreSQL 数据库以使用 TimescaleDB 来测试 TImescaleDB 安装。

使用名为 postgres 的超级用户连接到 PostgreSQL

$ sudo su - postgres
$ psql
psql (12.11 (Ubuntu 12.11-1.pgdg22.04+1))
Type "help" for help.
postgres=# CREATE database test_db;
CREATE DATABASE

添加TimescaleDB:

连接到数据库

postgres=# \c test_db
You are now connected to database "test_db" as user "postgres".

使用 TimescaleDB 扩展数据库

test_db=# CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
WARNING:
WELCOME TO
 _____ _                               _     ____________
|_   _(_)                             | |    |  _  \ ___ \
  | |  _ _ __ ___   ___  ___  ___ __ _| | ___| | | | |_/ /
  | | | |  _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
  | | | | | | | | |  __/\__ \ (_| (_| | |  __/ |/ /| |_/ /
  |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
               Running version 1.7.5
For more information on TimescaleDB, please visit the following links:

 1. Getting started: https://docs.timescale.com/getting-started
 2. API reference documentation: https://docs.timescale.com/api
 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture

Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.

CREATE EXTENSION

今天就这样!连接到您新创建的数据库:

psql -U postgres -h localhost -d test_db

参考:TimescaleDB 官方文档

©2015-2025 Norria support@norria.com