Issue creating backup with PgSqlDump
Posted: Fri 21 Oct 2011 02:32
Hi, (using vb.net 2010, Devart.data.PostgreSql 5.50.228.0, PostgreSql 9.0.4)
I’m unable to use the pgSqlDump routine to create a file that I can then use to import back into the database. The issue is not with the restore routine (using the PgSqlScript command) as I’m able to call pg_dump.exe directly and create a backup file that works great when I go to import it back in. The issue is in the file that gets created using PgSqlDump. My guess is that I’m not doing something right so I will try and be as detailed as possible.
When I call Pg_Dump.exe directly, I use the following command line:
Where
This creates my backup file
I then use the following code to import the backup file. This replaces whatever currently exists in the database:
This works great.
So instead of calling Pg_Dump.exe directly I want to use PgSqlDump to create the same file.
So here is the code I’m using:
The first indication of a problem is that the file created with PgSqlDump is half the size of the file created with pg_Dump.exe. When I run this file through the same routine as shown above it errors out, stating that various relations (tables) don’t exist. The table it claims doesn’t exist varies from backup to backup, even though the database that got backed up is identical each time.
So I’m kind of at a loss as to how to resolve this. Any help would be appreciated. Let me know if I can provide any other information.
Regards,
I’m unable to use the pgSqlDump routine to create a file that I can then use to import back into the database. The issue is not with the restore routine (using the PgSqlScript command) as I’m able to call pg_dump.exe directly and create a backup file that works great when I go to import it back in. The issue is in the file that gets created using PgSqlDump. My guess is that I’m not doing something right so I will try and be as detailed as possible.
When I call Pg_Dump.exe directly, I use the following command line:
Code: Select all
System.Diagnostics.Process.Start(strPGDumpCommand, strParams)
Code: Select all
strPgDumpCommand = "C:\Program Files (x86)\PostgreSQL\9.0\bin\pg_dump.exe "
strParameters = "--file="c:\users\public\documents\DD3\Backup\DD3_000_000_20111020_070742.pg" --username="postgres" --no-password --disable-dollar-quoting --format=plain --inserts --column-inserts "dd3_000""
I then use the following code to import the backup file. This replaces whatever currently exists in the database:
Code: Select all
Dim strStreamRestore As New StreamReader(gclsSession.App_BackupFolder & "\" & mstrBackupFile)
conn = gclsSession.GetDataConnection(True, True)
sqlText = "DROP DATABASE """ & gclsSession.pg_DatabaseName & """;"
pgCommand = conn.CreateCommand()
pgCommand.CommandText = sqlText
pgCommand.ExecuteScalar()
conn.Close()
sqlText = "CREATE DATABASE """ & gclsSession.pg_DatabaseName & """"
sqlText = sqlText & " With OWNER = postgres"
sqlText = sqlText & " ENCODING = 'UTF8'"
sqlText = sqlText & " TABLESPACE = pg_default"
sqlText = sqlText & " LC_COLLATE = 'English_United States.1252'"
sqlText = sqlText & " LC_CTYPE = 'English_United States.1252'"
sqlText = sqlText & " CONNECTION LIMIT = -1;"
conn.Open()
pgCommand = conn.CreateCommand()
pgCommand.CommandText = sqlText
pgCommand.ExecuteScalar()
conn.Close()
gclsSession.CloseDataConnection()
conn = gclsSession.GetDataConnection(True, False)
sqlText = strStreamRestore.ReadToEnd()
strStreamRestore.Close()
pgScript = New PgSqlScript(sqlText, conn)
pgScript.Execute()
conn.Close()
So instead of calling Pg_Dump.exe directly I want to use PgSqlDump to create the same file.
So here is the code I’m using:
Code: Select all
Dim pgDump As PgSqlDump = New PgSqlDump
pgDump.Connection = gclsSession.GetDataConnection()
pgDump.ObjectTypes = PgSqlDumpObjects.All - PgSqlDumpObjects.Languages
pgDump.IncludeDrop = False
pgDump.IncludeBlob = True
pgDump.QuoteIdentifier = False
pgDump.Backup()
Dim stream As StreamWriter = New StreamWriter(gclsSession.App_BackupFolder & "\" & strFileName)
stream.WriteLine(pgDump.DumpText)
stream.Close()
stream.Dispose()
stream = Nothing
So I’m kind of at a loss as to how to resolve this. Any help would be appreciated. Let me know if I can provide any other information.
Regards,