Я пытаюсь клонировать базу данных из одного postgres в другой. Я использую старую версию postgres 8.1.4, новая база данных находится внутри docker контейнера, работающего под управлением Ubuntu.
Мне нужно будет скопировать полную базу данных, но для простоты сейчас я показываю ошибку в одной таблице. На текущем заполненном сервере я делаю:
pg_dump -U postgres -d cnx -t freq1_data -F c > /data/misc/luca/freq1_data.dump
, чтобы сбросить таблицу.
затем я создаю контейнер со следующим dockerfile
FROM ubuntu:18.04
RUN apt-get update -y
RUN apt-get install python3.8 -y
RUN apt-get install python3.8-venv -y
RUN apt-get install python3.8-distutils -y
RUN apt-get install python3.8-venv python3.8-dev -y
RUN apt-get install gcc -y
RUN mkdir adam
ADD /adam/ /adam/
RUN mkdir /cnx_data/
RUN python3.8 -m venv adam_env
RUN /bin/bash -c "source /adam_env/bin/activate"
RUN ./adam_env/bin/pip install -r /adam/build/requirements.txt
RUN ./adam_env/bin/pip install -e /adam/src/adam/
RUN apt-get install build-essential -y
RUN apt-get install wget -y
RUN apt-get install -y build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev
RUN apt-get install -y clang
RUN wget https://ftp.postgresql.org/pub/source/v8.1.4/postgresql-8.1.4.tar.gz
RUN tar -xzf postgresql-8.1.4.tar.gz
RUN apt-get install libreadline-dev -y
RUN cd postgresql-8.1.4 && ./configure CFLAGS="-O2" CC=clang && make && make install
RUN mkdir /usr/local/pgsql/data
RUN useradd -ms /bin/bash postgres
RUN mkdir -p /usr/local/pgsql/data/
RUN mkdir /usr/local/pgsql/log
RUN chown -R postgres /usr/local/pgsql/
USER postgres
RUN /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
COPY freq1_data.dump /cnx_data/
Из работающего контейнера, который я делаю:
postgres@c1ee3cfe5dbf:/$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data &
[1] 10
postgres@c1ee3cfe5dbf:/$ LOG: could not bind IPv6 socket: Cannot assign requested address
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: database system was shut down at 2020-04-01 18:14:57 UTC
LOG: checkpoint record is at 0/38FF90
LOG: redo record is at 0/38FF90; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 565; next OID: 10794
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready
LOG: transaction ID wrap limit is 2147484146, limited by database "postgres"
postgres@c1ee3cfe5dbf:/$ /usr/local/pgsql/bin/createdb -T template0 cnx
LOG: transaction ID wrap limit is 2147484146, limited by database "postgres"
CREATE DATABASE
postgres@c1ee3cfe5dbf:/$
postgres@c1ee3cfe5dbf:/$ /usr/local/pgsql/bin/pg_restore -U postgres -d cnx /cnx_data/freq1_data.dump
, эта последняя команда возвращает большое количество ошибок:
postgres@c1ee3cfe5dbf:/$ cat /tmp/error.log | head
pg_restore: [archiver] Error while PROCESSING TOC:
pg_restore: [archiver] Error from TOC entry 2439; 1259 2506496895 TABLE freq1_data postgres
pg_restore: [archiver] could not set search_path to "smdata": ERROR: schema "smdata" does not exist
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data_id_seq" does not exist
Command was:
CREATE TABLE freq1_data (
id integer DEFAULT nextval('freq1_data_id_seq'::regclass) NOT NULL,
measurement_point_id ...
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data" does not exist
Command was: ALTER TABLE ONLY freq1_data ALTER COLUMN cbdist_pkt_queue SET STORAGE EXTERNAL;
postgres@c1ee3cfe5dbf:/$ cat /tmp/error.log | head -n 20
pg_restore: [archiver] Error while PROCESSING TOC:
pg_restore: [archiver] Error from TOC entry 2439; 1259 2506496895 TABLE freq1_data postgres
pg_restore: [archiver] could not set search_path to "smdata": ERROR: schema "smdata" does not exist
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data_id_seq" does not exist
Command was:
CREATE TABLE freq1_data (
id integer DEFAULT nextval('freq1_data_id_seq'::regclass) NOT NULL,
measurement_point_id ...
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data" does not exist
Command was: ALTER TABLE ONLY freq1_data ALTER COLUMN cbdist_pkt_queue SET STORAGE EXTERNAL;
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data" does not exist
Я чувствую, что что-то упустил. Как определение схемы, но я не могу понять, что делать.
РЕДАКТИРОВАТЬ 1: После запуска: create schema smdata
Я получаю сообщение об ошибке:
postgres@323cadf989cf:/$ cat /tmp/error.log | head
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2439; 1259 2506496895 TABLE freq1_data postgres
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data_id_seq" does not exist
Command was:
CREATE TABLE freq1_data (
id integer DEFAULT nextval('freq1_data_id_seq'::regclass) NOT NULL,
measurement_point_id ...
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data" does not exist
Command was: ALTER TABLE ONLY freq1_data ALTER COLUMN cbdist_pkt_queue SET STORAGE EXTERNAL;
pg_restore: [archiver (db)] could not execute query: ERROR: relation "freq1_data" does not exist
postgres@323cadf989cf:/$
Похоже, он не скопировал схему из старого БД.