Error when run bitnami postgres container - postgresql

it's my first time with docker. I have created a docker container from a bitnami image with this Dockerfile:
FROM bitnami/postgresql:14.1.0
MAINTAINER <whatever>
ADD --chown=1001:1001 main /bitnami/postgresql/data
where main is a copy of my postgresql database /var/lib/postgresql/data
When I try to run the container in this way:
docker run -d --name database -p 5432:5432 -e ALLOW_EMPTY_PASSWORD=yes mypostgres
I get the following error, does anyone know what it is and how to fix it.
postgresql 15:39:28.09
postgresql 15:39:28.09 Welcome to the Bitnami postgresql container
postgresql 15:39:28.09 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql 15:39:28.09 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql 15:39:28.09
postgresql 15:39:28.12 INFO ==> ** Starting PostgreSQL setup **
postgresql 15:39:28.16 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 15:39:28.17 WARN ==> You set the environment variable ALLOW_EMPTY_PASSWORD=yes. For safety reasons, do not use this flag in a production environment.
postgresql 15:39:28.18 INFO ==> Loading custom pre-init scripts...
postgresql 15:39:28.18 INFO ==> Initializing PostgreSQL database...
postgresql 15:39:28.21 INFO ==> pg_hba.conf file not detected. Generating it...
postgresql 15:39:28.22 INFO ==> Generating local authentication configuration
postgresql 15:39:28.23 INFO ==> Deploying PostgreSQL with persisted data...
postgresql 15:39:28.25 INFO ==> Configuring replication parameters
postgresql 15:39:28.30 INFO ==> Configuring fsync
postgresql 15:39:28.34 INFO ==> Loading custom scripts...
postgresql 15:39:28.34 INFO ==> Enabling remote connections
postgresql 15:39:28.37 INFO ==> ** PostgreSQL setup finished! **
postgresql 15:39:28.41 INFO ==> ** Starting PostgreSQL **
2021-12-14 15:39:28.454 GMT [1] LOG: pgaudit extension initialized
2021-12-14 15:39:28.462 GMT [1] FATAL: could not open directory "pg_notify": No such file or directory
2021-12-14 15:39:28.463 GMT [1] LOG: database system is shut down

Related

Authentication error when connection to local postgres db

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.

Postgresql Docker container not receiving TCP requests in swarm mode

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

"error: pq: role "root" does not exist" when running pq with Postgres for Docker [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
I am setting up a local Postgres database on Docker with the postgres:14-alpine image, and running database migrations on it with golang-migrate, when I got the following error message after running the migrate tool:
error: pq: role "root" does not exist
I was running the following commands:
$ docker run --name postgres14 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=pass -d postgres:14-alpine
$ docker exec -it postgres14 createdb --user=root --owner=root demodb
$ migrate -path db/migrations -database postgresql://root:pass#localhost:5432/demodb?sslmode=disable --verbose up
These commands can also be viewed in this Makefile, and the full codebase can be found in this repository.
Here are the logs from the Postgres container:
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 ... 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
waiting for server to start....2022-10-15 09:56:41.209 UTC [36] LOG: starting PostgreSQL 14.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
2022-10-15 09:56:41.211 UTC [36] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-15 09:56:41.217 UTC [37] LOG: database system was shut down at 2022-10-15 09:56:41 UTC
2022-10-15 09:56:41.220 UTC [36] 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...2022-10-15 09:56:41.422 UTC [36] LOG: received fast shutdown request
.2022-10-15 09:56:41.423 UTC [36] LOG: aborting any active transactions
2022-10-15 09:56:41.423 UTC [36] LOG: background worker "logical replication launcher" (PID 43) exited with exit code 1
2022-10-15 09:56:41.424 UTC [38] LOG: shutting down
2022-10-15 09:56:41.434 UTC [36] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
What should I do to configure the root role correctly?
The docker image docs specify that POSTGRES_USER environment variable defaults to postgres if not set, try using that instead of root or drop the container and build it again using the correct environment variable
once you are inside the psql shell you can create a user with
CREATE USER username WITH PASSWORD 'your_password';
then to grant the user access on a specific database:
GRANT ALL PRIVILEGES ON DATABASE demodb TO username;
once that is done you can use the user in the connection string in make file
Turns out the Postgres server that was installed and setup on my OS by Hombrew was using the same port, which clashed with the requests made to the containerized database under the same port number.
This issue can be solved by either using a different port number for the containerized database, or by shutting down the database on the OS.

Bitnami jupyterhub charts on k8s failing due to password authentication failed for user "bn_jupyterhub"

I deployed JupyterHub packaged by Bitnami on our GKE k8s cluster under one of our namespaces with the same default values defined in their repo successfully.
https://github.com/bitnami/charts/tree/master/bitnami/jupyterhub/#installing-the-chart
However I noticed jupyterhub pod is crashing with Init:CrashLoopBackOff error and logs shows it could not connect to database server.
kubectl logs pod/jupyterhub-hub-59cc99bdfb-d4vjx wait-for-db
←[38;5;6m ←[38;5;5m04:24:03.35 ←[0m←[38;5;2mINFO ←[0m ==> Connecting to the PostgreSQL instance jupyterhub-postgresql:5432
←[38;5;6m ←[38;5;5m04:25:03.57 ←[0m←[38;5;1mERROR←[0m ==> Could not connect to the database server
/bin/bash: line 18: return: can only `return' from a function or sourced script
It seems postgressql-0 pod is runnin into authentication error seems to be the cause here. I have not used any changes in the values.yaml file provided in the https://github.com/bitnami/charts/blob/master/bitnami/jupyterhub/values.yaml.
kubectl logs jupyterhub-postgresql-0 postgresql
←[38;5;6mpostgresql ←[38;5;5m03:13:30.41 ←[0m
←[38;5;6mpostgresql ←[38;5;5m03:13:30.41 ←[0m←[1mWelcome to the Bitnami postgresql container←[0m
←[38;5;6mpostgresql ←[38;5;5m03:13:30.41 ←[0mSubscribe to project updates by watching ←[1mhttps://github.com/bitnami/containers←[0m
←[38;5;6mpostgresql ←[38;5;5m03:13:30.41 ←[0mSubmit issues and feature requests at ←[1mhttps://github.com/bitnami/containers/issues←[0m
←[38;5;6mpostgresql ←[38;5;5m03:13:30.42 ←[0m
←[38;5;6mpostgresql ←[38;5;5m03:13:30.45 ←[0m←[38;5;2mINFO ←[0m ==> ** Starting PostgreSQL setup **
←[38;5;6mpostgresql ←[38;5;5m03:13:30.46 ←[0m←[38;5;2mINFO ←[0m ==> Validating settings in POSTGRESQL_* env vars..
←[38;5;6mpostgresql ←[38;5;5m03:13:30.47 ←[0m←[38;5;2mINFO ←[0m ==> Loading custom pre-init scripts...
←[38;5;6mpostgresql ←[38;5;5m03:13:30.48 ←[0m←[38;5;2mINFO ←[0m ==> Initializing PostgreSQL database...
←[38;5;6mpostgresql ←[38;5;5m03:13:30.50 ←[0m←[38;5;2mINFO ←[0m ==> pg_hba.conf file not detected. Generating it...
←[38;5;6mpostgresql ←[38;5;5m03:13:30.50 ←[0m←[38;5;2mINFO ←[0m ==> Generating local authentication configuration
←[38;5;6mpostgresql ←[38;5;5m03:13:30.53 ←[0m←[38;5;2mINFO ←[0m ==> Deploying PostgreSQL with persisted data...
←[38;5;6mpostgresql ←[38;5;5m03:13:30.57 ←[0m←[38;5;2mINFO ←[0m ==> Configuring replication parameters
←[38;5;6mpostgresql ←[38;5;5m03:13:30.61 ←[0m←[38;5;2mINFO ←[0m ==> Configuring fsync
←[38;5;6mpostgresql ←[38;5;5m03:13:30.62 ←[0m←[38;5;2mINFO ←[0m ==> Configuring synchronous_replication
←[38;5;6mpostgresql ←[38;5;5m03:13:30.66 ←[0m←[38;5;2mINFO ←[0m ==> Loading custom scripts...
←[38;5;6mpostgresql ←[38;5;5m03:13:30.66 ←[0m←[38;5;2mINFO ←[0m ==> Enabling remote connections
←[38;5;6mpostgresql ←[38;5;5m03:13:30.67 ←[0m←[38;5;2mINFO ←[0m ==> ** PostgreSQL setup finished! **
←[38;5;6mpostgresql ←[38;5;5m03:13:30.69 ←[0m←[38;5;2mINFO ←[0m ==> ** Starting PostgreSQL **
2022-09-01 03:13:30.760 GMT [1] LOG: pgaudit extension initialized
2022-09-01 03:13:30.765 GMT [1] LOG: starting PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-09-01 03:13:30.765 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-09-01 03:13:30.766 GMT [1] LOG: listening on IPv6 address "::", port 5432
2022-09-01 03:13:30.769 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-09-01 03:13:30.775 GMT [91] LOG: database system was shut down at 2022-09-01 02:36:41 GMT
2022-09-01 03:13:30.813 GMT [1] LOG: database system is ready to accept connections
2022-09-01 03:13:57.645 GMT [116] FATAL: password authentication failed for user "bn_jupyterhub"
2022-09-01 03:13:57.645 GMT [116] DETAIL: Connection matched pg_hba.conf line 1: "host all all 0.0.0.0/0 md5"
2022-09-01 03:14:02.663 GMT [118] FATAL: password authentication failed for user "bn_jupyterhub"
2022-09-01 03:14:02.663 GMT [118] DETAIL: Connection matched pg_hba.conf line 1: "host all all 0.0.0.0/0 md5"
2022-09-01 03:14:07.681 GMT [131] FATAL: password authentication failed for user "bn_jupyterhub"
This was deployed with the same command helm install jupyterhub bitnami/jupyterhub. There were no special instructions or password suppled in the values.yaml file.
What am I missing here? Do I have to specify password values here to make it working? restarting the pod and redeploying the charts seems not helpful.
Any further advises are highly appreciated!
Thank you
Thought i'd chip in here...
...This is caused due to deploying/redeploying via a pv/pvc, that doesn't necessarily get deleted - Then when you redeploy if you don't explicitly define a password then the previous pvc gets re-used, it recognises there's a bn_jupyterhub user on the database... And so never updates it.
Workarounds:
Specify inside your jupyterhub some override values for values.yaml to explicitly define the bn_jupyterhub password (functional, but clearly insecure).
Define a secret prior to deploying, and then use that with the same values.yaml overriding to use that existing secret. That way, the secret doesn't get re-created and you can use forevermore.
Define a separate postgres database and configure jupyterhub to use that external database.
Reference: https://docs.bitnami.com/general/how-to/troubleshoot-helm-chart-issues/#persistence-volumes-pvs-retained-from-previous-releases

Error running PostgreSQL on Docker-io

When attempting to initialise the PostgreSQL database after installing on a Docker-io Fedora 19 container I get the following error:
bash-4.2# postgresql-setup initdb
Failed to get D-Bus connection: No connection to service manager.
failed to find PGDATA setting in postgresql.service
Looks like an environmental issue but any help would be appreciated.