Strapi, postgres, docker: What is the right way to export a local database and export it on a remote server? - postgresql

The problem
I have a project based on Strapi's CMS and Postgres database wrapped in docker containers which I start toghether from a single docker-compose.yml script. I have developed the project locally and want to move it on a remote server keeping the current state of all data I inserted by the CMS. In other words my local Postgres database is not empty and contains tables and information generated by the CMS. I have copied all *.js files dynamically generated from the CMS to the remote server along with the public/ folder, but have troubles to export/import an exact copy of the database. What is the right way to copy the database from the docker containers? I prefer to export it in a single or multiple *.sql files that can be imported from the /usr/local/bin/docker-entrypoint.sh folder.
What have I tried so far?
Using Adminer I have exported it as a single *.sql file. It imports successfully just by placing the exported file in Postgres container's folder /usr/local/bin/docker-entrypoint.sh. So all data I have inserted into the CMS on my local database is in the remote database. At first glance everything looks alright, until I try to update some CMS collection from the admin panel. Then in the user interface come up strange errors in the same time the Postgres and Strapi's log says this:
postgres | 2023-02-17 11:44:39.438 UTC [40] ERROR: duplicate key value violates unique constraint "about_pages_components_pkey"
postgres | 2023-02-17 11:44:39.438 UTC [40] DETAIL: Key (id)=(35) already exists.
postgres | 2023-02-17 11:44:39.438 UTC [40] STATEMENT: insert into "about_pages_components" ("component_id", "component_type", "entity_id", "field", "order") values ($1, $2, $3, $4, $5) returning "id"
api | [2023-02-17 11:44:39.440] error: insert into "about_pages_components" ("component_id", "component_type", "entity_id", "field", "order") values ($1, $2, $3, $4, $5) returning "id" - duplicate key value violates unique constraint "about_pages_components_pkey"
api | error: insert into "about_pages_components" ("component_id", "component_type", "entity_id", "field", "order") values ($1, $2, $3, $4, $5) returning "id" - duplicate key value violates unique constraint "about_pages_components_pkey"
api | at Parser.parseErrorMessage (/opt/app/node_modules/pg-protocol/dist/parser.js:287:98)
api | at Parser.handlePacket (/opt/app/node_modules/pg-protocol/dist/parser.js:126:29)
api | at Parser.parse (/opt/app/node_modules/pg-protocol/dist/parser.js:39:38)
api | at Socket.<anonymous> (/opt/app/node_modules/pg-protocol/dist/index.js:11:42)
api | at Socket.emit (events.js:400:28)
api | at Socket.emit (domain.js:475:12)
api | at addChunk (internal/streams/readable.js:293:12)
api | at readableAddChunk (internal/streams/readable.js:267:9)
api | at Socket.Readable.push (internal/streams/readable.js:206:10)
api | at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
ngi
Adminer's export settings:
Using docker exec -t postgres pg_dump -c -U postgres > init.sql I get the following error log:
postgres | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
postgres | SET
postgres | SET
postgres | SET
postgres | SET
postgres | SET
postgres | set_config
postgres | ------------
postgres |
postgres | (1 row)
postgres |
postgres | SET
postgres | SET
postgres | SET
postgres | SET
postgres | 2023-02-17 11:50:46.045 UTC [50] ERROR: relation "public.up_users" does not exist
postgres | 2023-02-17 11:50:46.045 UTC [50] STATEMENT: ALTER TABLE ONLY public.up_users DROP CONSTRAINT up_users_updated_by_id_fk;
postgres | psql:/docker-entrypoint-initdb.d/init.sql:19: ERROR: relation "public.up_users" does not exist
postgres | 2023-02-17 11:50:47.358 UTC [1] LOG: starting PostgreSQL 14.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
postgres | 2023-02-17 11:50:47.358 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2023-02-17 11:50:47.358 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2023-02-17 11:50:47.375 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2023-02-17 11:50:47.393 UTC [24] LOG: database system was interrupted; last known up at 2023-02-17 11:50:45 UTC
postgres | 2023-02-17 11:50:51.704 UTC [24] LOG: database system was not properly shut down; automatic recovery in progress
postgres | 2023-02-17 11:50:51.735 UTC [24] LOG: invalid record length at 0/16FCE28: wanted 24, got 0
postgres | 2023-02-17 11:50:51.735 UTC [24] LOG: redo is not required
postgres | 2023-02-17 11:50:52.395 UTC [1] LOG: database system is ready to accept connections
Using docker exec -t postgres pg_dumpall -c -U postgres > init.sql I get the following error log:
postgres | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
postgres | SET
postgres | SET
postgres | SET
postgres | 2023-02-17 12:05:48.154 UTC [49] ERROR: current user cannot be dropped
postgres | 2023-02-17 12:05:48.154 UTC [49] STATEMENT: DROP ROLE postgres;
postgres | psql:/docker-entrypoint-initdb.d/init.sql:22: ERROR: current user cannot be dropped
postgres | 2023-02-17 12:05:49.532 UTC [1] LOG: starting PostgreSQL 14.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
postgres | 2023-02-17 12:05:49.532 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2023-02-17 12:05:49.533 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2023-02-17 12:05:49.554 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2023-02-17 12:05:49.581 UTC [22] LOG: database system was interrupted; last known up at 2023-02-17 12:05:48 UTC
Strapi version and dependencies:
"dependencies": {
"#strapi/plugin-i18n": "4.2.3",
"#strapi/plugin-users-permissions": "4.2.3",
"#strapi/strapi": "4.2.3",
"better-sqlite3": "7.4.6",
"pg": "^8.8.0"
},
Postgres docker image postgres:14.3-alpine
Adminer docker image adminer:4.8.1

Related

Unable to connect to postgres using docker compose

I have a very simple docker-compose.yml file which currently is only to set up a posgresql database, but I can't connect to it once it is running. Instead I get this error:
2022-10-10 11:19:41.820 UTC [43] FATAL: lock file "postmaster.pid" already exists
2022-10-10 11:19:41.820 UTC [43] HINT: Is another postmaster (PID 1) running in data directory "/var/lib/postgresql/data"?
The docker-compose.yml is:
version: "3.9"
services:
db:
image: "postgres"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- '5432:5432'
volumes:
- /pgdata:/var/lib/postgresql/data
When I try to connect to the running container I use:
docker exec -it -u postgres 31f122d6a413 postgres
The logs from the container are:
Recreating test-docker-proj ...
WARNING: Service "db" is using volume "/var/lib/postgresql/data" from the previous container. Host mapping "/pgdata" has no effect.
Recreating test-docker-proj ... done
Attaching to test-docker-proj
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2022-10-10 11:05:02.349 UTC [1] LOG: starting PostgreSQL 14.5 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
db_1 | 2022-10-10 11:05:02.349 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2022-10-10 11:05:02.349 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2022-10-10 11:05:02.352 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2022-10-10 11:05:02.356 UTC [22] LOG: database system was shut down at 2022-10-10 10:47:01 UTC
db_1 | 2022-10-10 11:05:02.361 UTC [1] LOG: database system is ready to accept connections
It seems that postgres/docker is persisting user login details from previous containers or something? I am at a bit of a loss anyway, so any guidance would be appreciated.
I am using:
Mac Monterey M1
docker-compose version 1.29.2
Probably worth adding that I can connect to the container using /bin/sh rather than postgres

Docker Composed PostgreSQL Copy Functioning but No Relations Found in Database

I have a simple Dockerfile that sets up a database and then runs a .sql file. The image builds and container starts with no apparent issue, but PostgreSQL is missing data that should have been included.
Here's the setup, logs, and problem---
Dockerfile
FROM postgres
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD postgres
ENV POSTGRES_DB exampledb
COPY db-setup.sql /docker-entrypoint-initdb.d/
I run it with docker build -t example-db ./
This is the copied .sql file
BEGIN;
CREATE TABLE IF NOT EXISTS users (
id integer NOT NULL,
name VARCHAR,
email VARCHAR,
password VARCHAR,
remember_token varchar(100),
company_name VARCHAR,
company_street VARCHAR,
company_city VARCHAR,
company_zipcode integer,
created_at timestamp,
updated_at timestamp
);
CREATE TABLE IF NOT EXISTS quotes (
id integer NOT NULL,
dot_number integer,
nbr_of_power_units integer,
value_of_power_units integer,
premium_amount integer,
premium_tax integer,
premium_total integer,
street VARCHAR,
city VARCHAR,
state VARCHAR,
zipcode integer,
driver1_name VARCHAR,
driver1_age integer,
driver2_name VARCHAR,
driver2_age integer,
driver3_name VARCHAR,
driver3_age integer,
driver4_name VARCHAR,
driver4_age integer,
driver5_name VARCHAR,
driver5_age integer,
created_at timestamp,
updated_at timestamp
);
INSERT INTO users (id, name) VALUES (1, 'test-user');
Lastly I start the container via docker run --name example-container -p 5432:5432 example-db
It appears to function correctly, outputing this log.
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 ... 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.
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....2021-05-07 04:04:45.428 UTC [47] 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-05-07 04:04:45.429 UTC [47] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-05-07 04:04:45.435 UTC [48] LOG: database system was shut down at 2021-05-07 04:04:45 UTC
2021-05-07 04:04:45.439 UTC [47] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/db-setup.sql
BEGIN
CREATE ROLE
CREATE TABLE
CREATE TABLE
INSERT 0 1
waiting for server to shut down....2021-05-07 04:04:45.772 UTC [47] LOG: received fast shutdown request
2021-05-07 04:04:45.774 UTC [47] LOG: aborting any active transactions
2021-05-07 04:04:45.776 UTC [47] LOG: background worker "logical replication launcher" (PID 54) exited with exit code 1
2021-05-07 04:04:45.777 UTC [49] LOG: shutting down
2021-05-07 04:04:45.810 UTC [47] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2021-05-07 04:04:45.919 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-05-07 04:04:45.919 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-05-07 04:04:45.920 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-05-07 04:04:45.923 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-05-07 04:04:45.929 UTC [84] LOG: database system was shut down at 2021-05-07 04:04:45 UTC
2021-05-07 04:04:45.935 UTC [1] LOG: database system is ready to accept connections
Pulling from that log there's an indication that the tables in the .sql file were created, and the test row inserted.
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/db-setup.sql
BEGIN
CREATE ROLE
CREATE TABLE
CREATE TABLE
INSERT 0 1
However, when I bash into the Docker container docker exec -it example-container /bin/bash and then log into psql psql -U postgres
I can see the newly created database
------------+----------+----------+------------+------------+-----------------------
exampledb | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
But, connecting to the db and running \dt yields- "Did not find any relations."
I am very confused and any help would be appreciated.
Ah! Man...this one looks sneaky. I think your culprit is the BEGIN; at the start of your SQL init script. That starts a Postgres transaction. Essentially that means your script will create your tables, but since there isn't an END; statement, the Postgres transaction is left open.
When Docker aborts active transactions as a part of its startup process, that init script transaction is aborted. And when an in progress Postgres transaction is aborted, all the work inside that transaction block is reversed. I.e., you go back to the state your database was in when the init script started - empty.
Try removing the BEGIN; and running it from there!

Connecting to an existing docker postgres container with sequelize

I have an existing postgres container that is working fine on its own. I am trying to follow best practices with Sequelize with proper migrations and models now.
I spin up the docker container containing the postgres database:
Starting postgres-express-docker_postgres_1 ... done
Attaching to postgres-express-docker_postgres_1
postgres_1 |
postgres_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1 |
postgres_1 | 2020-08-06 14:43:59.373 UTC [1] LOG: starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1 | 2020-08-06 14:43:59.373 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-08-06 14:43:59.373 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-08-06 14:43:59.376 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-08-06 14:43:59.388 UTC [27] LOG: database system was shut down at 2020-08-06 14:43:54 UTC
postgres_1 | 2020-08-06 14:43:59.393 UTC [1] LOG: database system is ready to accept connections
Then when I try to run sequelize db:migrate to run the built out migrations I get:
ERROR: getaddrinfo ENOTFOUND 0.0.0.0:5432
What Am I missing here? The sequelize Config is pointing to the same address...
Thanks in advance

Docker | Postgres Database is uninitialized and superuser password is not specified

I am using docker-compose.yml to create multiple running containers but failing to start Postgres docker server, with following logs and yes I have searched many related SO posts, but they didn't helped me out.
Creating network "complex_default" with the default driver
Creating complex_server_1 ... done
Creating complex_redis_1 ... done
Creating complex_postgres_1 ... done
Attaching to complex_postgres_1, complex_redis_1, complex_server_1
postgres_1 | Error: Database is uninitialized and superuser password is not specified.
postgres_1 | You must specify POSTGRES_PASSWORD to a non-empty value for the
postgres_1 | superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
postgres_1 |
postgres_1 | You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
postgres_1 | connections without a password. This is *not* recommended.
postgres_1 |
postgres_1 | See PostgreSQL documentation about "trust":
postgres_1 | https://www.postgresql.org/docs/current/auth-trust.html
complex_postgres_1 exited with code 1
below is my docker-compose configuration:
version: '3'
services:
postgres:
image: 'postgres:11-alpine'
redis:
image: 'redis:latest'
server:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres_password
- PGPORT=5432
as well as package.json inside server directory is following:
{
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.4",
"express": "^4.16.3",
"nodemon": "^2.0.4",
"pg": "7.4.3",
"redis": "^2.8.0"
},
"scripts": {
"dev": "nodemon",
"start": "node index.js"
}
}
also for better consideration, I have attached my hands-on project structure:
A year ago it were actually working fine, Does anyone have any idea, what's going wrong here inside my docker-compose file now.
A year ago it were actually working fine, Does anyone have any idea, what's going wrong here inside my docker-compose file now.
Seems like you pulled the fresh image, where in the new image you should specify Postgres user password. You can look into Dockerhub, the image is update one month ago
postgress-11-alpine
db:
image: postgres:11-alpine
restart: always
environment:
POSTGRES_PASSWORD: example
As the error message is self expalinatory
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
or POSTGRES_HOST_AUTH_METHOD=trust use this which is not recommended.
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
connections without a password. This is *not* recommended.
POSTGRES_PASSWORD
This environment variable is required for you to use the PostgreSQL image. It must not be empty or undefined. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER environment variable.
Environment Variables
#Adiii yes, you are nearly right, so I have to explicitly mentioned the environment also for the postgres image but with no db parent tag.
So here, I am explicitly mentioning the docker-compose.yaml config to help others for better understanding, also now I am using recent stable postgres image version 12-alpine, currently latest is postgres:12.3
version: '3'
services:
postgres:
image: 'postgres:12-alpine'
environment:
POSTGRES_PASSWORD: postgres_password
redis:
image: 'redis:latest'
server:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres_password
- PGPORT=5432
and so after docker-compose up the creating and running logs were as following:
PS E:\docker\complex> docker-compose up
Creating network "complex_default" with the default driver
Creating complex_postgres_1 ... done
Creating complex_redis_1 ... done
Creating complex_server_1 ... done
Attaching to complex_redis_1, complex_postgres_1, complex_server_1
postgres_1 | The files belonging to this database system will be owned by user "postgres".
postgres_1 | This user must also own the server process.
postgres_1 |
postgres_1 | The database cluster will be initialized with locale "en_US.utf8".
postgres_1 | The default database encoding has accordingly been set to "UTF8".
postgres_1 | The default text search configuration will be set to "english".
postgres_1 |
postgres_1 | Data page checksums are disabled.
postgres_1 |
postgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1 | creating subdirectories ... ok
postgres_1 | selecting dynamic shared memory implementation ... posix
postgres_1 | selecting default max_connections ... 100
postgres_1 | selecting default shared_buffers ... 128MB
postgres_1 | selecting default time zone ... UTC
redis_1 | 1:C 05 Aug 2020 14:24:48.692 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 05 Aug 2020 14:24:48.692 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 05 Aug 2020 14:24:48.692 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
postgres_1 | creating configuration files ... ok
redis_1 | 1:M 05 Aug 2020 14:24:48.693 * Running mode=standalone, port=6379.
redis_1 | 1:M 05 Aug 2020 14:24:48.693 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 05 Aug 2020 14:24:48.694 # Server initialized
redis_1 | 1:M 05 Aug 2020 14:24:48.694 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 05 Aug 2020 14:24:48.694 * Ready to accept connections
postgres_1 | running bootstrap script ... ok
server_1 |
server_1 | > # dev /app
server_1 | > nodemon
server_1 |
postgres_1 | performing post-bootstrap initialization ... sh: locale: not found
postgres_1 | 2020-08-05 14:24:50.153 UTC [29] WARNING: no usable system locales were found
server_1 | [nodemon] 2.0.4
server_1 | [nodemon] to restart at any time, enter `rs`
server_1 | [nodemon] watching path(s): *.*
server_1 | [nodemon] watching extensions: js,mjs,json
server_1 | [nodemon] starting `node index.js`
postgres_1 | ok
server_1 | Listening
postgres_1 | syncing data to disk ... ok
postgres_1 |
postgres_1 |
postgres_1 | Success. You can now start the database server using:
postgres_1 |
postgres_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres_1 |
postgres_1 | initdb: warning: enabling "trust" authentication for local connections
postgres_1 | You can change this by editing pg_hba.conf or using the option -A, or
postgres_1 | --auth-local and --auth-host, the next time you run initdb.
postgres_1 | waiting for server to start....2020-08-05 14:24:51.634 UTC [34] LOG: starting PostgreSQL 12.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
postgres_1 | 2020-08-05 14:24:51.700 UTC [34] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-08-05 14:24:51.981 UTC [35] LOG: database system was shut down at 2020-08-05 14:24:50 UTC
postgres_1 | 2020-08-05 14:24:52.040 UTC [34] LOG: database system is ready to accept connections
postgres_1 | done
postgres_1 | server started
postgres_1 |
postgres_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
postgres_1 |
postgres_1 | waiting for server to shut down....2020-08-05 14:24:52.121 UTC [34] LOG: received fast shutdown request
postgres_1 | 2020-08-05 14:24:52.186 UTC [34] LOG: aborting any active transactions
postgres_1 | 2020-08-05 14:24:52.188 UTC [34] LOG: background worker "logical replication launcher" (PID 41) exited with exit code 1
postgres_1 | 2020-08-05 14:24:52.188 UTC [36] LOG: shutting down
postgres_1 | 2020-08-05 14:24:52.669 UTC [34] LOG: database system is shut down
postgres_1 | done
postgres_1 | server stopped
postgres_1 |
postgres_1 | PostgreSQL init process complete; ready for start up.
postgres_1 |
postgres_1 | 2020-08-05 14:24:52.832 UTC [1] LOG: starting PostgreSQL 12.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
postgres_1 | 2020-08-05 14:24:52.832 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-08-05 14:24:52.832 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-08-05 14:24:52.954 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-08-05 14:24:53.136 UTC [43] LOG: database system was shut down at 2020-08-05 14:24:52 UTC
postgres_1 | 2020-08-05 14:24:53.194 UTC [1] LOG: database system is ready to accept connections
Hope this would help manyone.
Adding on ArifMustafa's answer, This worked for me.
postgres:
image: 'postgres:12-alpine'
environment:
POSTGRES_PASSWORD: mypassword
expose:
- 5432
volumes:
- postgres_data:/var/lib/postgres/data/
volumes:
postgres_data:
In my case there was an error about the POSTGRES_PASSWORD (in docker-compose.yml) and the DATABASE settings for PASSWORD in the project_level settings.py file.
After providing a password in docker-compose.yml
db: # For the PostgreSQL database
image: postgres:11
environment:
- POSTGRES_PASSWORD=example
It is necessary to provide the same password to enable access to the POSTGRES database between the two containers (in my case the web application and the database it depended on). In the project_level settings.py:
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'example',
'HOST': 'db',
'PORT': 5432
}
}
To resolve the error when using the command,
docker pull postgres
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
or POSTGRES_HOST_AUTH_METHOD=trust use this which is not recommended.
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all connections without a password. This is not recommended.
Here comes the solution for this:
$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
The default postgres user and database are created in the entrypoint with initdb.
The postgres database is a default database meant for use by users, utilities and third party applications.
postgresql.org/docs

Postgres docker "User "postgres" has no password assigned."

I am running a Postgres image using docker. It used to run without any problems on both Windows10 and Ubuntu 18.04.
After recloning the project on the Ubuntu system, it gives me password authentication failed for user "postgres" error after running docker-compose up.
It used to run without any problems before recloning the project on the Ubuntu system and it still works without any problems on the Windows10 system.
My docker-compose.yml:
version: '2'
services:
postgresql:
image: 'bitnami/postgresql:latest'
ports:
- '5432:5432'
environment:
- POSTGRESQL_USERNAME=someuser
- POSTGRESQL_PASSWORD=mysecretpassword
- POSTGRESQL_DATABASE=mydatabase
I tried sudo docker system prune to remove all stopped containers and their unused networks. This does not solve the problem.
What do I need to change/do so the Postgres image is able to run succesfully on the Ubuntu system again?
The full error:
postgresql_1 | nami INFO Initializing postgresql
postgresql_1 | postgre INFO ==> No injected postgresql.conf file found.
Creating default postgresql.conf file...
postgresql_1 | postgre INFO ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgresql_1 | postgre INFO ==> Deploying PostgreSQL from scratch...
postgresql_1 | postgre INFO ==> Creating database mydatabase...
postgresql_1 | postgre INFO ==> Creating user "someuser"...
postgresql_1 | postgre INFO ==> Granting access to "someuser" to the database mydatabase...
postgresql_1 | postgre INFO ==> Configuring PostgreSQL...
postgresql_1 | postgre INFO ==> Configuring replication parameters...
postgresql_1 | postgre INFO ==> Configuring permissions for config files...
postgresql_1 | postgre INFO
postgresql_1 | postgre INFO
########################################################################
postgresql_1 | postgre INFO Installation parameters for postgresql:
postgresql_1 | postgre INFO User: someuser
postgresql_1 | postgre INFO Password: ***************
postgresql_1 | postgre INFO Database: mydatabase
postgresql_1 | postgre INFO (Passwords are not shown for security reasons)
postgresql_1 | postgre INFO
########################################################################
postgresql_1 | postgre INFO
postgresql_1 | nami INFO postgresql successfully initialized
postgresql_1 | INFO ==> Starting postgresql...
postgresql_1 | 2019-04-15 09:31:18.582 GMT [125] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgresql_1 | 2019-04-15 09:31:18.583 GMT [125] LOG: listening on IPv6 address "::", port 5432
postgresql_1 | 2019-04-15 09:31:18.587 GMT [125] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
postgresql_1 | 2019-04-15 09:31:18.599 GMT [132] LOG: database system was shut down at 2019-04-15 09:31:18 GMT
postgresql_1 | 2019-04-15 09:31:18.603 GMT [125] LOG: database system is ready to accept connections
postgresql_1 | 2019-04-15 09:31:24.414 GMT [139] FATAL: password authentication failed for user "postgres"
postgresql_1 | 2019-04-15 09:31:24.414 GMT [139] DETAIL: User "postgres" has no password assigned.
postgresql_1 | Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"
postgresql_1 | 2019-04-15 09:31:27.492 GMT [140] FATAL: password authentication failed for user "postgres"
postgresql_1 | 2019-04-15 09:31:27.492 GMT [140] DETAIL: User "postgres" has no password assigned.
If you check the documentation of the docker image (https://hub.docker.com/r/bitnami/postgresql) it says that when you set POSTGRESQL_USERNAME the postgres user won't have a password assigned and you won't be able to use it to login to the db.
Use the user that you specified.