Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 在github操作中使用psql_Postgresql_Github_Psql_Github Actions - Fatal编程技术网

Postgresql 在github操作中使用psql

Postgresql 在github操作中使用psql,postgresql,github,psql,github-actions,Postgresql,Github,Psql,Github Actions,我试图在github操作中使用psql,但发现以下错误: psql: error: could not connect to server: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.543

我试图在github操作中使用psql,但发现以下错误:

psql: error: could not connect to server: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
其中,我的github操作yml文件如下所示(run_all_tests.sh文件只调用尝试运行命令psql的子进程)有人知道为什么会发生这种情况吗?

name: Python application

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest

    # Service containers to run with `container-job`
    services:
      # Label used to access the service container
      postgres:
        # Docker Hub image
        image: postgres
        # Provide the password for postgres
        env:
          POSTGRES_PASSWORD: postgres
        # Set health checks to wait until postgres has started
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - name: Copy the code
        uses: actions/checkout@v2
      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - name: Install dependencies
        run: |
          python3 setup.py install
      - name: Test with unittest
        run: |
          cd backend/py
          source run_all_tests.sh
        env:
          # The hostname used to communicate with the PostgreSQL service container
          POSTGRES_HOST: postgres
          # The default PostgreSQL port
          POSTGRES_PORT: 5432

因为我有同样的问题,我尝试了一种对我有效的不同方法

首先,我在容器中运行作业:

作业:
建造:
容器:gradle:jdk11
这不会使
psql
命令可用,因此您需要添加一个运行步骤来安装它。根据您选择的Docker映像,特定的安装方法可能会有所不同:

作业:
建造:
容器:gradle:jdk11
...
步骤:
-运行:|
更新源
apt get安装--是--否安装建议postgresql客户端
请注意,上面或下面可能有不同的步骤

现在是执行您需要的所有这些SQL的时候了。这里最重要的一点:数据库主机名是
postgres
,它是服务容器的id


工作:
建造:
容器:gradle:jdk11
...
步骤:
-运行:|
更新源
apt get安装--是--否安装建议postgresql客户端
-运行:|
psql-h postgres-U postgres-c“创建数据库…”
psql-h postgres-U postgres-c“创建角色…”

尝试将
POSTGRES\u主机
更改为
localhost
,因为您打开了POSTGRES端口,它应该可以工作。至于为什么
postgres
hostname不起作用,尽管在文档中-我不确定。我看到同样的错误,即使我不幸地将postgres\u主机设置为localhost-还有其他想法吗?我不知道在
testwithunittest
步骤中,您在哪里指定了连接到postgres服务器的密码。您是否假设
postgres
是用户名和密码?您正在运行测试的数据库是什么?