尝试克隆postgres数据库(pg_dump,pg_restore)时出错

问题描述 投票:0回答:1

我正在尝试将数据库从一个postgres克隆到另一个。我正在使用旧版本的Postgres 8.1.4,新数据库位于运行ubuntu的docker容器中。

我需要复制完整的数据库,但是为了简单起见,现在在单个表上显示错误。在当前填充的服务器上,执行:

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:/$ 

似乎它没有从旧数据库复制架构。

postgresql docker pg-dump
1个回答
0
投票

您也应该转储序列:

pg_dump -U postgres -t freq1_data_id_seq -t freq1_data -F c -f /data/misc/luca/freq1_data.dump cnx
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.