Ubuntu 服务 - pq:用户“root”的密码验证失败

Ubuntu 服务 - pq:用户“root”的密码验证失败

我有一个在使用 PostgreSQL 的 Ubuntu 服务器上运行的应用程序。

我可以从项目目录运行应用程序的可执行文件(作为非 root 用户)。

我已经为此应用程序创建了一个服务 ( /etc/systemd/system/cineapi.service),以便它在重新启动时自动启动。该文件的内容是:

[Unit]
Description=cineapi

[Service]
Type=simple
Restart=on-failure
RestartSec=5s
WorkingDirectory=/home/saurabh/projects/cineapi
ExecStart=/home/saurabh/projects/cineapi/cineapi.o

[Install]
WantedBy=multi-user.target

当重新加载系统守护程序并启动服务时,如下所示:

sudo systemctl daemon-reload
sudo service cineapi start

我收到错误:

pq: password authentication failed for user "root"

我不明白为什么会发生这种情况。我没有在应用程序的任何地方使用“root”用户。它的.env文件看起来像

postgres://goapi:somepassword@MY_IPV4_ADDR:DB_PORT/cineapi

并在启动时获取。我还进行了以下更改:

  • /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用户goapi具有超级用户权限

    postgres=# \du
                               List of roles
    Role name |                         Attributes                         
    ----------+------------------------------------------------------------
    goapi     | Superuser, Create DB
    postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS
    

日志

执行二进制文件时 Postgres 记录:

2024-02-24 18:42:31.053 PST [16433] LOG:  checkpoint starting: time
2024-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/1A477A8
2024-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 日志

2024-02-24 18:37:31.024 PST [16432] LOG:  database system is ready to accept connections
2024-02-24 18:38:28.926 PST [16473] root@root FATAL:  role "root" does not exist

相关内容