diff --git a/backup/backup.go b/backup/backup.go index 4c29768dd..80edede48 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -128,7 +128,7 @@ func DoBackup() { } gplog.Info("Gathering table state information") - metadataTables, dataTables := RetrieveAndProcessTables() + metadataTables, dataTables, allTables := 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(metadataTables) + backupStatistics(allTables) } globalTOC.WriteToFileAndMakeReadOnly(globalFPInfo.GetTOCFilePath()) diff --git a/backup/wrappers.go b/backup/wrappers.go index 4c77e9a27..c956ef0f7 100644 --- a/backup/wrappers.go +++ b/backup/wrappers.go @@ -203,7 +203,7 @@ func createBackupDirectoriesOnAllHosts() { * Metadata retrieval wrapper functions */ -func RetrieveAndProcessTables() ([]Table, []Table) { +func RetrieveAndProcessTables() ([]Table, []Table, []Table) { includedRelations := GetIncludedUserTableRelations(connectionPool, IncludedRelationFqns) tableRelations := ConvertRelationsOptionsToBackup(includedRelations) @@ -213,12 +213,12 @@ func RetrieveAndProcessTables() ([]Table, []Table) { tableRelations = append(tableRelations, GetForeignTableRelations(connectionPool)...) } - tables := ConstructDefinitionsForTables(connectionPool, tableRelations) + allTables := ConstructDefinitionsForTables(connectionPool, tableRelations) - metadataTables, dataTables := SplitTablesByPartitionType(tables, IncludedRelationFqns) + metadataTables, dataTables := SplitTablesByPartitionType(allTables, IncludedRelationFqns) objectCounts["Tables"] = len(metadataTables) - return metadataTables, dataTables + return metadataTables, dataTables, allTables } 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 d2ce960df..79ba299d7 100644 --- a/end_to_end/end_to_end_suite_test.go +++ b/end_to_end/end_to_end_suite_test.go @@ -1605,13 +1605,6 @@ 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, @@ -1622,19 +1615,16 @@ 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 et CASCADE; DROP TABLE pt CASCADE;`) + `DROP TABLE pt CASCADE;`) outputBkp := gpbackup(gpbackupPath, backupHelperPath, "--with-stats", + "--leaf-partition-data", "--backup-dir", backupDir, "--single-backup-dir") timestamp := getBackupTimestamp(string(outputBkp)) @@ -1654,7 +1644,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 cl.relname != 'pt_1_prt_src_mdm' AND %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 %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 89ecfe738..858d5210d 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"`)) @@ -67,7 +67,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, 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")) @@ -87,7 +87,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, 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")) @@ -105,7 +105,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, 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")) @@ -142,7 +142,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, 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")) @@ -160,7 +160,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, 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")) @@ -201,7 +201,7 @@ var _ = Describe("Wrappers Integration", func() { err = backup.ExpandIncludesForPartitions(connectionPool, subject, includeOids, backupCmdFlags) 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")) @@ -221,7 +221,7 @@ var _ = Describe("Wrappers Integration", func() { err = backup.ExpandIncludesForPartitions(connectionPool, subject, includeOids, backupCmdFlags) 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")) @@ -256,7 +256,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, dataTables := backup.RetrieveAndProcessTables() + _, dataTables, _ := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(3)) Expect(dataTables[0].Name).To(Equal("thousands")) @@ -279,7 +279,7 @@ var _ = Describe("Wrappers Integration", func() { Expect(err).To(Not(HaveOccurred())) backup.ValidateAndProcessFilterLists(subject) - _, dataTables := backup.RetrieveAndProcessTables() + _, dataTables, _ := backup.RetrieveAndProcessTables() Expect(len(dataTables)).To(Equal(3)) Expect(dataTables[0].Name).To(Equal("thousands"))