alexbelgium / hassio-addons

My homeassistant addons
MIT License
1.49k stars 213 forks source link

🐛 [Postgress] Connection to local host failed #1398

Closed AalianKhan closed 4 months ago

AalianKhan commented 4 months ago

Description

Hello, I want to use Immich so I installed the Postgres add-on for the database. However, when I install and run the add-on I get "error connection to the server at "localhost" (127.0.0.1), port 5432 failed: Connection refused. Is the server running on that host and accepting TCP/IP connections?"

From my understanding, the add-on is the server so I am not sure what this means or how to fix it.

Reproduction steps

1. Install 'Postgres 15'
2. Use default configuration
3. Start Add-on
4. See error
5. Addon stops

Addon Logs

Starting...
/etc/cont-init.d/00-banner.sh: executing

-----------------------------------------------------------
 Add-on: Postgres 15
 Postgres 15 with pgvecto.rs support
-----------------------------------------------------------
 Add-on version: 15.5-7
 You are running the latest version of this add-on.
 System: Home Assistant OS 12.3  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2024.5.4
 Home Assistant Supervisor: 2024.05.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums
-----------------------------------------------------------
 Provided by: https://github.com/alexbelgium/hassio-addons 
-----------------------------------------------------------
/etc/cont-init.d/00-global_var.sh: executing
POSTGRES_PASSWORD=******
Timezone set from Etc/UTC to America/Toronto
/etc/cont-init.d/01-config_yaml.sh: executing
Setting permissions for the config.yaml directory

Load environment variables from /config/config.yaml if existing
If accessing the file with filebrowser it should be mapped to /addon_configs/db21ed7f-postgres/config.yaml
---------------------------------------------------------
Wiki here on how to use : github.com/alexbelgium/hassio-addons/wiki/Add‐ons-feature-:-add-env-variables

... no config file, creating one from template. Please customize the file in /config/config.yaml before restarting.
... no env variables found, exiting
/etc/cont-init.d/01-custom_script.sh: executing
Execute /addon_configs/db21ed7f-postgres/postgres.sh if existing
Wiki here : github.com/alexbelgium/hassio-addons/wiki/Add-ons-feature-:-customisation
/etc/cont-init.d/20-folders.sh: executing
/etc/cont-init.d/99-run.sh: executing
[17:04:53] WARNING: A default config.env file was copied in /config. Please customize according to https://hub.docker.com/_/postgres and restart the add-on

[17:04:53] INFO: Starting the app
[17:04:53] INFO: Waiting for port 5432 to open...
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /config/database ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Toronto
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /config/database -l logfile start

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
waiting for server to start....2024-05-18 17:04:56.169 EDT [255] LOG:  starting PostgreSQL 15.5 (Debian 15.5-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-05-18 17:04:56.171 EDT [255] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-05-18 17:04:56.180 EDT [259] LOG:  database system was shut down at 2024-05-18 17:04:55 EDT
2024-05-18 17:04:56.206 EDT [255] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/10-vector.sh
[17:04:56] INFO: Waiting for port 5432 to open...
2024-05-18 17:09:56.278 EDT [257] LOG:  checkpoint starting: time
2024-05-18 17:10:00.315 EDT [257] LOG:  checkpoint complete: wrote 43 buffers (0.3%); 0 WAL file(s) added, 0 removed, 0 recycled; write=4.027 s, sync=0.004 s, total=4.038 s; sync files=11, longest=0.002 s, average=0.001 s; distance=252 kB, estimate=252 kB
[17:19:53] INFO: Enabling vector.rs
psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
    Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address
    Is the server running on that host and accepting TCP/IP connections?
[17:19:56] INFO: Enabling vector.rs
/docker-entrypoint-initdb.d/10-vector.sh: line 24: setup_postgres.sql: Permission denied
Error : /etc/cont-init.d/99-run.sh exiting 1

Starting the upstream container

Architecture

armv7

OS

HAos

alexbelgium commented 4 months ago

Hi, as the postsgres addon is separate, you need to use the ip of your homeassistant instead of 127.0.0.1

AalianKhan commented 4 months ago

Where do I exactly set this? image BTW the logs shown above are in the PostGress addon-on, not in immich

alexbelgium commented 4 months ago

Thanks for the clarification I had read too fast. Have you tried restarting the addon? Or looking at [17:04:53] WARNING: A default config.env file was copied in /config. Please customize according to https://hub.docker.com/_/postgres and restart the add-on?

I've reinstalled it on my system and it starts without issues ; thanks

AalianKhan commented 4 months ago

I see, yes I have restarted, reinstalled and deleted the addon folder in my system

so you don't get that warning? I don't see any config.env in my system, Is this where I should be looking? image

There is config file in the addon_config folder image

Here is the contents

image image image

I am using Nginx so I assume I have to declare my actual IP somewhere but I can't seem to find it.

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AalianKhan commented 4 months ago

Since using Nginx, translation of localhost returns 127.0.0.0. Editing listen_addresses in Postgresql.conf to my IP address solved the issue.

alexbelgium commented 4 months ago

Thanks very much for the solution! This will likely help other people who would encounter the same