systemctl start postgresql-14
systemctl status postgresql-14
✨3.4 配置参数
cat >> /var/lib/pgsql/14/data/postgresql.conf <<"EOF"
listen\_addresses = '\*'
port=5432
logging\_collector = on
log\_directory = 'pg\_log'
log\_filename = 'postgresql-%a.log'
log\_truncate\_on\_rotation = on
EOF
cat << EOF > /var/lib/pgsql/14/data/pg\_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
host replication all 0.0.0.0/0 md5
local replication all trust
EOF
✨3.5 重启
systemctl restart postgresql-14
ALTER USER postgres WITH PASSWORD ‘123456’;
psql -U postgres -h 192.168.3.10 -d postgres -p 5432
📣 4.TimescaleDB部署
✨ 4.1 repository
tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
[timescale\_timescaledb]
name=timescale\_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/\$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
✨ 4.2 yum在线安装
1.Update your local repository list:
yum update --skip-broken --nobest
2.Install TimescaleDB:
yum install timescaledb-2-postgresql-14
在Red Hat Enterprise Linux 8上安装时,需要使用:
sudo dnf module disable postgresql
命令禁用系统中内置的PostgreSQL模块。
✨ 4.3 插件配置
修改postgresql config文件,使timescaledb这个插件能正常工作,通过调优脚本来配置数据库
[root@rhel8 ~]# find / -name pg_config
/usr/pgsql-14/bin/pg_config
sudo timescaledb-tune --pg-config=/usr/pgsql-14/bin/pg_config
📣 5.TimescaleDB使用
✨ 5.1 登陆PG
[root@rhel8 ~]# su - postgres
[postgres@rhel8 ~]$
[postgres@rhel8 ~]$ psql
psql (14.10)
Type "help" for help.
postgres=# create database jemdb;
CREATE DATABASE
postgres=# \c jemdb
You are now connected to database "jemdb" as user "postgres".
✨ 5.2 创建插件
1.创建插件
CREATE EXTENSION IF NOT EXISTS timescaledb;
2.删除插件
DROP EXTENSION IF EXISTS timescaledb;
jemdb=# \dx
List of installed extensions
Name | Version | Schema | Description
-------------+---------+------------+--------------------------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
timescaledb | 2.14.2 | public | Enables scalable inserts and complex queries for time-series data (Apache 2 Edition)
(2 rows)
✨ 5.3 使用超表
1、创建普通测试表
CREATE TABLE conditions (
time TIMESTAMPTZ NOT NULL,
location TEXT NOT NULL,
temperature DOUBLE PRECISION NULL,
humidity DOUBLE PRECISION NULL
);
2、基于time分区将上一步创建的普通表转换为超表
jemdb=# SELECT create\_hypertable('conditions', 'time');
create_hypertable
-------------------------
(1,public,conditions,t)
(1 row)
3、插入数据并查询
jemdb=# INSERT INTO conditions(time, location, temperature, humidity)
SELECT now(), to_char(i, 'FM0000'), random()*i, random()*i FROM generate_series(1,10000) i;
4.针对过去3小时的数据,每15分钟采集度量一次,按照时间和温度降序排序
SELECT time_bucket('15 minutes', time) AS fifteen_min,
location, COUNT(*),
MAX(temperature) AS max_temp,
MAX(humidity) AS max_hum
FROM conditions
WHERE time > NOW() - interval '3 hours'
GROUP BY fifteen_min, location
ORDER BY fifteen_min DESC, max_temp DESC;
5.更改现有超表上的块间隔长度
SELECT set_chunk_time_interval('conditions', INTERVAL '24 hours');
SELECT h.table_name, c.interval_length
FROM _timescaledb_catalog.dimension c
JOIN _timescaledb_catalog.hypertable h
ON h.id = c.hypertable_id;
超表(hypertable)是具有特殊功能的PostgreSQL表,可以很容易地处理时间序列数据。与它们交互就像与普通PostgreSQL表交互一样,但在幕后,超表会自动按时间将数据划分为块。在TimescaleDB中,超表与普通PostgreSQL表可以一起存在。超表用来存储时序数据,这样可以提高插入和查询的性能,而且可以访问一些有用的时间序列特性。普通PostgreSQL表用来存储其它关系型数据。
📣 6 总结
随着物联网的发展,时序数据库的需求越来越多,比如水文监控、工厂的设备监控、国家安全相关的数据监控、通讯监控、金融行业指标数据、传感器数据等。
在互联网行业中,也有着非常多的时序数据,例如用户访问网站的行为轨迹,应用程序产生的日志数据等等。
以下是时序数据库的发展史推荐给大家,一起交流学习
学习路线:
这个方向初期比较容易入门一些,掌握一些基本技术,拿起各种现成的工具就可以开黑了。不过,要想从脚本小子变成黑客大神,这个方向越往后,需要学习和掌握的东西就会越来越多以下是网络渗透需要学习的内容:
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!