Gitlab ci, symfony + postgres Error Connection refused - postgresql

I have an error when I create the schema with doctine
$ php bin/console doctrine:schema:create --env=test
In AbstractPostgreSQLDriver.php line 73:
An exception occurred in driver: SQLSTATE[08006] [7] could not connect to s
erver: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
with my gitlab-ci.yml
database:
stage: building
services:
- postgres:10
variables:
POSTGRES_DB: back
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ''
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
before_script:
# Install pdo_pgsql driver
- apt-get update
- apt-get install -y libpq-dev
- docker-php-ext-install pdo_pgsql
script:
- php bin/console doctrine:schema:create --env=test
- php -d memory_limit=2048M bin/console --env=test cache:warmup --no-debug
And my gitlab-parameters.yml (who is cp on app/config/parameters.yml)
parameters:
database_host: postgres
database_port: 5432
database_name: back
database_user: postgres
database_password: ''
Other information :
when I try to create database, I have the good message from gitlab-ci
$ php bin/console doctrine:database:create --env=test
Could not create database "back" for connection named default
An exception occurred while executing 'CREATE DATABASE "back"':
SQLSTATE[42P04]: Duplicate database: 7 ERROR: database "back" already exists
Version :
php 7.2.19
smyfony 3.4
and my config_text.yml
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
profiler:
collect: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
How fix it?
EDIT :
postgres is not running :
netstat -plntu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN -

Related

Docker Postgres psql connection: FATAL: role "..." does not exist

I am using docker-compose to build a node express & Postgres application.
Problem
I cannot enter the container with psql to inspect the tables but my initial migration is logging that there was a successful migration.
--- EDIT ---
Codebase
--- END EDIT ---
Running Containers
note: the db is immediately shutting down and this might be the reason my psql is failing while the migration (which is creating a new connection) is working??
## -- LOG FROM RUNNING DB CONTAINER -- ##
2021-12-04 22:08:27.683 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-12-04 22:08:27.683 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-12-04 22:08:27.688 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-12-04 22:08:27.723 UTC [76] LOG: database system was shut down at 2021-12-04 22:08:27 UTC
2021-12-04 22:08:27.734 UTC [1] LOG: database system is ready to accept connections
✅ Successful Migration Command
docker exec reactquery_demo-backend-1 npm run migrate
❌ Failed psql Command(s)
trying to connect to db w/ docker user: psql -p 5432 -d reactquery_demo_db -U docker
trying to connect to db container w/ docker user:psql -p 5432 -d reactquery_demo-db-1 -U docker
THE ERROR:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: role "docker" does not exist
I have seen posts about this being caused by the fact that a POSTGRES_USER is not added in the docker-compose but I have that in mine (as shown below)
I have also tried:
uninstalling / reinstalling / upgrading postgresql w/ homebrew
running rm /usr/local/var/postgres/postmaster.pid and then restarting Postgres w/ homebrew
stopping the homebrew Postgres processes completely so that is does not conflict with docker Postgres??
when I do this I get the following error: psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket?
Repo Structure
Package.json
{
"name": "ReactQueryDemo",
"version": "0.0.1",
"description": "Simple Overview of React Query for Weekly Dev Meeting",
"main": "index.js",
"scripts": {
"dev": "node index.js",
"dev:watch": "nodemon index.js",
"migrate": "node db/scripts/migrate.js"
},
"dependencies": {
"express": "^4.17.1",
"knex": "^0.95.14",
"pg": "^8.7.1"
}
}
Docker Compose
version: '3.8'
services:
backend:
build: ./backend
ports:
- '8080:8080'
depends_on:
- db
db:
image: 'postgres'
ports:
- '5432:5432'
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=docker
- POSTGRES_DB=react_query_demo_db
volumes:
- data:/var/lib/postgresql/data
volumes:
data:
Dockerfile
FROM node:17
WORKDIR /backend
# copy everything from local backend dir
# into your current working directory in
# the container: /backend
COPY . .
# install dependencies in the container
# the .dockerignore does not copy the
# node_modules || Dockerfile itself
RUN npm i
CMD ["npm", "run", "dev"]
Backend Index
// server
const server = require("./api/server.js");
// port
const PORT = process.env.PORT || 8080;
// listening
server.listen(PORT, () => {
console.log(`*** \n\tServer listening on http://0.0.0.0:${PORT}\n***`)
});
Server
// import packages
const express = require('express')
// import routes
// create server
const server = express()
// configure server
server.use(express.json())
// configure routing
// base route
server.get('/', async(req,res) => {
console.log('React Query Demo Server Running')
res.json({ status: "SUCCESS", message: "React Query Demo Server Running" })
})
// exports
module.exports = server
Database Index
// imports
const knex = require('knex')
module.exports = knex({
client: 'postgres',
connection: {
host: 'db', // this is the name of the service in the docker-compose
user: 'docker',
password: 'password',
database: 'react_query_demo_db'
}
})

PostgreSQL error: FATAL: password authentication failed for user "pgadmin"

I am making a Telegram bot with a PostgreSQL database. Everything works correctly on the local computer, but when I upload the code to the server using docker-compose, the following errors appear in the console from time to time:
2021-10-10 02:08:58.865 UTC [3458] FATAL: password authentication failed for user "pgadmin"
2021-10-10 02:08:58.865 UTC [3458] DETAIL: Role "pgadmin" does not exist.
Connection matched pg_hba.conf line 94: "host all all 0.0.0.0/0 md5"
2021-10-09 16:27:22.198 UTC [2259] FATAL: password authentication failed for user "pgsql"
2021-10-09 16:27:22.198 UTC [2259] DETAIL: Role "pgsql" does not exist.
Connection matched pg_hba.conf line 94: "host all all 0.0.0.0/0 md5"
2021-10-09 16:25:16.113 UTC [2250] FATAL: password authentication failed for user "postgres"
2021-10-09 16:25:18.992 UTC [2252] DETAIL: Password does not match for user "postgres".
Connection matched pg_hba.conf line 94: "host all all 0.0.0.0/0 md5"
2021-10-09 21:06:32.169 UTC [2831] FATAL: expected password response, got message type 0
2021-10-09 21:07:39.610 UTC [2834] FATAL: unsupported frontend protocol 0.0: server supports 2.0 to 3.0
2021-10-09 21:07:39.819 UTC [2835] FATAL: unsupported frontend protocol 255.255: server supports 2.0 to 3.0
2021-10-09 21:07:40.029 UTC [2836] FATAL: no PostgreSQL user name specified in startup packet
And I don't use these users. It seems to me that someone else is trying to access the database. If so, is it possible to somehow specify the IP addresses from which traffic will be allowed? But my bot parses sites, so you need to limit the IP so that it would not affect its work. Thanks!
UPD:
As I was prompted in the comments, maybe the contents of the docker files will help
Dockerfile:
FROM python:3.9.5
WORKDIR /src
COPY requirements.txt /src
RUN pip install -r requirements.txt
COPY . /src
docker-compose.yml:
version: "3.1"
services:
steamtrader_db:
container_name: steamtrader_db
image: sameersbn/postgresql:10-2
environment:
PG_PASSWORD: $PGPASSWORD
DB_USER: $PGUSER
DB_PASS: $PGPASSWORD
DB_NAME: $DATABASE
restart: always
ports:
- 5432:5432
networks:
- steamtrader_botnet
volumes:
- ./pgdata:/var/lib/postgresql
steamtrader_bot:
container_name: steamtrader
build:
context: .
command: python bot.py
restart: always
networks:
- steamtrader_botnet
env_file:
- ".env"
volumes:
- .:/src
depends_on:
- steamtrader_db
networks:
steamtrader_botnet:
driver: bridge

Error when Adding postgresql user named odoo in remote node(docker containner) with ansible

I'm working to add postgresql user named odoo in remote node (docker container) with ansible knowing that I'm trying to follow the manual installation:
$sudo apt-get install postgresql-9.6
$sudo su postgres
$cd
$createuser -s odoo
and this is my code
- name: Instalation of postgresql-9.6 server
apt:
name: postgresql-9.6
state: latest
- name: Ensure the PostgreSQL service is running
service: name=postgresql state=started enabled=yes
- name: Create odoo user
become_user: postgres
postgresql_user:
state: present
login_user: postgres
name: odoo
password: odoo
role_attr_flags: "SUPERUSER,CREATEDB"
priv: "CONNECT/products:ALL"
after running i faced this error
PLAY [My Odoo] ***************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************
ok: [172.17.0.5]
TASK [Postgresql : Instalation of postgresql-9.6 server] *********************************************************************************************
ok: [172.17.0.5]
TASK [Postgresql : Ensure the PostgreSQL service is running] *****************************************************************************************
ok: [172.17.0.5]
TASK [Postgresql : Create odoo user] *****************************************************************************************************************
fatal: [172.17.0.5]: FAILED! => {"changed": false, "msg": "privileges require a database to be specified"}
to retry, use: --limit #/home/fedora/Desktop/ansible-test/playbook.retry
PLAY RECAP *******************************************************************************************************************************************
172.17.0.5 : ok=3 changed=0 unreachable=0 failed=1
Can you help me resolving this?
You've specified a priv option, but haven't specified a database, which should be affected by your config. In your specific case, since you just want to create a user you should omit priv: to have something like
- name: Create odoo user
become_user: postgres
postgresql_user:
state: present
login_user: postgres
name: odoo
password: odoo
role_attr_flags: "SUPERUSER,CREATEDB"

MongoDB Docker container refuses connection when auth enabled

If I set up my container without auth eg)
docker run --name some-mongo -d -p 27017:27017 mongo
I can connect to my mongoDB from a remote machine eg)
mongo [serverIP]
However, my issue is when using the --auth flag
Following the documentation:
docker run --name some-mongo -d -p 27017:27017 mongo --auth
> db.createUser({ user: 'foo', pwd: 'bar', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })
results in connections being refused:
$ mongo -u foo -p bar [serverIP]
MongoDB shell version v3.4.9
connecting to: [serverIP]
2017-12-09T14:01:41.114-0600 W NETWORK [thread1] Failed to connect to [serverIP]:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-09T14:01:41.115-0600 E QUERY [thread1] Error: couldn't connect to server [serverIP]:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
I double-checked and the port looks to be open on the server:
$ netstat -tuplen
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
...
tcp6 0 0 :::27017 :::* LISTEN 0 53238875 -
...
(Docker is running on a debian Digital Ocean droplet)
You need to specify the --authenticationDatabase flag
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
see the tutorial

Puppet fails on icinga2 using puppet-icinga2 module

I am trying to bring up a box for icinga2 using vagrant and
I am using puppet-icinga2 from https://github.com/Icinga/puppet-icinga2/tree/v0.6.2
so I have a role as shown below
class role::icinga2_server {
class { 'postgresql::server':
ip_mask_deny_postgres_user => '0.0.0.0/32',
ip_mask_allow_all_users => '0.0.0.0/0',
listen_addresses => 'localhost',
postgres_password => 'password',}
postgresql::server::db {
'icinga2_data':
user => 'icinga2',
password => 'password'
}
class { 'icinga2::server':
server_db_type => 'pgsql',
db_host => 'localhost',
db_port => '5432',
db_name => 'icinga2_data',
db_user => 'icinga2',
db_password => 'password',
}
}
So when I provision box I get postgres intall fine via puppet (using puppet-postgres module) then puppet throws errors on
==> centos7: Notice: /Stage[main]/Vagrant/Group[vagrant]/gid: gid changed '1000' to '500'
==> centos7: Debug: /Stage[main]/Vagrant/Group[vagrant]: The container Class[Vagrant] will propagate my refresh event
==> centos7: Debug: Exec[postgres_schema_load](provider=posix): Executing 'su - postgres -c 'export PGPASSWORD='\''password'\'' && psql -U icinga2 -h localhost -d icinga2_data < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql' && export PGPASSWORD='' && touch /etc/icinga2/postgres_schema_loaded.txt'
==> centos7: Debug: Executing 'su - postgres -c 'export PGPASSWORD='\''password'\'' && psql -U icinga2 -h localhost -d icinga2_data < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql' && export PGPASSWORD='' && touch /etc/icinga2/postgres_schema_loaded.txt'
==> centos7: Notice: /Stage[main]/Icinga2::Server::Install::Execs/Exec[postgres_schema_load]/returns: psql: could not connect to server: Connection refused
==> centos7: Notice: /Stage[main]/Icinga2::Server::Install::Execs/Exec[postgres_schema_load]/returns: Is the server running on host "localhost" (::1) and accepting
==> centos7: Notice: /Stage[main]/Icinga2::Server::Install::Execs/Exec[postgres_schema_load]/returns: TCP/IP connections on port 5432?
==> centos7: Notice: /Stage[main]/Icinga2::Server::Install::Execs/Exec[postgres_schema_load]/returns: could not connect to server: Connection refused
==> centos7: Notice: /Stage[main]/Icinga2::Server::Install::Execs/Exec[postgres_schema_load]/returns: Is the server running on host "localhost" (192.168.10.131) and accepting
==> centos7: Notice: /Stage[main]/Icinga2::Server::Install::Execs/Exec[postgres_schema_load]/returns: TCP/IP connections on port 5432?
==> centos7: Error: su - postgres -c 'export PGPASSWORD='\''password'\'' && psql -U icinga2 -h localhost -d icinga2_data < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql' && export PGPASSWORD='' && touch /etc/icinga2/postgres_schema_loaded.txt returned 2 instead of one of [0]
I see errors stating psql cannot connect but when I bring my vagrant box up, ssh in I see postgres installed running and listening fine. I can also connect using psql but puppet fails at creating schema on postgres as seen on debug output.
I also did login and executed same command for postgres schema load and it did work fine.
I have tried running failed command on system, logged in and executed
su - postgres -c 'export PGPASSWORD='\''password'\'' && psql -U icinga2 -h localhost -d icinga2_data < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql' && export PGPASSWORD='' && touch /etc/icinga2/postgres_schema_loaded.txt
and it did work as expected.
Why puppet is failing to load schema?