My problem:
When importing the database it seems (now) that the database is dropped and can then not be connected. (That did always work before. Import script seems not to be changed).
The whole thing happens within a docker container. Which on my first guess is not the problem.
Creation of the SQL used to import:
pg_dump --host=$HOSTNAME --create --clean --format=plain --username=$USERNAME --file=$DIR_BACKUPS/$DATABASE-latest.sql $DATABASE
(The $VARIABLES are filled from the outside.)
What happens:
The exported SQL I pass to docker for importing:
cat mydbname-latest.sql | docker exec -i test-postgres-9.6 psql -U postgres
When the script runs it seems that the database is being dropped but cannot be connected to it later. I guess the database creation failed. It did exist and was connectable on the beginning before running the dumb.
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
DROP DATABASE
ERROR: invalid locale name: "de_DE.UTF-8"
ERROR: database "mydbname" does not exist
\connect: FATAL: database "mydbname" does not exist
Why isn't there a script failure on database creation failure, which is invisible?
Why does the ALTER DATABASE statement run through (if the database was not created)?
Here is the beginning of created SQL from the export.
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.6.10
-- Dumped by pg_dump version 9.6.10
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
DROP DATABASE mydbname;
--
-- Name: mydbname; Type: DATABASE; Schema: -; Owner: postgres
--
CREATE DATABASE mydbname WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'de_DE.UTF-8' LC_CTYPE = 'de_DE.UTF-8';
ALTER DATABASE mydbname OWNER TO postgres;
\connect mydbname
...
the \connect mydbname line is subject to throw the error.
If anyone needs more informations let me know. I appreciate your help.
Script for creating docker container from image:
docker run -d --name $DOCKER_CONTAINER_NAME -e POSTGRES_DB=$POSTGRES_DATABASE_NAME -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -p $POSTGRES_PORT:5432 -v $POSTGRES_DATA:/var/lib/postgresql/data $DOCKER_IMAGE
with these variables set:
DOCKER_CONTAINER_NAME=test-postgres-9.6
DOCKER_IMAGE=test/postgres:9.6
POSTGRES_DATABASE_NAME=mydbname
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_PORT=5402
POSTGRES_DATA=/Users/Itsme/docker/test/psql-data