# install postgresql
```
sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install postgresql-14
```
# install timescaledb

Add repo:
```
sudo sh -c "echo 'deb [signed-by=/usr/share/keyrings/timescale.keyring] https://packagecloud.io/timescale/timescaledb/ubuntu/ $(lsb_release -c -s) main' > /etc/apt/sources.list.d/timescaledb.list"
wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/timescale.keyring
sudo apt-get update
sudo apt install timescaledb-2-postgresql-14
```

## config timescale
Run configurator/installer
```
sudo service postgresql stop
sudo timescaledb-tune
```

## change postgres default password
```
sudo service postgresql start
sudo -u postgres psql postgres -p 5499
alter user postgres with password 'q';
```

## External access to postgres

### in config file
**/etc/postgresql/14/main/postgresql.conf**

allow external access - replace `listen_addresses = 'local'` to `listen_addresses = '*'`

change port - replace `port = '5433'` to `port = '5499'`

### in config file
**/etc/postgresql/14/main/pg_hba.conf**

Add line to allow your IP:
`host   all    all      <your ip>/32      scram-sha-256`

### check connection:
`psql -h <server ip> -p 5499 -d postgres -U postgres -W`