Come installare TimescaleDB su Ubuntu 22.04|20.04|18.04
Questo tutorial ti guiderà attraverso i passaggi per installare il database delle serie temporali TimescaleDB su Ubuntu 22.04|
Caratteristiche di TimescaleDB
Di seguito sono riportati i vantaggi derivanti dall'utilizzo di TimescaleDB
- Facile da usare: dispone di un'interfaccia SQL completa per tutti gli SQL supportati nativamente da PostgreSQL (inclusi indici secondari, aggregati non basati sul tempo, sottoquery, JOIN, funzioni finestra). supporta inoltre funzioni e ottimizzazioni API e un solido supporto per i criteri di conservazione dei dati.
- Affidabilità: TimescaleDB è stato progettato da PostgreSQL per la piena compatibilità con l'ecosistema PostgreSQL esistente e le sue fantastiche funzionalità come la replica in streaming e i backup.
- Scalabilità: dispone di una partizione temporale/spaziale trasparente sia per l'aumento (nodo singolo) che per l'aumento (di prossima uscita). Elevata velocità di scrittura dei dati (inclusi commit in batch, indici in memoria, supporto transazionale, supporto per il backfill dei dati). TimescaleDB ti offre inoltre operazioni parallele su blocchi e server.
Come installare TimescaleDB su Ubuntu 22.04|20.04|18.04
Segui i passaggi forniti qui per rendere operativo TimescaleDB sul tuo Ubuntu 22.04|
Passaggio 1: aggiorna il tuo sistema
Assicurati che il tuo sistema esegua i pacchetti più recenti.
sudo apt update && sudo apt -y full-upgrade
Riavviare il sistema per assicurarsi che tutto funzioni correttamente
[ -f /var/run/reboot-required ] && sudo reboot -f
Passaggio 2: installa PostgreSQL
TimescaleDB richiede PostgreSQL 9.6 o versione successiva+. Dobbiamo installarlo prima di poter configurare TimescaleDB.
Importa la chiave di firma del repository:
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
Aggiungi il repository apt PostgreSQL:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Aggiorna gli elenchi dei pacchetti e installa il pacchetto postgresql
:
sudo apt update
sudo apt install postgresql-12
Il file di configurazione per il server database PostgreSQL è /etc/postgresql/*/main/postgresql.conf
Imposta la password dell'utente amministratore di PostgreSQL
sudo su - postgres
psql -c "alter user postgres with password 'StrongDBPassw0rd'"
exit
Passaggio 3: installa TimescaleDB su Ubuntu 22.04|20.04|18.04
L'ultimo passaggio è l'installazione di TimescaleDB sul server.
Ubuntu 20.04|18.04
Aggiungi PPA al sistema utilizzando i comandi seguenti:
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
Aggiorna l'indice del pacchetto APT per confermare se il repository è stato effettivamente aggiunto:
$ 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
Quindi installa TimescaleDB per PostgreSQL 12, se hai PG 11, sostituisci di conseguenza:
sudo apt install timescaledb-postgresql-12
Accetta le richieste di installazione che ti vengono mostrate:
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
Ora aggiorna le impostazioni di configurazione PostgreSQL per TimescaleDB:
sudo timescaledb-tune --quiet --yes
Output dell'esecuzione del comando:
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
Riavvia il servizio PostgreSQL dopo aver apportato la modifica:
sudo systemctl restart postgresql
IN CASO NO, è necessario aggiornare la modifica postgresql.conf
per caricare manualmente le librerie TimescaleDB necessarie:
sudo vim /etc/postgresql/12/main/postgresql.conf
Trova la riga sottostante e modifica il valore come mostrato (decommenta se necessario):
shared_preload_libraries = 'timescaledb'
Vedi lo screenshot qui sotto
Riavvia il servizio postgresql
dopo aver salvato le modifiche:
sudo systemctl restart [email
Conferma se il servizio postgresql è stato riavviato correttamente senza problemi:
$ 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.
Passaggio 4: testa l'installazione di TimescaleDB su Ubuntu 22.04|20.04|18.04
Ora possiamo testare la nostra installazione di TimescaleDB creando un nuovo database vuoto o convertendo un database PostgreSQL esistente per utilizzare TimescaleDB.
Connettiti a PostgreSQL utilizzando un superutente denominato postgres
$ 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
Aggiungi TimescaleDB:
Connettersi al database
postgres=# \c test_db
You are now connected to database "test_db" as user "postgres".
Estendi il database con 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
Per oggi è tutto!. Connettiti al database appena creato:
psql -U postgres -h localhost -d test_db
Riferimento: documentazione ufficiale di TimescaleDB