Дрон с Postgres - psql: не удалось подключиться к серверу: нет такого файла или каталога - PullRequest
0 голосов
/ 27 мая 2020

Я пробовал настроить сервер дрона с помощью плагина postgres, но мне совершенно не удается заставить его работать.

Я скопировал настройку дрона по умолчанию из документации:

---
  kind: pipeline
  type: docker
  name: default

  steps:
    - name: test
      image: postgres:9-alpine
      commands:
        - sleep 5 #give the service some time to start
        - psql -U postgres -d test

  services:
    - name: database
      image: postgres:9-alpine
      environment:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: password
        POSTGRES_DB: test

Но я получаю следующую ошибку при попытке запустить его

psql: 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"?

Я предполагаю, что postgres не запускается по какой-то причине, но это трудно сказать.

Вот журнал Postgres:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found
performing post-bootstrap initialization ... No usable system locales were found.
Use the option "--debug" to see details.
ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....LOG:  database system was shut down at 2020-05-27 08:49:09 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
 done
server started
CREATE DATABASE


/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  autovacuum launcher shutting down
LOG:  shutting down
waiting for server to shut down....LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

LOG:  database system was shut down at 2020-05-27 08:49:11 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

Либо это, либо Postgres запускается нормально, но что-то убивает его, прежде чем другие процессы получат возможность общаться. Хотя я не совсем уверен.

Любая помощь будет принята с благодарностью.

1 Ответ

0 голосов
/ 27 мая 2020

Drone вызывает службы в собственном контейнере, у которых есть собственное имя хоста.
В вашем случае вы назвали свою службу database, поэтому при подключении к psql вам нужно передать имя хоста, чтобы psql установил соединение с контейнером по TCP:

psql -U postgres -d test -h database
...