A Shell Script to Install PostgreSQL 16 & Timescale 2.13 on Ubuntu 22.04
- Run the script
sudo apt update
sudo apt upgrade
sudo apt install gnupg postgresql-common apt-transport-https lsb-release wget
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo echo "deb https://packagecloud.io/timescale/timescaledb/ubuntu/ $(lsb_release -c -s) main" | sudo tee /etc/apt/sources.list.d/timescaledb.list
sudo wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg
sudo apt update
sudo apt install timescaledb-2-postgresql-16
sudo apt-get update
sudo apt-get install postgresql-client
sudo sh -c 'echo "shared_preload_libraries = '\''timescaledb'\''" >> /etc/postgresql/16/main/postgresql.conf'
sudo systemctl restart postgresql
sudo -u postgres psql
-
Set the password for the "postgres" user:
\password postgres -
Exit from PostgreSQL:
\q -
Use "psql" client to connect to PostgreSQL:
psql -U postgres -h localhost -
At the "psql" prompt, create an empty database. Our database is called "tsdb":
CREATE database tsdb; -
Connect to the database you created:
\c tsdb -
Add the TimescaleDB extension:
CREATE EXTENSION IF NOT EXISTS timescaledb;