From d717eb078528f55a0fd8a2f7fb95602ae30b71cf Mon Sep 17 00:00:00 2001 From: tteckster Date: Fri, 13 May 2022 15:23:06 -0400 Subject: [PATCH] Update README.md --- README.md | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/README.md b/README.md index b289aecb..5f4233f7 100644 --- a/README.md +++ b/README.md @@ -640,6 +640,112 @@ ________________________________________________________________________________ +
+ 🔸PostgreSQL LXC + +

+ +

PostgreSQL LXC

+ +To create a new Proxmox PostgreSQL LXC, run the following in the Proxmox Shell. + +```yaml +bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/ct/postgresql-v3.sh)" +``` + +

⚡ Default Settings: 1GB RAM - 4GB Storage - 1vCPU ⚡

+ +To enable PostgreSQL to listen to remote connections, you need to edit your defaults file. To do this, open the console in your PostgreSQL LXC +```yaml +nano /etc/postgresql/13/main/postgresql.conf +``` +Un-comment `listen_addresses` and replace localhost with * sign to allow all Ip-address to connect to the Database server. +``` +listen_addresses = '*' # what IP address(es) to listen on; +``` +Save and exit the editor with "Ctrl+O", "Enter" and "Ctrl+X". + +```yaml +nano /etc/postgresql/13/main/pg_hba.conf +``` +Change values to match as shown below +``` +# Database administrative login by Unix domain socket +local all postgres md5 + +# TYPE DATABASE USER ADDRESS METHOD + +# "local" is for Unix domain socket connections only +local all all md5 +# IPv4 local connections: +host all all 0.0.0.0/0 md5 +# IPv6 local connections: +host all all ::0/0 md5 +# Allow replication connections from localhost, by a user with the +# replication privilege. +local replication all peer +host replication all 127.0.0.1/32 md5 +host replication all ::1/128 md5 +``` +Save and exit the editor with "Ctrl+O", "Enter" and "Ctrl+X". + +Restart the Database server to apply the changes: +``` +sudo systemctl restart postgresql +``` + +To make sure our PostgreSQL is secured with a strong password, set a password for its system user and then change the default database admin user account + +Change user password +```yaml +passwd postgres +``` +Login using Postgres system account + +``` +su - postgres +``` +Now, change the Admin database password +``` +psql -c "ALTER USER postgres WITH PASSWORD 'your-password';" +``` +Create a new user. +```yaml +psql +``` +```yaml +CREATE USER admin WITH PASSWORD 'your-password'; +``` +Create a new database: +```yaml +CREATE DATABASE homeassistant; +``` +Grant all rights or privileges on created database to the user +```yaml +GRANT ALL ON DATABASE homeassistant TO admin; +``` +To check that the database has been created +```yaml +\l +``` +Change the recorder: `db_url:` in your HA configuration.yaml + +Example: `db_url: postgresql://admin:your-password@192.168.100.20:5432/homeassistant?client_encoding=utf8` + +⚙️ **To Update PostgreSQL** + +Run in the LXC console +```yaml +apt update && apt upgrade -y +``` +⚙️ [**Adminer**](https://raw.githubusercontent.com/tteck/Proxmox/main/misc/images/adminer.png) (formerly phpMinAdmin) is a full-featured database management tool + + `http://your-PostgreSQL-lxc-ip/adminer/` + +____________________________________________________________________________________________ + +
+
Zigbee2MQTT LXC