So, yeah, the difference between PostgreSQL and MySQL is that the former is the more ‘real’ database with a better general standing in the areas of data integrity and transaction processing. This probably does not account for much in the Home Assistant use case with its very simplistic database structure. In fact, it may well be that MySQL has better performance, precisely because it may be missing some safeguards.
But: The one thing I absolutely love about PostgreSQL and make use of here is its peer authentication method: Authentication as a postgres user is successful if it matches the unix user name. You saw that I created a hass postgres user which owns the database, but never did anything else with it. That’s because the home assistant process runs as the unix user hass and can therefore simply connect to postgres as the postgres user hass. No passwords required. No mucking around. And more secure.
@henryk - Thanks very much for taking the time to reply; learning is why I participate so actively here and in your two paragraphs I learned an awful lot. Thanks for sharing with me and with others!
Is it possible to have the recorder component to write to an installation of PG on a different server? From the syntax it seems like it might work, but will I need to have a local install of PG so HA can access the required libraries?
I don’t see a problem with this as long as there is support on the HA machine for the client.
In other words, I don’t think HA cares whether the server is local or not as long as the req client libraries are installed and HA can access them (if you’re running a venv, then the libs would have to be installed with the venv active).
I have been having trouble with handling my large db (over 500 Mb in one day) using SQLite. So I tried your method, and everything seemed ok at beginning (after rebooting my Pi), but then I ordered HA to restart itself and then it never loaded again. This is the error log;
Any suggestion on why I am having this problem?
Also, even when it was working (right after rebooting the Pi) the history tab doesn’t load anything!
I have to mention this as well. once I was trying to install “psycopg2”, the pi terminal looked like as if it ran into some sort of error;
One last thing, in my RPi (with the latest Raspbian), I had to change
I will give it a go this weekend ! Thank you so much for sharing your experience @mouseandcat !
My new problem is that even though I use the SQLite in Recorder of my configuration.yaml , > the purge_days function doesn’t seem to be doing anything ! I monitored my *.db file, and it is growing in size continuously without purging any old data …
Before you install postgresql, run “sudo apt update” and “sudo apt upgrade”. While my system was fairly up to date, I needed to do this before postresql would install.
db_url: postgres://@/hass should be db_url: postgres://@/homeassistant
It looked like everything worked except that my logbook and history in my UI are empty and don’t populate now. I don’t see any errors in the logs. I logged into the psql database as shown above and I can see that it was growing while i was running home assistant as well:
I am logged in as “hass” for the user, but I haven’t setup a virtual environment as the guide shows. But I don’t see why that would make any difference since I just installed psycopg2 in the normal environment…
I just did this using a stock Hassbian install, on a Raspi 2 Model B. HOLY COW!!!
Two things:
The UI is A LOT faster than it was when using the SQLite database.
The OS, HASS Server, and Postgres all combined use only about 70MB of RAM!!
My next step (after doing a dd of my SD card) is to create a RAM disk for /var. This will entail writing systemd modules to tar up /var on shutdown, and un-tar /var on startup. The purpose of this is to not burn up SD cards.