I have an application running on Ubuntu server that's using PostgreSQL.
I can run the application's executable (as a non-root user) from the project's directory.
I have created a service for this application (/etc/systemd/system/cineapi.service
), so that it starts automatically on reboot. The contents of this file are:
[Unit]Description=cineapi[Service]Type=simpleRestart=on-failureRestartSec=5sWorkingDirectory=/home/saurabh/projects/cineapiExecStart=/home/saurabh/projects/cineapi/cineapi.o[Install]WantedBy=multi-user.target
When a reload the system daemon and start the service like:
sudo systemctl daemon-reloadsudo service cineapi start
I'm getting an error:
pq: password authentication failed for user "root"
I dont understand why this is happening. I'm not using the "root" user anywhere in the application. It's .env
file looks like
postgres://goapi:somepassword@MY_IPV4_ADDR:DB_PORT/cineapi
and is sourced at startup. I also have the following changes in:
/etc/postgresql/16/main/postgresql.conf
password_encryption = scram-sha-256
/etc/postgresql/16/main/pg_hba.conf
host cineapi goapi MY_IPV4_ADDR scram-sha-256
DB user
goapi
has superuser privilegespostgres=# \du List of rolesRole name | Attributes ----------+------------------------------------------------------------goapi | Superuser, Create DBpostgres | Superuser, Create role, Create DB, Replication, Bypass RLS
Logs
Postgres logs when executing the binary:
2024-02-24 18:42:31.053 PST [16433] LOG: checkpoint starting: time2024-02-24 18:42:36.817 PST [16433] LOG: checkpoint complete: wrote 60 buffers (0.4%); 0 WAL file(s) added, 0 removed, 0 recycled; write=5.737 s, sync=0.014 s, total=5.765 s; sync files=54, longest=0.003 s, average=0.001 s; distance=201 kB, estimate=201 kB; lsn=0/1A477E0, redo lsn=0/1A477A82024-02-24 18:43:39.173 PST [16573] goapi@cineapi LOG: could not receive data from client: Connection reset by peer #### ---------------- I stopped the executable ----------------- ####
Postgres logs when starting the application's system service
2024-02-24 18:37:31.024 PST [16432] LOG: database system is ready to accept connections2024-02-24 18:38:28.926 PST [16473] root@root FATAL: role "root" does not exist