linux - GitHubCI+PostgreSQL : after DB creation script is run, 数据库用户仍然无法登录

标签 linux postgresql ubuntu github-actions

我需要在 GitHubActions 工作流程中创建一个 PostgreSQL 数据库,所以我想出了以下 yml 片段:

jobs:
  build:
    name: DB
    runs-on: ubuntu-20.04

    steps:
      - uses: actions/checkout@v2

      - name: Create DB
        run: |
          sudo apt update --yes
          sudo apt install postgresql --yes
          sudo service postgresql start
          sudo -u postgres createdb somedb
          sudo -u postgres psql -d somedb -a -q -f db/createDBCommands.sql
          sudo -u postgres psql -c "CREATE USER someDbUser WITH PASSWORD 'localDevPassword';"
          sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE somedb to someDbUser;"
以上工作正常(不抛出错误)。但是,当我想在访问数据库的同一个 CI 作业中运行测试时,我收到以下错误:

28P01: password authentication failed for user "someDbUser"


代码中使用的连接字符串为:"Server=localhost;Port=5432;Database=somedb;User Id=someDbUser;Password=localDevPassword" .
我尝试在连接字符串中的密码中添加双引号(正确转义它们,但它仍然不起作用)。
是我必须从 127.0.0.1 主机内授予用户访问权限吗?如果是这样,如何使用命令而不是修改配置文件来做到这一点? (鉴于我正在使用 CI。)

最佳答案

如果您不一定需要新用户,您可以更改 super 用户密码并使用该用户进行连接。

- name: Create DB
    run: |
      sudo apt update --yes
      sudo apt install postgresql --yes
      sudo service postgresql start
      sudo -u postgres createdb somedb
      sudo -u postgres psql -d somedb -a -q -f db/createDBCommands.sql
      sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'localDevPassword';"
您可以使用以下连接字符串连接到它:
"Server=localhost;Port=5432;Database=somedb;User Id=postgres;Password=localDevPassword"

关于linux - GitHubCI+PostgreSQL : after DB creation script is run, 数据库用户仍然无法登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71106650/

相关文章:

c++ - 如何解决无法使用 using namespace std;在 C++ 中

javascript - 使用 Node js 连接到 postgres

ubuntu - 如何关闭 Sublime 2 更新通知?

docker - WSL : Can't install docker on WSL 2, Ubuntu 18.04

node.js - NPM v5.0.1 升级后找不到模块 'fs.realpath'

linux - Linux 如何在 x86-64 中支持超过 512GB 的虚拟地址范围?

从 unix 移植到 linux 的 C-Motif 代码项目

python - 使用 PhantomJS 的 Selenium 内存使用失控

python - 如何通过 django 代码识别我的 Linux 电脑上的文本文件而不检查其扩展名及其文件大小?

sql - 多列的唯一计数