恢复数据库 PostgreSQL 重复行

Restore DataBase PostgreSQL duplicate lines

我正在备份和恢复系统。

使用此代码制作备份即时消息:

textInformacao.Text = "";


        Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);

        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\backup\pg_dump.exe";
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = false;
        psi.CreateNoWindow = true;
        psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -F c -b -v -f {3} {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, arquivoSaida, ConfiguracaoSistema.NomeDataBase);
        psi.UseShellExecute = false;

        p = Process.Start(psi);
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.EnableRaisingEvents = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
        p.Start();
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();

如果我得到这个文件并打开 pgAdmin,一切正常,数据库将被恢复。

使用此代码恢复 im:

textInformacao.Text = "";

        Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);

        string caminhoArquivo = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\testesigep_vs.backup";



        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\backup\pg_restore.exe";
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = false;
        psi.CreateNoWindow = true;
        psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -c -d {3} -v {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, ConfiguracaoSistema.NomeDataBase, caminhoArquivo);
        psi.UseShellExecute = false;


        p = Process.Start(psi);
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.EnableRaisingEvents = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
        p.Start();
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();

当我 运行 这段代码时,我有一个 "big problem" 所有行都是重复的。 看看我的数据库已恢复:

Database picture

看图片,看ID列有2个值相同。

我该如何解决这个问题? 为什么在 PgAdmin Restore 中没有问题,而在 c# 中却出现这个问题?

编辑::::::::::::::::::::::::::::::::: :::::::: 开始恢复

pg_restore: 连接到数据库进行恢复 pg_restore:删除数据库 sigep_vs pg_restore: [archiver (db)] 处理目录时出错: pg_restore: [archiver (db)] 来自 TOC 条目 2949 的错误; 1262 158041 数据库 sigep_vs sigep pg_restore: [archiver (db)] 无法执行查询:错误:无法删除当前打开的数据库 命令是:DROP DATABASE sigep_vs;

pg_restore: 创建数据库 "sigep_vs" pg_restore: [archiver (db)] 无法执行查询:错误:数据库 "sigep_vs" 已经存在 命令是:CREATE DATABASE sigep_vs WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C' LC_CTYPE = 'C';

Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);

        string caminhoArquivo = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\testesigep_vs.backup";

        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\backup\pg_restore.exe";
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = false;
        psi.CreateNoWindow = true;
        psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -d {3} -v {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, ConfiguracaoSistema.NomeDataBase, caminhoArquivo);
        psi.UseShellExecute = false;

        p = new Process { StartInfo = psi };

        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.EnableRaisingEvents = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
        p.Start();
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();

现在,正在工作:

Environment.SetEnvironmentVariable("PGPASSWORD", ConfiguracaoSistema.Password);

        string caminhoArquivo = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\testesigep_vs.backup";

        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = @Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\backup\pg_restore.exe";
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = false;
        psi.CreateNoWindow = true;
        psi.Arguments = string.Format(@"-h {0} -p {1} -U {2} -d {3} -v {4}", caminhoServidor, ConfiguracaoSistema.Port, ConfiguracaoSistema.UserName, ConfiguracaoSistema.NomeDataBase, caminhoArquivo);
        psi.UseShellExecute = false;

        p = new Process { StartInfo = psi };

        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.EnableRaisingEvents = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += e.Data + "\r\n"; textInformacao.ScrollToEnd(); })); });
        p.Exited += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { textInformacao.Text += "Processo Finalizado!"; })); };
        p.Start();
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();`