diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 8d5eac4791..c95287104e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -657,7 +657,14 @@ pg_get_viewdef(PG_FUNCTION_ARGS)

        prettyFlags = PRETTYFLAG_INDENT;

+       /*
+        * Setup the snapshot to get the catalog information using this snapshot
+        * which will prevent accessing a future catalog data which has occurred
+        * due to concurrent catalog change.
+        */
+       SetupHistoricSnapshot(GetActiveSnapshot(), NULL);
        res = pg_get_viewdef_worker(viewoid, prettyFlags, WRAP_COLUMN_DEFAULT);
+       TeardownHistoricSnapshot(false);

        if (res == NULL)
                PG_RETURN_NULL();
@@ -1154,10 +1161,17 @@ pg_get_indexdef(PG_FUNCTION_ARGS)

        prettyFlags = PRETTYFLAG_INDENT;

+       /*
+        * Setup the snapshot to get the catalog information using this snapshot
+        * which will prevent accessing a future catalog data which has occurred
+        * due to concurrent catalog change.
+        */
+       SetupHistoricSnapshot(GetActiveSnapshot(), NULL);
        res = pg_get_indexdef_worker(indexrelid, 0, NULL,
                                                                 false, false,
                                                                 false, false,
                                                                 prettyFlags, true);
+       TeardownHistoricSnapshot(false);

        if (res == NULL)
                PG_RETURN_NULL();