I am currently struggling to connect to a locally created postgres db. The postgres server is defined inside a docker-compose.yml like this:
version: '3.9'
services:
postgres:
image: bitnami/postgresql:13.4.0
container_name: mopla-postgres
restart: always
environment:
- POSTGRES_USER=mopla
- POSTGRES_PASSWORD=develop
- POSTGRESQL_DATABASE=mopla
volumes:
- mopla-postgres:/bitnami/postgresql
- ./database_dumps:/docker-entrypoint-initdb.d
ports:
- 5432:5432
...
The container seems to start:
postgresql 09:02:41.34
postgresql 09:02:41.34 Welcome to the Bitnami postgresql container
postgresql 09:02:41.34 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql 09:02:41.34 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql 09:02:41.35
postgresql 09:02:41.36 INFO ==> ** Starting PostgreSQL setup **
postgresql 09:02:41.39 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 09:02:41.39 INFO ==> Loading custom pre-init scripts...
postgresql 09:02:41.40 INFO ==> Initializing PostgreSQL database...
postgresql 09:02:41.42 INFO ==> pg_hba.conf file not detected. Generating it...
postgresql 09:02:41.42 INFO ==> Generating local authentication configuration
postgresql 09:02:41.43 INFO ==> Deploying PostgreSQL with persisted data...
postgresql 09:02:41.43 INFO ==> Configuring replication parameters
postgresql 09:02:41.46 INFO ==> Configuring fsync
postgresql 09:02:41.49 INFO ==> Loading custom scripts...
postgresql 09:02:41.50 INFO ==> Enabling remote connections
postgresql 09:02:41.51 INFO ==> ** PostgreSQL setup finished! **
postgresql 09:02:41.55 INFO ==> ** Starting PostgreSQL **
2022-11-28 09:02:41.571 GMT [1] LOG: pgaudit extension initialized
2022-11-28 09:02:41.576 GMT [1] LOG: starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2022-11-28 09:02:41.576 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-11-28 09:02:41.576 GMT [1] LOG: listening on IPv6 address "::", port 5432
2022-11-28 09:02:41.580 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-11-28 09:02:41.586 GMT [85] LOG: database system was shut down at 2022-11-28 09:02:36 GMT
2022-11-28 09:02:41.590 GMT [1] LOG: database system is ready to accept connections
Now, when I try to connect to this database with pgadmin with the password "develop", I get an authentication error:
Here is the configuration:
Is there anything obvious I am doing wrong? Anything I can do to debug this issue further?
Alright, I figured it out.
There was a windows-service running that was also opening a postgres db on the same port (5432), so I was trying to connect to the wrong db.
TCPView helped me figuring out the issue.
Related
I am not quite sure where my problem is, I can only describe some symtoms, so please be patient with error logs/configurations.
I want to install a HA postgresql database. The easiest ways to me seems to do it via preconfigured docker images.
I am using the bitnami postgresql image for this with the following configuration in swarm mode on two separate nodes.
version: '3.8'
services:
postgresql-master:
image: 'docker.io/bitnami/postgresql:15'
ports:
- '5432:5432'
networks:
- postgres_network
volumes:
- '/localVol:/bitnami/postgresql'
environment:
- POSTGRESQL_REPLICATION_MODE=master
- POSTGRESQL_REPLICATION_USER=repmgr_username
- POSTGRESQL_REPLICATION_PASSWORD=repmgr_password
- POSTGRESQL_USERNAME=username
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_DATABASE=dbname
- POSTGRESQL_SYNCHRONOUS_COMMIT_MODE=on
- POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
deploy:
placement:
constraints:
- node.labels.type == primary
postgresql-slave:
image: 'docker.io/bitnami/postgresql:15'
ports:
- '5432'
networks:
- postgres_network
depends_on:
- postgresql-master
environment:
- POSTGRESQL_USERNAME=username
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_REPLICATION_MODE=slave
- POSTGRESQL_REPLICATION_USER=repmgr_username
- POSTGRESQL_REPLICATION_PASSWORD=repmgr_password
- POSTGRESQL_MASTER_HOST=postgresql-master
- POSTGRESQL_MASTER_PORT_NUMBER=5432
volumes:
- '/localVol:/bitnami/postgresql'
deploy:
placement:
constraints:
- node.labels.type != primary
networks:
postgres_network:
driver: overlay
external: false
internal: true
ipam:
config:
- subnet: 10.70.1.0/24
The swarm is created via a simple init command and the node is joined via the join command. No extra config.
When running this file with docker compose up (without the deploy constraints) on one host, the two containers are up and running, replicating the database and so on. Working as desired.
When running this file as is with docker stack up, the primary is running and stable, the secondary is not; see logs
Primary
postgresql 14:07:57.00 INFO ==> ** Starting PostgreSQL setup **
postgresql 14:07:57.06 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 14:07:57.07 INFO ==> Loading custom pre-init scripts...
postgresql 14:07:57.09 INFO ==> Initializing PostgreSQL database...
postgresql 14:07:57.10 INFO ==> Custom configuration /opt/bitnami/postgresql/conf/pg_hba.conf detected
postgresql 14:07:57.17 INFO ==> Deploying PostgreSQL with persisted data...
postgresql 14:07:57.21 INFO ==> Configuring replication parameters
postgresql 14:07:57.28 INFO ==> Configuring fsync
postgresql 14:07:57.31 INFO ==> Loading custom scripts...
postgresql 14:07:57.31 INFO ==> Enabling remote connections
postgresql 14:07:57.33 INFO ==> ** PostgreSQL setup finished! **
postgresql 14:07:57.34 INFO ==> ** Starting PostgreSQL **
2022-11-16 14:07:57.363 GMT [1] LOG: pgaudit extension initialized
2022-11-16 14:07:57.374 GMT [1] LOG: starting PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-11-16 14:07:57.377 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-11-16 14:07:57.378 GMT [1] LOG: could not create IPv6 socket for address "::": Address family not supported by protocol
2022-11-16 14:07:57.380 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-11-16 14:07:57.384 GMT [83] LOG: database system was shut down at 2022-11-16 14:07:36 GMT
2022-11-16 14:07:57.392 GMT [1] LOG: database system is ready to accept connections
secondary
postgresql 14:40:51.58 INFO ==> ** Starting PostgreSQL setup **
postgresql 14:40:51.64 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 14:40:51.65 INFO ==> Loading custom pre-init scripts...
postgresql 14:40:51.66 INFO ==> Initializing PostgreSQL database...
postgresql 14:40:51.70 INFO ==> pg_hba.conf file not detected. Generating it...
postgresql 14:40:51.70 INFO ==> Generating local authentication configuration
postgresql 14:40:51.74 INFO ==> Waiting for replication master to accept connections (60 timeout)...
postgresql-master:5432 - no response
The secondary restarts itself after a time of constantly logging no response.
I have tried pinging the containers which works. Also when exposing the port of the primary to the host, it is possible to access the database from the host BUT it is not possible to send any TCP traffic to both container as tried with netcat and tcpdump. Netcat is able to send packets, but tcpdump on the primary and secondary does not show requests.
Anybody got a tip for me?
I just found the error.
As someone states in his blog, a specific port (4789) is blocked when virtualising with an ESXi stack. This is the default port for overlay network traffic.
Simply changing that port when initialising a swarm solves the problem.
docker swarm init --data-path-port 4788
I have already googled this and searched in stack-overflow.
I have this simple docker-compose setup
version: '3.8'
services:
db:
image: postgres:15-bullseye
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=combiner
ports:
- '5432:5432'
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
driver: local
It starts up just fine and I can see the log in the container.
PostgreSQL Database directory appears to contain a database; Skipping initialization
2022-11-06T12:49:06.168906100Z
2022-11-06T12:49:06.198469600Z 2022-11-06 12:49:06.198 UTC [1] LOG: starting PostgreSQL 15.0 (Debian 15.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-11-06T12:49:06.198585700Z 2022-11-06 12:49:06.198 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-11-06T12:49:06.198631000Z 2022-11-06 12:49:06.198 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-11-06T12:49:06.203216100Z 2022-11-06 12:49:06.203 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-11-06T12:49:06.209822300Z 2022-11-06 12:49:06.209 UTC [27] LOG: database system was shut down at 2022-11-06 12:49:05 UTC
2022-11-06T12:49:06.216866300Z 2022-11-06 12:49:06.216 UTC [1] LOG: database system is ready to accept connections
But I cannot connect to the database from outside the container.
I try to use Intellij's database tool and it get a password authentication error.
I am of course running docker-compose on the same computer that I run Intellij on and of course I am giving the correct pasword and user. I should not have to edit the pg_hba.conf file in the container to allow access from outside the container.
Any idea what is going wrong here?
I am trying to run postgreSQL via docker-compose and I am getting the issue that user/password is not created when I started the service.
version: "3"
services:
db:
image: postgres:latest
container_name: postgres
#volumes:
#- postgres-data:/var/lib/postgresql/data
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=postgrespassword
- POSTGRES_USER=postgres
- POSTGRES_DB=random_db_name
restart: always
I have this block of code in my docker-compose.yml and I run the following command:
docker-compose up -d (this allow me to start the service in background)
and when I check the logs I got:
docker logs -f 0e1731f95396
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 dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
initdb: 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.
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2021-04-27 16:20:44.592 UTC [49] LOG: starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-27 16:20:44.594 UTC [49] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-27 16:20:44.603 UTC [50] LOG: database system was shut down at 2021-04-27 16:20:44 UTC
2021-04-27 16:20:44.609 UTC [49] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down...2021-04-27 16:20:44.889 UTC [49] LOG: received fast shutdown request
.2021-04-27 16:20:44.891 UTC [49] LOG: aborting any active transactions
2021-04-27 16:20:44.892 UTC [49] LOG: background worker "logical replication launcher" (PID 56) exited with exit code 1
2021-04-27 16:20:44.892 UTC [51] LOG: shutting down
2021-04-27 16:20:44.907 UTC [49] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2021-04-27 16:20:45.018 UTC [1] LOG: starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-27 16:20:45.019 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-04-27 16:20:45.019 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-04-27 16:20:45.023 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-27 16:20:45.029 UTC [77] LOG: database system was shut down at 2021-04-27 16:20:44 UTC
2021-04-27 16:20:45.034 UTC [1] LOG: database system is ready to accept connections
But when I try to connect to this database locally I get the message: "FATAL: role "postgres" does not exist"
Do you have any input about how to solve this problem?
I already made a few attempts after reading a few comments from different places but I got always the same problem.
I was expecting to run locally postgreSQL and setup already a user/password and a Database with that name in the docker-compose
I have a docker compose setup that was working before (for several months) but after restarting the Pi its now not working :(
Whats to be noted is that when pointing the DB to an empty DB folder, there are no restarts of the Postgres container and no errors. I tried one backup from the past for the DB data folder but still getting the error. Not sure why?
Here is the error postgres is returning:
PostgreSQL Database directory appears to contain a database; Skipping initialization
2021-03-30 13:38:46.052 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on arm-unknown-linux-gnueabihf, compiled by gcc (Debian 8.3.0-6) 8.3.0, 32-bit
2021-03-30 13:38:46.053 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-03-30 13:38:46.053 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-03-30 13:38:46.063 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-03-30 13:38:48.195 UTC [1] LOG: startup process (PID 26) was terminated by signal 11: Segmentation fault
2021-03-30 13:38:48.195 UTC [1] LOG: aborting startup due to startup process failure
2021-03-30 13:38:48.272 UTC [1] LOG: database system is shut down
Here is part of the docker compose file for the DB:
miniflux-db:
container_name: miniflux-db
image: postgres:12-alpine
environment:
- POSTGRES_USER=${MINIFLUX_DB_USER}
- POSTGRES_PASSWORD=${MINIFLUX_DB_PASSWORD}
restart: unless-stopped
volumes:
- ${MINIFLUX_DB}:/var/lib/postgresql/data:shared
networks:
- miniflux-net
Info:
Raspberry Pi 4
Docker version 20.10.5, build 55c4c88
I can't even port the data to version 13 of Postgres nor use the Postgres DB folder on an Intel architecture. Had I known that Postgres DB data folder is architecture-bound I would not have chosen it!
Any help pls? Thanks!
try this:
wget http://ftp.debian.org/debian/pool/main/libs/libseccomp/libseccomp2_2.5.1-1_armhf.deb
sudo dpkg -i libseccomp2_2.5.1-1_armhf.deb
I my case I had to prune docker then it worked.
You can try this: Segmentation fault on RPi #812
Raspbian OS has a old version from libseccomp, you need to upgrade this lib manually.
If you have some volumes used by container, remove then before start postgres container again.
Problem
Following the postgres docker official page:
https://hub.docker.com/_/postgres
I've created "stack.yml"
and it's contain:
# Use postgres/example user/password credentials
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
And then running command:
$ docker stack deploy -c stack.yml postgres
But after it is finished, I cannot open http://localhost:8080
it keep "Waiting for ..."
I followed everything from the docs, and keep retrying but keep failing, any help would be very appreciated?
update:
using docker-compose is working, but I'm still curious why running with docker stack ... won't work
Additional details
Software version:
Pop!_OS 20.04 LTS
Docker version 19.03.12, build 48a66213fe
Here is $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0fa7f4ce6ef postgres:latest "docker-entrypoint.s…" 23 minutes ago Up 23 minutes 5432/tcp postgres_db.1.pq28sm95br3hhr92gvxpsrgwd
4a8b54019f7d adminer:latest "entrypoint.sh docke…" 23 minutes ago Up 23 minutes 8080/tcp postgres_adminer.1.kya7f232pjc4975ubj9ywa13x
Here is $ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
j7mxwf0rpi7g postgres_adminer replicated 1/1 adminer:latest *:8080->8080/tcp
we8izke0tb34 postgres_db replicated 1/1 postgres:latest
Here is docker logs for 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 dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
initdb: 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.
waiting for server to start....2020-09-08 06:21:18.981 UTC [46] LOG: starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-09-08 06:21:18.982 UTC [46] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-09-08 06:21:18.994 UTC [47] LOG: database system was shut down at 2020-09-08 06:21:18 UTC
2020-09-08 06:21:18.997 UTC [46] LOG: database system is ready to accept connections
done
server started
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2020-09-08 06:21:19.074 UTC [46] LOG: received fast shutdown request
waiting for server to shut down....2020-09-08 06:21:19.075 UTC [46] LOG: aborting any active transactions
2020-09-08 06:21:19.076 UTC [46] LOG: background worker "logical replication launcher" (PID 53) exited with exit code 1
2020-09-08 06:21:19.077 UTC [48] LOG: shutting down
2020-09-08 06:21:19.090 UTC [46] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2020-09-08 06:21:19.186 UTC [1] LOG: starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2020-09-08 06:21:19.186 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-09-08 06:21:19.186 UTC [1] LOG: listening on IPv6 address "::", port 5432
2020-09-08 06:21:19.188 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-09-08 06:21:19.216 UTC [55] LOG: database system was shut down at 2020-09-08 06:21:19 UTC
2020-09-08 06:21:19.219 UTC [1] LOG: database system is ready to accept connections
Here is docker logs for adminer:
[Tue Sep 8 06:21:01 2020] PHP 7.4.10 Development Server (http://[::]:8080) started
Use an IP address instead of hostname