github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/doc/content/en/docs/install/postgresql.md (about) 1 --- 2 linkTitle: "Postgresql" 3 date: 2023-11-01 4 description: > 5 6 --- 7 8 # Installing PostgreSQL 15 with TimescaleDB and pgcrypto on Linux Debian 9 10 ## Introduction 11 12 In this article, we will discuss how to install PostgreSQL 15 with the TimescaleDB and pgcrypto extensions on the Linux Debian operating system. 13 14 ## Step 1: Update the Packages 15 16 Before installing PostgreSQL 15, let's ensure our system is up to date: 17 18 ```bash 19 sudo apt update 20 sudo apt upgrade 21 ``` 22 23 ## Step 2: Install PostgreSQL 15 24 25 Install PostgreSQL 15 and its necessary dependencies: 26 27 ```bash 28 sudo apt install postgresql-15 postgresql-contrib 29 ``` 30 31 ## Step 3: Install TimescaleDB 32 33 Now, let's install TimescaleDB, the extension for working with time-series data in PostgreSQL: 34 35 ```bash 36 sudo apt install timescaledb-2-postgresql-15 37 ``` 38 39 ## Step 4: Install pgcrypto 40 41 To install pgcrypto, we'll use the `psql` tool that comes with PostgreSQL: 42 43 ```bash 44 sudo -u postgres psql 45 ``` 46 47 Then execute the following SQL commands interactively: 48 49 ```sql 50 CREATE EXTENSION IF NOT EXISTS pgcrypto; 51 ``` 52 53 ## Step 5: Configuration and Usage 54 55 Now, PostgreSQL 15 with TimescaleDB and pgcrypto is installed and ready for use. You can configure the database and start working on your Smart Home project. 56 57 # Installing PostgreSQL 15 with TimescaleDB and pgcrypto in a Docker Container 58 59 ## Introduction 60 61 In this article, we will create a Docker container with PostgreSQL 15, TimescaleDB, and pgcrypto for your Smart Home project. 62 63 ## Step 1: Install Docker 64 65 If you don't have Docker installed, you can do so with the following command: 66 67 ```bash 68 sudo apt install docker.io 69 ``` 70 71 ## Step 2: Launch the PostgreSQL Container 72 73 Create and start a Docker container with PostgreSQL 15, TimescaleDB, and pgcrypto: 74 75 ```bash 76 docker run --name smart-home-db -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 -v /path/to/data:/var/lib/postgresql/data postgres:15 77 ``` 78 79 Replace `/path/to/data` with the location where you want to store PostgreSQL data. 80 81 ## Step 3: Install TimescaleDB and pgcrypto 82 83 To install TimescaleDB and pgcrypto, run the following commands within the container: 84 85 ```bash 86 docker exec -it smart-home-db psql -U postgres 87 ``` 88 89 Then execute the following SQL commands interactively: 90 91 ```sql 92 CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; 93 CREATE EXTENSION IF NOT EXISTS pgcrypto; 94 ``` 95 96 ## Step 4: Configuration and Usage 97 98 You now have a Docker container with PostgreSQL 15, TimescaleDB, and pgcrypto for your Smart Home project. You can configure the container and start using it in your application. 99 100 Both of these articles will help you install and configure PostgreSQL 15 with TimescaleDB and pgcrypto on Linux Debian and in a Docker container for your Smart Home project. Good luck!