diff --git a/backup/backup.go b/backup/backup.go index 8bbd37ac4..d881a9038 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -128,7 +128,7 @@ func DoBackup() { } gplog.Info("Gathering table state information") - metadataTables, dataTables, allTables := RetrieveAndProcessTables() + metadataTables, dataTables := RetrieveAndProcessTables() dataTables, numExtOrForeignTables := GetBackupDataSet(dataTables) if len(dataTables) == 0 && !backupReport.MetadataOnly { gplog.Warn("No tables in backup set contain data. Performing metadata-only backup instead.") @@ -195,7 +195,7 @@ func DoBackup() { printDataBackupWarnings(numExtOrForeignTables) if MustGetFlagBool(options.WITH_STATS) { - backupStatistics(allTables) + backupStatistics(metadataTables) } globalTOC.WriteToFileAndMakeReadOnly(globalFPInfo.GetTOCFilePath()) diff --git a/backup/wrappers.go b/backup/wrappers.go index a976ee2d1..dc24a16ed 100644 --- a/backup/wrappers.go +++ b/backup/wrappers.go @@ -205,7 +205,7 @@ func createBackupDirectoriesOnAllHosts() { * Metadata retrieval wrapper functions */ -func RetrieveAndProcessTables() ([]Table, []Table, []Table) { +func RetrieveAndProcessTables() ([]Table, []Table) { includedRelations := GetIncludedUserTableRelations(connectionPool, IncludedRelationFqns) tableRelations := ConvertRelationsOptionsToBackup(includedRelations) @@ -215,12 +215,12 @@ func RetrieveAndProcessTables() ([]Table, []Table, []Table) { tableRelations = append(tableRelations, GetForeignTableRelations(connectionPool)...) } - allTables := ConstructDefinitionsForTables(connectionPool, tableRelations) + tables := ConstructDefinitionsForTables(connectionPool, tableRelations) - metadataTables, dataTables := SplitTablesByPartitionType(allTables, IncludedRelationFqns) + metadataTables, dataTables := SplitTablesByPartitionType(tables, IncludedRelationFqns) objectCounts["Tables"] = len(metadataTables) - return metadataTables, dataTables, allTables + return metadataTables, dataTables } func retrieveFunctions(sortables *[]Sortable, metadataMap MetadataMap) ([]Function, map[uint32]FunctionInfo) { diff --git a/end_to_end/end_to_end_suite_test.go b/end_to_end/end_to_end_suite_test.go index da4219fc7..95bd3d111 100644 --- a/end_to_end/end_to_end_suite_test.go +++ b/end_to_end/end_to_end_suite_test.go @@ -1527,6 +1527,13 @@ var _ = Describe("backup and restore end to end tests", func() { skipIfOldBackupVersionBefore("1.18.0") testhelper.AssertQueryRuns(backupConn, ` + CREATE TABLE et ( + id character varying(13), + flg smallint, + dttm timestamp without time zone, + src character varying(80) + ) WITH (appendonly='true', orientation='row', compresstype=zstd, compresslevel='3') DISTRIBUTED BY (id); + CREATE TABLE pt ( id character varying(13), flg smallint, @@ -1537,16 +1544,19 @@ var _ = Describe("backup and restore end to end tests", func() { ); INSERT INTO pt(id, flg, dttm, src) VALUES (1, 1, now(), 'val'); + INSERT INTO et(id, flg, dttm, src) VALUES (2, 2, now(), 'val'); ANALYZE pt; + ANALYZE et; ANALYZE ROOTPARTITION pt; + + ALTER TABLE pt EXCHANGE PARTITION src_mdm WITH TABLE et; `) defer testhelper.AssertQueryRuns(backupConn, - `DROP TABLE pt CASCADE;`) + `DROP TABLE et CASCADE; DROP TABLE pt CASCADE;`) timestamp := gpbackup(gpbackupPath, backupHelperPath, "--with-stats", - "--leaf-partition-data", "--backup-dir", backupDir, "--single-backup-dir") files, err := path.Glob(path.Join(backupDir, "backups/*", timestamp, "*statistics.sql")) @@ -1564,7 +1574,7 @@ var _ = Describe("backup and restore end to end tests", func() { assertPGClassStatsRestored(backupConn, restoreConn, publicSchemaTupleCounts) assertPGClassStatsRestored(backupConn, restoreConn, schema2TupleCounts) - statsQuery := fmt.Sprintf(`SELECT count(*) AS string FROM pg_statistic st left join pg_class cl on st.starelid = cl.oid left join pg_namespace nm on cl.relnamespace = nm.oid where %s;`, backup.SchemaFilterClause("nm")) + statsQuery := fmt.Sprintf(`SELECT count(*) AS string FROM pg_statistic st left join pg_class cl on st.starelid = cl.oid left join pg_namespace nm on cl.relnamespace = nm.oid where cl.relname != 'pt_1_prt_src_mdm' AND %s;`, backup.SchemaFilterClause("nm")) backupStatisticCount := dbconn.MustSelectString(backupConn, statsQuery) restoredStatisticsCount := dbconn.MustSelectString(restoreConn, statsQuery) diff --git a/integration/wrappers_test.go b/integration/wrappers_test.go index 5e41ac66e..29658406d 100644 --- a/integration/wrappers_test.go +++ b/integration/wrappers_test.go @@ -37,7 +37,7 @@ var _ = Describe("Wrappers Integration", func() { connectionPool.MustBegin(0) defer connectionPool.MustCommit(0) - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(2)) Expect(dataTables[0].Name).To(Equal("foo")) Expect(dataTables[1].Name).To(Equal(`"BAR"`)) @@ -63,7 +63,7 @@ var _ = Describe("Wrappers Integration", func() { rootCmd := &cobra.Command{} backup.DoInit(rootCmd) // initialize the ObjectCount - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(3)) Expect(dataTables[0].Name).To(Equal("thousands")) Expect(dataTables[1].Name).To(Equal("ten")) @@ -76,7 +76,7 @@ var _ = Describe("Wrappers Integration", func() { backup.DoInit(rootCmd) // initialize the ObjectCount rootCmd.Execute() - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(2)) Expect(dataTables[0].Name).To(Equal("ten")) Expect(dataTables[1].Name).To(Equal("empty")) @@ -88,7 +88,7 @@ var _ = Describe("Wrappers Integration", func() { backup.DoInit(rootCmd) // initialize the ObjectCount rootCmd.Execute() - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(2)) Expect(dataTables[0].Name).To(Equal("ten")) Expect(dataTables[1].Name).To(Equal("empty")) @@ -119,7 +119,7 @@ var _ = Describe("Wrappers Integration", func() { backup.DoInit(rootCmd) // initialize the ObjectCount rootCmd.Execute() - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(2)) Expect(dataTables[0].Name).To(Equal("thousands")) Expect(dataTables[1].Name).To(Equal("empty")) @@ -131,7 +131,7 @@ var _ = Describe("Wrappers Integration", func() { backup.DoInit(rootCmd) // initialize the ObjectCount rootCmd.Execute() - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(2)) Expect(dataTables[0].Name).To(Equal("thousands")) Expect(dataTables[1].Name).To(Equal("empty")) @@ -168,7 +168,7 @@ var _ = Describe("Wrappers Integration", func() { err := opts.ExpandIncludesForPartitions(connectionPool, rootCmd.Flags()) Expect(err).ShouldNot(HaveOccurred()) - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(2)) Expect(dataTables[0].Name).To(Equal("partition_table")) Expect(dataTables[1].Name).To(Equal("ten")) @@ -184,7 +184,7 @@ var _ = Describe("Wrappers Integration", func() { err := opts.ExpandIncludesForPartitions(connectionPool, rootCmd.Flags()) Expect(err).ShouldNot(HaveOccurred()) - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(3)) Expect(dataTables[0].Name).To(Equal("partition_table_1_prt_girls")) @@ -215,7 +215,7 @@ var _ = Describe("Wrappers Integration", func() { rootCmd := &cobra.Command{} backup.DoInit(rootCmd) // initialize the ObjectCount - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(3)) Expect(dataTables[0].Name).To(Equal("thousands")) @@ -234,7 +234,7 @@ var _ = Describe("Wrappers Integration", func() { rootCmd := &cobra.Command{} backup.DoInit(rootCmd) // initialize the ObjectCount - _, dataTables, _ := backup.RetrieveAndProcessTables() + _, dataTables := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(3)) Expect(dataTables[0].Name).To(Equal("thousands"))