恢复DataBase PostgreSQL重复行

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

我将备份和还原到系统。

使用此代码进行make Backup:

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,一切都会正确,数据库将被恢复。

使用此代码进行make restore:

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();

当我运行这段代码时,我有一个“大问题”,所有行都是重复的。看我的数据库恢复:

Database picture

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

我怎么解决这个问题?为什么在PgAdmin Restore中没有问题,在c#中出现这个问题?

编辑::::::::::::::::::::::::::::::::::::::::::::::::: :::开始还原

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

pg_restore:创建DATABASE“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();
c# wpf postgresql restore
1个回答
0
投票

现在,正在工作:

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();`
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.