Восстановление базы данных PostgreSQL дубликаты строк - PullRequest
0 голосов
/ 12 апреля 2019

Я делаю Backup и Restore to system.

Для резервного копирования я использую этот код:

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

когда я запускаю этот код, у меня возникает «большая проблема», все строки дублируются. смотри мою базу восстановили:

База данных изображения

посмотрите изображение, столбец идентификатора взгляда имеет 2 одинаковых значения.

Как я могу решить эту проблему? Почему в PgAdmin Restore нет проблем, а в c # эта проблема?

EDIT :::::::::::::::::::::::::::::::::::::::::::::: :::::: Начать восстановление

pg_restore: подключение к базе данных для восстановления pg_restore: удаление базы данных sigep_vs pg_restore: [archiver (db)] Ошибка при обработке содержимого: pg_restore: [archiver (db)] Ошибка записи ТОС 2949; 1262 158041 БАЗА ДАННЫХ sigep_vs sigep pg_restore: [archiver (db)] не смог выполнить запрос: ERROR: не удалось удалить текущую открытую базу данных Команда была: 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();

1 Ответ

0 голосов
/ 12 апреля 2019

Сейчас работает:

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