如何在Ubuntu 18.04 LTS上安装TimescaleDB
本教程将引导我们完成在Ubuntu 18.04 LTS上安装TimescaleDB时间序列数据库的步骤。 TimescaleDB是开放源代码的时间序列数据库,已针对快速提取和复杂查询进行了优化。它讲完整的SQL,并且像传统的关系数据库一样易于使用,但是可以按以前为NoSQL数据库保留的方式进行扩展。TimescaleDB提供了NoSQL和关系数据库系统中的优点。
TimescaleDB的功能
以下是使用TimescaleDBEasy的好处:具有PostgreSQL本地支持的所有SQL的完整SQL接口(包括二级索引,基于非时间的聚合,子查询,JOIN,窗口函数)。可靠性:TimescaleDB是从PostgreSQL设计出来的,与现有PostgreSQL生态系统及其流式复制和备份等很酷的功能完全兼容。可扩展性:透明的时间/空间分区扩展(单节点)和扩展(即将发布)。高数据写入率(包括批处理提交,内存索引,事务支持,对数据回填的支持)。 TimescaleDB还为我们提供了跨块和服务器的并行操作。
如何在Ubuntu 18.04 LTS上安装TimescaleDB
请按照此处提供的步骤在Ubuntu 18.04 LTS服务器上启动并运行TimeTimescaleDB。
更新系统
确保系统正在运行最新的软件包。
sudo apt update sudo apt upgrade
重新启动系统以确保一切正常
sudo reboot
安装PostgreSQL
TimescaleDB需要PostgreSQL 9.6或者更高版本。我们需要先安装它,然后才能设置TimescaleDB。
导入存储库签名密钥:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add
添加PostgreSQL apt存储库:
cat >/etc/apt/sources.list.d/pgdg.list<<EOF deb http://apt.postgresql.org/pub/repos/apt/bionic-pgdg main EOF
更新软件包列表并安装postgresql软件包
sudo apt update sudo apt install postgresql-10
PostgreSQL 10的配置文件是/etc/postgresql/10/main/postgresql.conf
设置PostgreSQL管理员用户密码
# su - postgres $psql -c "alter user postgres with password 'StrongPassword'"
安装TimescaleDB
最后一步是在Ubuntu 18.04服务器上安装TimescaleDB。
AddPPA:
sudo add-apt-repository ppa:timescale/timescaledb-ppa sudo apt-get update
然后安装PostgreSQL 10的installTimescaleDB,如果我们有PG 9,则将10替换为9。
sudo apt install timescaledb-postgresql-10
编辑postgresql.conf以加载必要的TImescaleDB库。
sudo vim /etc/postgresql/10/main/postgresql.conf
找到下面的行并更改显示的值(如果需要,请取消注释):
shared_preload_libraries = 'timescaledb'
见下面的截图
保存更改后重启postgresql服务
sudo systemctl restart postgresql
测试TImescaleDB安装
现在,我们可以通过创建一个新的空数据库或者将现有的PostgreSQL数据库转换为使用TimescaleDB来测试TImescaleDB的安装。
使用名为postgres的超级用户连接到PostgreSQL。
# su - postgres $psql psql (10.5 (Ubuntu 10.5-1.pgdg18.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 0.12.1
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

