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

ベストアンサー1

おすすめ記事