diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index e488f5e234..4cd4354278 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -554,17 +554,15 @@ report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc,
 						   BlockNumber blkno, OffsetNumber offnum,
 						   AttrNumber attnum, char *msg)
 {
-	Datum		values[HEAPCHECK_RELATION_COLS];
-	bool		nulls[HEAPCHECK_RELATION_COLS];
+	Datum		values[HEAPCHECK_RELATION_COLS] = {0};
+	bool		nulls[HEAPCHECK_RELATION_COLS] = {0};
 	HeapTuple	tuple;
 
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
 	values[0] = Int64GetDatum(blkno);
 	values[1] = Int32GetDatum(offnum);
 	values[2] = Int32GetDatum(attnum);
-	nulls[2] = (attnum < 0);
 	values[3] = CStringGetTextDatum(msg);
+	nulls[2] = (attnum < 0);
 
 	/*
 	 * In principle, there is nothing to prevent a scan over a large, highly
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index d42e4e9628..d4b1c76303 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -26,9 +26,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 			   double *indexPages)
 {
 	IndexOptInfo *index = path->indexinfo;
-	GenericCosts costs;
-
-	MemSet(&costs, 0, sizeof(costs));
+	GenericCosts costs = {0};
 
 	/* We have to visit all index tuples anyway */
 	costs.numIndexTuples = index->tuples;
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 879276e6de..f4c959ecab 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -202,7 +202,7 @@ brin_page_items(PG_FUNCTION_ARGS)
 	for (;;)
 	{
 		Datum		values[7];
-		bool		nulls[7];
+		bool		nulls[7] = {0};
 
 		/*
 		 * This loop is called once for every attribute of every tuple in the
@@ -230,8 +230,6 @@ brin_page_items(PG_FUNCTION_ARGS)
 		else
 			attno++;
 
-		MemSet(nulls, 0, sizeof(nulls));
-
 		if (unusedItem)
 		{
 			values[0] = UInt16GetDatum(offset);
@@ -334,7 +332,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
 	BrinMetaPageData *meta;
 	TupleDesc	tupdesc;
 	Datum		values[4];
-	bool		nulls[4];
+	bool		nulls[4] = {0};
 	HeapTuple	htup;
 
 	if (!superuser())
@@ -354,7 +352,6 @@ brin_metapage_info(PG_FUNCTION_ARGS)
 
 	/* Extract values from the metapage */
 	meta = (BrinMetaPageData *) PageGetContents(page);
-	MemSet(nulls, 0, sizeof(nulls));
 	values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
 	values[1] = Int32GetDatum(meta->brinVersion);
 	values[2] = Int32GetDatum(meta->pagesPerRange);
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index 5287dbe1a3..81815392d7 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -238,7 +238,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
 	Page		page;
 	int			j;
 	Datum		values[9];
-	bool		nulls[9];
+	bool		nulls[9] = {0};
 	HashPageStat stat;
 	HeapTuple	tuple;
 	TupleDesc	tupleDesc;
@@ -261,8 +261,6 @@ hash_page_stats(PG_FUNCTION_ARGS)
 		elog(ERROR, "return type must be a row type");
 	tupleDesc = BlessTupleDesc(tupleDesc);
 
-	MemSet(nulls, 0, sizeof(nulls));
-
 	j = 0;
 	values[j++] = Int32GetDatum(stat.live_items);
 	values[j++] = Int32GetDatum(stat.dead_items);
@@ -303,7 +301,7 @@ hash_page_items(PG_FUNCTION_ARGS)
 	Page		page;
 	Datum		result;
 	Datum		values[3];
-	bool		nulls[3];
+	bool		nulls[3] = {0};
 	uint32		hashkey;
 	HeapTuple	tuple;
 	FuncCallContext *fctx;
@@ -361,8 +359,6 @@ hash_page_items(PG_FUNCTION_ARGS)
 
 		itup = (IndexTuple) PageGetItem(uargs->page, id);
 
-		MemSet(nulls, 0, sizeof(nulls));
-
 		j = 0;
 		values[j++] = Int32GetDatum((int32) uargs->offset);
 		values[j++] = PointerGetDatum(&itup->t_tid);
@@ -409,7 +405,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
 	int			i,
 				j;
 	Datum		values[3];
-	bool		nulls[3];
+	bool		nulls[3] = {0};
 	uint32	   *freep;
 
 	if (!superuser())
@@ -495,8 +491,6 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
 		elog(ERROR, "return type must be a row type");
 	tupleDesc = BlessTupleDesc(tupleDesc);
 
-	MemSet(nulls, 0, sizeof(nulls));
-
 	j = 0;
 	values[j++] = Int64GetDatum((int64) bitmapblkno);
 	values[j++] = Int32GetDatum(bitmapbit);
@@ -526,7 +520,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
 	int			i,
 				j;
 	Datum		values[16];
-	bool		nulls[16];
+	bool		nulls[16] = {0};
 	Datum		spares[HASH_MAX_SPLITPOINTS];
 	Datum		mapp[HASH_MAX_BITMAPS];
 
@@ -544,8 +538,6 @@ hash_metapage_info(PG_FUNCTION_ARGS)
 
 	metad = HashPageGetMeta(page);
 
-	MemSet(nulls, 0, sizeof(nulls));
-
 	j = 0;
 	values[j++] = Int64GetDatum((int64) metad->hashm_magic);
 	values[j++] = Int64GetDatum((int64) metad->hashm_version);
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index a654234c6b..952f5ed57e 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -181,13 +181,11 @@ heap_page_items(PG_FUNCTION_ARGS)
 		Datum		result;
 		ItemId		id;
 		Datum		values[14];
-		bool		nulls[14];
+		bool		nulls[14] = {0};
 		uint16		lp_offset;
 		uint16		lp_flags;
 		uint16		lp_len;
 
-		memset(nulls, 0, sizeof(nulls));
-
 		/* Extract information from the line pointer */
 
 		id = PageGetItemId(page, inter_call_data->offset);
@@ -507,8 +505,8 @@ Datum
 heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
 {
 #define HEAP_TUPLE_INFOMASK_COLS 2
-	Datum		values[HEAP_TUPLE_INFOMASK_COLS];
-	bool		nulls[HEAP_TUPLE_INFOMASK_COLS];
+	Datum		values[HEAP_TUPLE_INFOMASK_COLS] = {0};
+	bool		nulls[HEAP_TUPLE_INFOMASK_COLS] = {0};
 	uint16		t_infomask = PG_GETARG_INT16(0);
 	uint16		t_infomask2 = PG_GETARG_INT16(1);
 	int			cnt = 0;
@@ -530,10 +528,6 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
 	bitcnt = pg_popcount((const char *) &t_infomask, sizeof(uint16)) +
 		pg_popcount((const char *) &t_infomask2, sizeof(uint16));
 
-	/* Initialize values and NULL flags arrays */
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	/* If no flags, return a set of empty arrays */
 	if (bitcnt <= 0)
 	{
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index 13eee4a137..ee20e9b085 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -814,12 +814,11 @@ apw_detach_shmem(int code, Datum arg)
 static void
 apw_start_leader_worker(void)
 {
-	BackgroundWorker worker;
+	BackgroundWorker worker = {0};
 	BackgroundWorkerHandle *handle;
 	BgwHandleStatus status;
 	pid_t		pid;
 
-	MemSet(&worker, 0, sizeof(BackgroundWorker));
 	worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
 	worker.bgw_start_time = BgWorkerStart_ConsistentState;
 	strcpy(worker.bgw_library_name, "pg_prewarm");
@@ -856,10 +855,9 @@ apw_start_leader_worker(void)
 static void
 apw_start_database_worker(void)
 {
-	BackgroundWorker worker;
+	BackgroundWorker worker = {0};
 	BackgroundWorkerHandle *handle;
 
-	MemSet(&worker, 0, sizeof(BackgroundWorker));
 	worker.bgw_flags =
 		BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
 	worker.bgw_start_time = BgWorkerStart_ConsistentState;
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 4acfddcdb8..b4d4231dc6 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1854,8 +1854,8 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
 {
 	pgssGlobalStats stats;
 	TupleDesc	tupdesc;
-	Datum		values[PG_STAT_STATEMENTS_INFO_COLS];
-	bool		nulls[PG_STAT_STATEMENTS_INFO_COLS];
+	Datum		values[PG_STAT_STATEMENTS_INFO_COLS] = {0};
+	bool		nulls[PG_STAT_STATEMENTS_INFO_COLS] = {0};
 
 	if (!pgss || !pgss_hash)
 		ereport(ERROR,
@@ -1866,9 +1866,6 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
 
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	/* Read global statistics for pg_stat_statements */
 	{
 		volatile pgssSharedState *s = (volatile pgssSharedState *) pgss;
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 58d32ba946..a155d4c13d 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -905,7 +905,7 @@ static void
 transformGraph(TrgmNFA *trgmNFA)
 {
 	HASHCTL		hashCtl;
-	TrgmStateKey initkey;
+	TrgmStateKey initkey = {0};
 	TrgmState  *initstate;
 	ListCell   *lc;
 
@@ -926,7 +926,6 @@ transformGraph(TrgmNFA *trgmNFA)
 	trgmNFA->nstates = 0;
 
 	/* Create initial state: ambiguous prefix, NFA's initial state */
-	MemSet(&initkey, 0, sizeof(initkey));
 	initkey.prefix.colors[0] = COLOR_UNKNOWN;
 	initkey.prefix.colors[1] = COLOR_UNKNOWN;
 	initkey.nstate = pg_reg_getinitialstate(trgmNFA->regex);
@@ -1014,22 +1013,19 @@ processState(TrgmNFA *trgmNFA, TrgmState *state)
  *
  * Note that we don't generate any actual arcs here.  addArcs will do that
  * later, after we have identified all the enter keys for this state.
+ *
+ * Ensure any pad bytes in destKey are zero, since it may get used as a
+ * hashtable key by getState.
  */
 static void
 addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
 {
 	regex_arc_t *arcs;
-	TrgmStateKey destKey;
+	TrgmStateKey destKey = {0};
 	ListCell   *cell;
 	int			i,
 				arcsCount;
 
-	/*
-	 * Ensure any pad bytes in destKey are zero, since it may get used as a
-	 * hashtable key by getState.
-	 */
-	MemSet(&destKey, 0, sizeof(destKey));
-
 	/*
 	 * Compare key to each existing enter key of the state to check for
 	 * redundancy.  We can drop either old key(s) or the new key if we find
@@ -1195,22 +1191,19 @@ addKeyToQueue(TrgmNFA *trgmNFA, TrgmStateKey *key)
 
 /*
  * Add outgoing arcs from given state, whose enter keys are all now known.
+ *
+ * Ensure any pad bytes in destKey are zero, since it may get used as a
+ * hashtable key by getState.
  */
 static void
 addArcs(TrgmNFA *trgmNFA, TrgmState *state)
 {
-	TrgmStateKey destKey;
+	TrgmStateKey destKey = {0};
 	ListCell   *cell;
 	regex_arc_t *arcs;
 	int			arcsCount,
 				i;
 
-	/*
-	 * Ensure any pad bytes in destKey are zero, since it may get used as a
-	 * hashtable key by getState.
-	 */
-	MemSet(&destKey, 0, sizeof(destKey));
-
 	/*
 	 * Iterate over enter keys associated with this expanded-graph state. This
 	 * includes both the state's own stateKey, and any enter keys we added to
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 4e2e9ea9bb..a95f73ec79 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -75,7 +75,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
 	Buffer		vmbuffer = InvalidBuffer;
 	TupleDesc	tupdesc;
 	Datum		values[2];
-	bool		nulls[2];
+	bool		nulls[2] = {0};
 
 	rel = relation_open(relid, AccessShareLock);
 
@@ -88,7 +88,6 @@ pg_visibility_map(PG_FUNCTION_ARGS)
 				 errmsg("invalid block number")));
 
 	tupdesc = pg_visibility_tupdesc(false, false);
-	MemSet(nulls, 0, sizeof(nulls));
 
 	mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
 	if (vmbuffer != InvalidBuffer)
@@ -117,7 +116,7 @@ pg_visibility(PG_FUNCTION_ARGS)
 	Page		page;
 	TupleDesc	tupdesc;
 	Datum		values[3];
-	bool		nulls[3];
+	bool		nulls[3] = {0};
 
 	rel = relation_open(relid, AccessShareLock);
 
@@ -130,7 +129,6 @@ pg_visibility(PG_FUNCTION_ARGS)
 				 errmsg("invalid block number")));
 
 	tupdesc = pg_visibility_tupdesc(false, true);
-	MemSet(nulls, 0, sizeof(nulls));
 
 	mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
 	if (vmbuffer != InvalidBuffer)
@@ -188,10 +186,9 @@ pg_visibility_map_rel(PG_FUNCTION_ARGS)
 	if (info->next < info->count)
 	{
 		Datum		values[3];
-		bool		nulls[3];
+		bool		nulls[3] = {0};
 		HeapTuple	tuple;
 
-		MemSet(nulls, 0, sizeof(nulls));
 		values[0] = Int64GetDatum(info->next);
 		values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
 		values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -233,10 +230,9 @@ pg_visibility_rel(PG_FUNCTION_ARGS)
 	if (info->next < info->count)
 	{
 		Datum		values[4];
-		bool		nulls[4];
+		bool		nulls[4] = {0};
 		HeapTuple	tuple;
 
-		MemSet(nulls, 0, sizeof(nulls));
 		values[0] = Int64GetDatum(info->next);
 		values[1] = BoolGetDatum((info->bits[info->next] & (1 << 0)) != 0);
 		values[2] = BoolGetDatum((info->bits[info->next] & (1 << 1)) != 0);
@@ -266,7 +262,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
 	int64		all_frozen = 0;
 	TupleDesc	tupdesc;
 	Datum		values[2];
-	bool		nulls[2];
+	bool		nulls[2] = {0};
 
 	rel = relation_open(relid, AccessShareLock);
 
@@ -300,7 +296,6 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
 	TupleDescInitEntry(tupdesc, (AttrNumber) 2, "all_frozen", INT8OID, -1, 0);
 	tupdesc = BlessTupleDesc(tupdesc);
 
-	MemSet(nulls, 0, sizeof(nulls));
 	values[0] = Int64GetDatum(all_visible);
 	values[1] = Int64GetDatum(all_frozen);
 
diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index a082dfb331..9081787634 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -229,8 +229,8 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
 {
 #define PG_GET_WAL_RECORD_INFO_COLS 11
 	Datum		result;
-	Datum		values[PG_GET_WAL_RECORD_INFO_COLS];
-	bool		nulls[PG_GET_WAL_RECORD_INFO_COLS];
+	Datum		values[PG_GET_WAL_RECORD_INFO_COLS] = {0};
+	bool		nulls[PG_GET_WAL_RECORD_INFO_COLS] = {0};
 	XLogRecPtr	lsn;
 	XLogRecPtr	curr_lsn;
 	XLogRecPtr	first_record;
@@ -266,9 +266,6 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
 				 errmsg("could not read WAL at %X/%X",
 						LSN_FORMAT_ARGS(first_record))));
 
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	GetWALRecordInfo(xlogreader, first_record, values, nulls,
 					 PG_GET_WAL_RECORD_INFO_COLS);
 
@@ -334,8 +331,8 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
 	XLogRecPtr	first_record;
 	XLogReaderState *xlogreader;
 	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
-	Datum		values[PG_GET_WAL_RECORDS_INFO_COLS];
-	bool		nulls[PG_GET_WAL_RECORDS_INFO_COLS];
+	Datum		values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
+	bool		nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
 
 	SetSingleFuncCall(fcinfo, 0);
 
@@ -343,9 +340,6 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
 
 	Assert(xlogreader);
 
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	while (ReadNextXLogRecord(xlogreader, first_record) &&
 		   xlogreader->EndRecPtr <= end_lsn)
 	{
@@ -556,17 +550,15 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
 #define PG_GET_WAL_STATS_COLS 9
 	XLogRecPtr	first_record;
 	XLogReaderState *xlogreader;
-	XLogStats	stats;
+	XLogStats	stats = {0};
 	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
-	Datum		values[PG_GET_WAL_STATS_COLS];
-	bool		nulls[PG_GET_WAL_STATS_COLS];
+	Datum		values[PG_GET_WAL_STATS_COLS] = {0};
+	bool		nulls[PG_GET_WAL_STATS_COLS] = {0};
 
 	SetSingleFuncCall(fcinfo, 0);
 
 	xlogreader = InitXLogReaderState(start_lsn, &first_record);
 
-	MemSet(&stats, 0, sizeof(stats));
-
 	while (ReadNextXLogRecord(xlogreader, first_record) &&
 		   xlogreader->EndRecPtr <= end_lsn)
 	{
@@ -578,9 +570,6 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
 	pfree(xlogreader->private_data);
 	XLogReaderFree(xlogreader);
 
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	GetXLogSummaryStats(&stats, rsinfo, values, nulls,
 						PG_GET_WAL_STATS_COLS,
 						stats_per_record);
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index e1048e47ff..d69ac1c93d 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -575,7 +575,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
 	HeapTuple	tuple;
 	TupleDesc	tupleDesc;
 	Datum		values[8];
-	bool		nulls[8];
+	bool		nulls[8] = {0};
 	Buffer		metabuf;
 	HashMetaPage metap;
 	float8		free_percent;
@@ -697,7 +697,6 @@ pgstathashindex(PG_FUNCTION_ARGS)
 	/*
 	 * Build and return the tuple
 	 */
-	MemSet(nulls, 0, sizeof(nulls));
 	values[0] = Int32GetDatum(stats.version);
 	values[1] = Int64GetDatum((int64) stats.bucket_pages);
 	values[2] = Int64GetDatum((int64) stats.overflow_pages);
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index cffb6f8310..939d114f02 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1678,8 +1678,8 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
 	while ((entry = (ConnCacheEntry *) hash_seq_search(&scan)))
 	{
 		ForeignServer *server;
-		Datum		values[POSTGRES_FDW_GET_CONNECTIONS_COLS];
-		bool		nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS];
+		Datum		values[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
+		bool		nulls[POSTGRES_FDW_GET_CONNECTIONS_COLS] = {0};
 
 		/* We only look for open remote connections */
 		if (!entry->conn)
@@ -1687,9 +1687,6 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
 
 		server = GetForeignServerExtended(entry->serverid, FSV_MISSING_OK);
 
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
-
 		/*
 		 * The foreign server may have been dropped in current explicit
 		 * transaction. It is not possible to drop the server from another
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 955a428e3d..cfac539008 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3307,7 +3307,7 @@ estimate_path_cost_size(PlannerInfo *root,
 		{
 			RelOptInfo *outerrel = fpinfo->outerrel;
 			PgFdwRelationInfo *ofpinfo;
-			AggClauseCosts aggcosts;
+			AggClauseCosts aggcosts = {0};
 			double		input_rows;
 			int			numGroupCols;
 			double		numGroups = 1;
@@ -3331,7 +3331,6 @@ estimate_path_cost_size(PlannerInfo *root,
 			input_rows = ofpinfo->rows;
 
 			/* Collect statistics about aggregates for estimating costs. */
-			MemSet(&aggcosts, 0, sizeof(AggClauseCosts));
 			if (root->parse->hasAggs)
 			{
 				get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &aggcosts);
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index e308228bde..6452111e19 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -127,9 +127,8 @@ typedef struct crosstab_cat_desc
 
 #define crosstab_HashTableLookup(HASHTAB, CATNAME, CATDESC) \
 do { \
-	crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN]; \
+	crosstab_HashEnt *hentry; char key[MAX_CATNAME_LEN] = {0}; \
 	\
-	MemSet(key, 0, MAX_CATNAME_LEN); \
 	snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATNAME); \
 	hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
 										 key, HASH_FIND, NULL); \
@@ -141,9 +140,8 @@ do { \
 
 #define crosstab_HashTableInsert(HASHTAB, CATDESC) \
 do { \
-	crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN]; \
+	crosstab_HashEnt *hentry; bool found; char key[MAX_CATNAME_LEN] = {0}; \
 	\
-	MemSet(key, 0, MAX_CATNAME_LEN); \
 	snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
 	hentry = (crosstab_HashEnt*) hash_search(HASHTAB, \
 										 key, HASH_ENTER, &found); \
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index ad489e33b3..14fe2d76c4 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -717,7 +717,7 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
 	Buffer		buffer;
 	Page		page;
 	BTPageOpaque pageop;
-	IndexTupleData trunctuple;
+	IndexTupleData trunctuple = {0};
 
 	/*
 	 * In normal operation, we would lock all the pages this WAL record
@@ -780,7 +780,6 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
 	 * Construct a dummy high key item that points to top parent page (value
 	 * is InvalidBlockNumber when the top parent page is the leaf page itself)
 	 */
-	MemSet(&trunctuple, 0, sizeof(IndexTupleData));
 	trunctuple.t_info = sizeof(IndexTupleData);
 	BTreeTupleSetTopParent(&trunctuple, xlrec->topparent);
 
@@ -898,7 +897,7 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
 		 * we'll delete in the subtree undergoing deletion.
 		 */
 		Buffer		leafbuf;
-		IndexTupleData trunctuple;
+		IndexTupleData trunctuple = {0};
 
 		Assert(!isleaf);
 
@@ -915,7 +914,6 @@ btree_xlog_unlink_page(uint8 info, XLogReaderState *record)
 		pageop->btpo_cycleid = 0;
 
 		/* Add a dummy hikey item */
-		MemSet(&trunctuple, 0, sizeof(IndexTupleData));
 		trunctuple.t_info = sizeof(IndexTupleData);
 		BTreeTupleSetTopParent(&trunctuple, xlrec->leaftopparent);
 
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 41b31c5c6f..dd330ce260 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -781,7 +781,7 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
 		GlobalTransaction gxact = &status->array[status->currIdx++];
 		PGPROC	   *proc = &ProcGlobal->allProcs[gxact->pgprocno];
 		Datum		values[5];
-		bool		nulls[5];
+		bool		nulls[5] = {0};
 		HeapTuple	tuple;
 		Datum		result;
 
@@ -791,9 +791,6 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
 		/*
 		 * Form tuple with appropriate data.
 		 */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
-
 		values[0] = TransactionIdGetDatum(proc->xid);
 		values[1] = CStringGetTextDatum(gxact->gid);
 		values[2] = TimestampTzGetDatum(gxact->prepared_at);
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 02bd919ff6..ed79e3d9a3 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -107,7 +107,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
 #define PG_STOP_BACKUP_V2_COLS 3
 	TupleDesc	tupdesc;
 	Datum		values[PG_STOP_BACKUP_V2_COLS];
-	bool		nulls[PG_STOP_BACKUP_V2_COLS];
+	bool		nulls[PG_STOP_BACKUP_V2_COLS] = {0};
 
 	bool		waitforarchive = PG_GETARG_BOOL(0);
 	XLogRecPtr	stoppoint;
@@ -117,9 +117,6 @@ pg_backup_stop(PG_FUNCTION_ARGS)
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
 		elog(ERROR, "return type must be a row type");
 
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	if (status != SESSION_BACKUP_RUNNING)
 		ereport(ERROR,
 				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 5f1726c095..0bd4557050 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
 	Acl		   *old_acl;
 	Acl		   *new_acl;
 	HeapTuple	newtuple;
-	Datum		values[Natts_pg_default_acl];
-	bool		nulls[Natts_pg_default_acl];
-	bool		replaces[Natts_pg_default_acl];
 	int			noldmembers;
 	int			nnewmembers;
 	Oid		   *oldmembers;
@@ -1341,13 +1338,10 @@ SetDefaultACL(InternalDefaultACL *iacls)
 	}
 	else
 	{
+		Datum		values[Natts_pg_default_acl] = {0};
+		bool		nulls[Natts_pg_default_acl] = {0};
 		Oid			defAclOid;
 
-		/* Prepare to insert or update pg_default_acl entry */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		if (isNew)
 		{
 			/* insert new entry */
@@ -1364,6 +1358,8 @@ SetDefaultACL(InternalDefaultACL *iacls)
 		}
 		else
 		{
+			bool		replaces[Natts_pg_default_acl] = {0};
+
 			defAclOid = ((Form_pg_default_acl) GETSTRUCT(tuple))->oid;
 
 			/* update existing entry */
@@ -1662,9 +1658,8 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
 	AclMode		avail_goptions;
 	bool		need_update;
 	HeapTuple	newtuple;
-	Datum		values[Natts_pg_attribute];
-	bool		nulls[Natts_pg_attribute];
-	bool		replaces[Natts_pg_attribute];
+	Datum		values[Natts_pg_attribute] = {0};
+	bool		nulls[Natts_pg_attribute] = {0};
 	int			noldmembers;
 	int			nnewmembers;
 	Oid		   *oldmembers;
@@ -1745,9 +1740,6 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
 	nnewmembers = aclmembers(new_acl, &newmembers);
 
 	/* finished building new ACL value, now insert it */
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, false, sizeof(nulls));
-	MemSet(replaces, false, sizeof(replaces));
 
 	/*
 	 * If the updated ACL is empty, we can set attacl to null, and maybe even
@@ -1766,10 +1758,12 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
 		nulls[Anum_pg_attribute_attacl - 1] = true;
 		need_update = !isNull;
 	}
-	replaces[Anum_pg_attribute_attacl - 1] = true;
 
 	if (need_update)
 	{
+		bool		replaces[Natts_pg_attribute] = {0};
+
+		replaces[Anum_pg_attribute_attacl - 1] = true;
 		newtuple = heap_modify_tuple(attr_tuple, RelationGetDescr(attRelation),
 									 values, nulls, replaces);
 
@@ -1975,9 +1969,9 @@ ExecGrant_Relation(InternalGrant *istmt)
 			Acl		   *new_acl;
 			Oid			grantorId;
 			HeapTuple	newtuple;
-			Datum		values[Natts_pg_class];
-			bool		nulls[Natts_pg_class];
-			bool		replaces[Natts_pg_class];
+			Datum		values[Natts_pg_class] = {0};
+			bool		nulls[Natts_pg_class] = {0};
+			bool		replaces[Natts_pg_class] = {0};
 			int			nnewmembers;
 			Oid		   *newmembers;
 			ObjectType	objtype;
@@ -2027,10 +2021,6 @@ ExecGrant_Relation(InternalGrant *istmt)
 			nnewmembers = aclmembers(new_acl, &newmembers);
 
 			/* finished building new ACL value, now insert it */
-			MemSet(values, 0, sizeof(values));
-			MemSet(nulls, false, sizeof(nulls));
-			MemSet(replaces, false, sizeof(replaces));
-
 			replaces[Anum_pg_class_relacl - 1] = true;
 			values[Anum_pg_class_relacl - 1] = PointerGetDatum(new_acl);
 
@@ -2129,6 +2119,9 @@ ExecGrant_Relation(InternalGrant *istmt)
 static void
 ExecGrant_Database(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_database] = {0};
+	bool		nulls[Natts_pg_database] = {0};
+	bool		replaces[Natts_pg_database] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2150,9 +2143,6 @@ ExecGrant_Database(InternalGrant *istmt)
 		Oid			grantorId;
 		Oid			ownerId;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_database];
-		bool		nulls[Natts_pg_database];
-		bool		replaces[Natts_pg_database];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2217,10 +2207,6 @@ ExecGrant_Database(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_database_datacl - 1] = true;
 		values[Anum_pg_database_datacl - 1] = PointerGetDatum(new_acl);
 
@@ -2249,6 +2235,9 @@ ExecGrant_Database(InternalGrant *istmt)
 static void
 ExecGrant_Fdw(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_foreign_data_wrapper] = {0};
+	bool		nulls[Natts_pg_foreign_data_wrapper] = {0};
+	bool		replaces[Natts_pg_foreign_data_wrapper] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2271,9 +2260,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
 		Oid			ownerId;
 		HeapTuple	tuple;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_foreign_data_wrapper];
-		bool		nulls[Natts_pg_foreign_data_wrapper];
-		bool		replaces[Natts_pg_foreign_data_wrapper];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2339,10 +2325,6 @@ ExecGrant_Fdw(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
 		values[Anum_pg_foreign_data_wrapper_fdwacl - 1] = PointerGetDatum(new_acl);
 
@@ -2376,6 +2358,9 @@ ExecGrant_Fdw(InternalGrant *istmt)
 static void
 ExecGrant_ForeignServer(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_foreign_server] = {0};
+	bool		nulls[Natts_pg_foreign_server] = {0};
+	bool		replaces[Natts_pg_foreign_server] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2398,9 +2383,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
 		Oid			ownerId;
 		HeapTuple	tuple;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_foreign_server];
-		bool		nulls[Natts_pg_foreign_server];
-		bool		replaces[Natts_pg_foreign_server];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2465,10 +2447,6 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_foreign_server_srvacl - 1] = true;
 		values[Anum_pg_foreign_server_srvacl - 1] = PointerGetDatum(new_acl);
 
@@ -2501,6 +2479,9 @@ ExecGrant_ForeignServer(InternalGrant *istmt)
 static void
 ExecGrant_Function(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_proc] = {0};
+	bool		nulls[Natts_pg_proc] = {0};
+	bool		replaces[Natts_pg_proc] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2523,9 +2504,6 @@ ExecGrant_Function(InternalGrant *istmt)
 		Oid			ownerId;
 		HeapTuple	tuple;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_proc];
-		bool		nulls[Natts_pg_proc];
-		bool		replaces[Natts_pg_proc];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2589,10 +2567,6 @@ ExecGrant_Function(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_proc_proacl - 1] = true;
 		values[Anum_pg_proc_proacl - 1] = PointerGetDatum(new_acl);
 
@@ -2624,6 +2598,9 @@ ExecGrant_Function(InternalGrant *istmt)
 static void
 ExecGrant_Language(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_language] = {0};
+	bool		nulls[Natts_pg_language] = {0};
+	bool		replaces[Natts_pg_language] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2646,9 +2623,6 @@ ExecGrant_Language(InternalGrant *istmt)
 		Oid			ownerId;
 		HeapTuple	tuple;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_language];
-		bool		nulls[Natts_pg_language];
-		bool		replaces[Natts_pg_language];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2720,10 +2694,6 @@ ExecGrant_Language(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_language_lanacl - 1] = true;
 		values[Anum_pg_language_lanacl - 1] = PointerGetDatum(new_acl);
 
@@ -2755,6 +2725,9 @@ ExecGrant_Language(InternalGrant *istmt)
 static void
 ExecGrant_Largeobject(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_largeobject_metadata] = {0};
+	bool		nulls[Natts_pg_largeobject_metadata] = {0};
+	bool		replaces[Natts_pg_largeobject_metadata] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2778,9 +2751,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
 		Oid			grantorId;
 		Oid			ownerId;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_largeobject_metadata];
-		bool		nulls[Natts_pg_largeobject_metadata];
-		bool		replaces[Natts_pg_largeobject_metadata];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2858,10 +2828,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_largeobject_metadata_lomacl - 1] = true;
 		values[Anum_pg_largeobject_metadata_lomacl - 1]
 			= PointerGetDatum(new_acl);
@@ -2895,6 +2861,9 @@ ExecGrant_Largeobject(InternalGrant *istmt)
 static void
 ExecGrant_Namespace(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_namespace] = {0};
+	bool		nulls[Natts_pg_namespace] = {0};
+	bool		replaces[Natts_pg_namespace] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -2917,9 +2886,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
 		Oid			ownerId;
 		HeapTuple	tuple;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_namespace];
-		bool		nulls[Natts_pg_namespace];
-		bool		replaces[Natts_pg_namespace];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -2984,10 +2950,6 @@ ExecGrant_Namespace(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_namespace_nspacl - 1] = true;
 		values[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(new_acl);
 
@@ -3019,6 +2981,9 @@ ExecGrant_Namespace(InternalGrant *istmt)
 static void
 ExecGrant_Tablespace(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_tablespace] = {0};
+	bool		nulls[Natts_pg_tablespace] = {0};
+	bool		replaces[Natts_pg_tablespace] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -3040,9 +3005,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
 		Oid			grantorId;
 		Oid			ownerId;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_tablespace];
-		bool		nulls[Natts_pg_tablespace];
-		bool		replaces[Natts_pg_tablespace];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -3108,10 +3070,6 @@ ExecGrant_Tablespace(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_tablespace_spcacl - 1] = true;
 		values[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(new_acl);
 
@@ -3139,6 +3097,9 @@ ExecGrant_Tablespace(InternalGrant *istmt)
 static void
 ExecGrant_Type(InternalGrant *istmt)
 {
+	Datum		values[Natts_pg_type] = {0};
+	bool		nulls[Natts_pg_type] = {0};
+	bool		replaces[Natts_pg_type] = {0};
 	Relation	relation;
 	ListCell   *cell;
 
@@ -3160,9 +3121,6 @@ ExecGrant_Type(InternalGrant *istmt)
 		Oid			grantorId;
 		Oid			ownerId;
 		HeapTuple	newtuple;
-		Datum		values[Natts_pg_type];
-		bool		nulls[Natts_pg_type];
-		bool		replaces[Natts_pg_type];
 		int			noldmembers;
 		int			nnewmembers;
 		Oid		   *oldmembers;
@@ -3242,10 +3200,6 @@ ExecGrant_Type(InternalGrant *istmt)
 		nnewmembers = aclmembers(new_acl, &newmembers);
 
 		/* finished building new ACL value, now insert it */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-		MemSet(replaces, false, sizeof(replaces));
-
 		replaces[Anum_pg_type_typacl - 1] = true;
 		values[Anum_pg_type_typacl - 1] = PointerGetDatum(new_acl);
 
@@ -3384,13 +3338,9 @@ ExecGrant_Parameter(InternalGrant *istmt)
 		{
 			/* finished building new ACL value, now insert it */
 			HeapTuple	newtuple;
-			Datum		values[Natts_pg_parameter_acl];
-			bool		nulls[Natts_pg_parameter_acl];
-			bool		replaces[Natts_pg_parameter_acl];
-
-			MemSet(values, 0, sizeof(values));
-			MemSet(nulls, false, sizeof(nulls));
-			MemSet(replaces, false, sizeof(replaces));
+			Datum		values[Natts_pg_parameter_acl] = {0};
+			bool		nulls[Natts_pg_parameter_acl] = {0};
+			bool		replaces[Natts_pg_parameter_acl] = {0};
 
 			replaces[Anum_pg_parameter_acl_paracl - 1] = true;
 			values[Anum_pg_parameter_acl_paracl - 1] = PointerGetDatum(new_acl);
@@ -6419,16 +6369,12 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
 	/* If we find an entry, update it with the latest ACL. */
 	if (HeapTupleIsValid(oldtuple))
 	{
-		Datum		values[Natts_pg_init_privs];
-		bool		nulls[Natts_pg_init_privs];
-		bool		replace[Natts_pg_init_privs];
-
 		/* If we have a new ACL to set, then update the row with it. */
 		if (new_acl)
 		{
-			MemSet(values, 0, sizeof(values));
-			MemSet(nulls, false, sizeof(nulls));
-			MemSet(replace, false, sizeof(replace));
+			Datum		values[Natts_pg_init_privs] = {0};
+			bool		nulls[Natts_pg_init_privs] = {0};
+			bool		replace[Natts_pg_init_privs] = {0};
 
 			values[Anum_pg_init_privs_initprivs - 1] = PointerGetDatum(new_acl);
 			replace[Anum_pg_init_privs_initprivs - 1] = true;
@@ -6446,9 +6392,6 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
 	}
 	else
 	{
-		Datum		values[Natts_pg_init_privs];
-		bool		nulls[Natts_pg_init_privs];
-
 		/*
 		 * Only add a new entry if the new ACL is non-NULL.
 		 *
@@ -6457,9 +6400,10 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
 		 */
 		if (new_acl)
 		{
-			/* No entry found, so add it. */
-			MemSet(nulls, false, sizeof(nulls));
+			Datum		values[Natts_pg_init_privs] = {0};
+			bool		nulls[Natts_pg_init_privs] = {0};
 
+			/* No entry found, so add it. */
 			values[Anum_pg_init_privs_objoid - 1] = ObjectIdGetDatum(objoid);
 			values[Anum_pg_init_privs_classoid - 1] = ObjectIdGetDatum(classoid);
 			values[Anum_pg_init_privs_objsubid - 1] = Int32GetDatum(objsubid);
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index de10923391..5cbd72ce10 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1635,12 +1635,11 @@ recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
 								bool reverse_self)
 {
 	find_expr_references_context context;
-	RangeTblEntry rte;
+	RangeTblEntry rte = {0};
 
 	context.addrs = new_object_addresses();
 
 	/* We gin up a rather bogus rangetable list to handle Vars */
-	MemSet(&rte, 0, sizeof(rte));
 	rte.type = T_RangeTblEntry;
 	rte.rtekind = RTE_RELATION;
 	rte.relid = relId;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index e770ea6eb8..9b03579e6e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1709,15 +1709,11 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
 		/* clear the missing value if any */
 		if (attStruct->atthasmissing)
 		{
-			Datum		valuesAtt[Natts_pg_attribute];
-			bool		nullsAtt[Natts_pg_attribute];
-			bool		replacesAtt[Natts_pg_attribute];
+			Datum		valuesAtt[Natts_pg_attribute] = {0};
+			bool		nullsAtt[Natts_pg_attribute] = {0};
+			bool		replacesAtt[Natts_pg_attribute] = {0};
 
 			/* update the tuple - set atthasmissing and attmissingval */
-			MemSet(valuesAtt, 0, sizeof(valuesAtt));
-			MemSet(nullsAtt, false, sizeof(nullsAtt));
-			MemSet(replacesAtt, false, sizeof(replacesAtt));
-
 			valuesAtt[Anum_pg_attribute_atthasmissing - 1] =
 				BoolGetDatum(false);
 			replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
@@ -2006,9 +2002,9 @@ RelationClearMissing(Relation rel)
 void
 SetAttrMissing(Oid relid, char *attname, char *value)
 {
-	Datum		valuesAtt[Natts_pg_attribute];
-	bool		nullsAtt[Natts_pg_attribute];
-	bool		replacesAtt[Natts_pg_attribute];
+	Datum		valuesAtt[Natts_pg_attribute] = {0};
+	bool		nullsAtt[Natts_pg_attribute] = {0};
+	bool		replacesAtt[Natts_pg_attribute] = {0};
 	Datum		missingval;
 	Form_pg_attribute attStruct;
 	Relation	attrrel,
@@ -2041,10 +2037,6 @@ SetAttrMissing(Oid relid, char *attname, char *value)
 								  Int32GetDatum(attStruct->atttypmod));
 
 	/* update the tuple - set atthasmissing and attmissingval */
-	MemSet(valuesAtt, 0, sizeof(valuesAtt));
-	MemSet(nullsAtt, false, sizeof(nullsAtt));
-	MemSet(replacesAtt, false, sizeof(replacesAtt));
-
 	valuesAtt[Anum_pg_attribute_atthasmissing - 1] = BoolGetDatum(true);
 	replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
 	valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
@@ -3321,7 +3313,7 @@ StorePartitionKey(Relation rel,
 	Relation	pg_partitioned_table;
 	HeapTuple	tuple;
 	Datum		values[Natts_pg_partitioned_table];
-	bool		nulls[Natts_pg_partitioned_table];
+	bool		nulls[Natts_pg_partitioned_table] = {0};
 	ObjectAddress myself;
 	ObjectAddress referenced;
 	ObjectAddresses *addrs;
@@ -3347,8 +3339,6 @@ StorePartitionKey(Relation rel,
 
 	pg_partitioned_table = table_open(PartitionedRelationId, RowExclusiveLock);
 
-	MemSet(nulls, false, sizeof(nulls));
-
 	/* Only this can ever be NULL */
 	if (!partexprDatum)
 		nulls[Anum_pg_partitioned_table_partexprs - 1] = true;
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index c5d463ac55..d7192f35e3 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -554,7 +554,7 @@ UpdateIndexRelation(Oid indexoid,
 	Datum		exprsDatum;
 	Datum		predDatum;
 	Datum		values[Natts_pg_index];
-	bool		nulls[Natts_pg_index];
+	bool		nulls[Natts_pg_index] = {0};
 	Relation	pg_index;
 	HeapTuple	tuple;
 	int			i;
@@ -608,8 +608,6 @@ UpdateIndexRelation(Oid indexoid,
 	/*
 	 * Build a pg_index tuple
 	 */
-	MemSet(nulls, false, sizeof(nulls));
-
 	values[Anum_pg_index_indexrelid - 1] = ObjectIdGetDatum(indexoid);
 	values[Anum_pg_index_indrelid - 1] = ObjectIdGetDatum(heapoid);
 	values[Anum_pg_index_indnatts - 1] = Int16GetDatum(indexInfo->ii_NumIndexAttrs);
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index c5d4a9912e..1a14093a9a 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -111,15 +111,12 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
 		Expr	   *expr2 = (Expr *) expr;
 		EState	   *estate = NULL;
 		ExprContext *econtext;
-		Datum		valuesAtt[Natts_pg_attribute];
-		bool		nullsAtt[Natts_pg_attribute];
-		bool		replacesAtt[Natts_pg_attribute];
+		Datum		valuesAtt[Natts_pg_attribute] = {0};
+		bool		nullsAtt[Natts_pg_attribute] = {0};
+		bool		replacesAtt[Natts_pg_attribute] = {0};
 		Datum		missingval = (Datum) 0;
 		bool		missingIsNull = true;
 
-		MemSet(valuesAtt, 0, sizeof(valuesAtt));
-		MemSet(nullsAtt, false, sizeof(nullsAtt));
-		MemSet(replacesAtt, false, sizeof(replacesAtt));
 		valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
 		replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
 
diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c
index 4857f6468d..1812bb7fcc 100644
--- a/src/backend/catalog/pg_cast.c
+++ b/src/backend/catalog/pg_cast.c
@@ -47,7 +47,7 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
 	HeapTuple	tuple;
 	Oid			castid;
 	Datum		values[Natts_pg_cast];
-	bool		nulls[Natts_pg_cast];
+	bool		nulls[Natts_pg_cast] = {0};
 	ObjectAddress myself,
 				referenced;
 	ObjectAddresses *addrs;
@@ -78,8 +78,6 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
 	values[Anum_pg_cast_castcontext - 1] = CharGetDatum(castcontext);
 	values[Anum_pg_cast_castmethod - 1] = CharGetDatum(castmethod);
 
-	MemSet(nulls, false, sizeof(nulls));
-
 	tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
 
 	CatalogTupleInsert(relation, tuple);
diff --git a/src/backend/catalog/pg_parameter_acl.c b/src/backend/catalog/pg_parameter_acl.c
index 2decee909b..0570e811d1 100644
--- a/src/backend/catalog/pg_parameter_acl.c
+++ b/src/backend/catalog/pg_parameter_acl.c
@@ -74,8 +74,8 @@ ParameterAclCreate(const char *parameter)
 	Relation	rel;
 	TupleDesc	tupDesc;
 	HeapTuple	tuple;
-	Datum		values[Natts_pg_parameter_acl];
-	bool		nulls[Natts_pg_parameter_acl];
+	Datum		values[Natts_pg_parameter_acl] = {0};
+	bool		nulls[Natts_pg_parameter_acl] = {0};
 
 	/*
 	 * To prevent cluttering pg_parameter_acl with useless entries, insist
@@ -98,8 +98,6 @@ ParameterAclCreate(const char *parameter)
 	 */
 	rel = table_open(ParameterAclRelationId, RowExclusiveLock);
 	tupDesc = RelationGetDescr(rel);
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, false, sizeof(nulls));
 	parameterId = GetNewOidWithIndex(rel,
 									 ParameterAclOidIndexId,
 									 Anum_pg_parameter_acl_oid);
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index c365de3a72..4ff692cb5e 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1162,15 +1162,12 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
 		HeapTuple	pubtuple = NULL;
 		HeapTuple	rettuple;
 		Oid			relid = list_nth_oid(tables, funcctx->call_cntr);
-		Datum		values[NUM_PUBLICATION_TABLES_ELEM];
-		bool		nulls[NUM_PUBLICATION_TABLES_ELEM];
+		Datum		values[NUM_PUBLICATION_TABLES_ELEM] = {0};
+		bool		nulls[NUM_PUBLICATION_TABLES_ELEM] = {0};
 
 		/*
 		 * Form tuple with appropriate data.
 		 */
-		MemSet(nulls, 0, sizeof(nulls));
-		MemSet(values, 0, sizeof(values));
-
 		publication = GetPublicationByName(pubname, false);
 
 		values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 57813b3458..cef0f2c279 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -869,7 +869,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
 
 	/* Initialize all values for row to NULL */
 	MemSet(values, 0, num_phys_attrs * sizeof(Datum));
-	MemSet(nulls, true, num_phys_attrs * sizeof(bool));
+	memset(nulls, true, num_phys_attrs * sizeof(bool));
 
 	if (!cstate->opts.binary)
 	{
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 1901b434c5..099d369b2f 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -689,8 +689,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
 	volatile Oid dst_deftablespace;
 	Relation	pg_database_rel;
 	HeapTuple	tuple;
-	Datum		new_record[Natts_pg_database];
-	bool		new_record_nulls[Natts_pg_database];
+	Datum		new_record[Natts_pg_database] = {0};
+	bool		new_record_nulls[Natts_pg_database] = {0};
 	Oid			dboid = InvalidOid;
 	Oid			datdba;
 	ListCell   *option;
@@ -1296,9 +1296,6 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
 		   (dblocprovider != COLLPROVIDER_ICU && !dbiculocale));
 
 	/* Form tuple */
-	MemSet(new_record, 0, sizeof(new_record));
-	MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
 	new_record[Anum_pg_database_oid - 1] = ObjectIdGetDatum(dboid);
 	new_record[Anum_pg_database_datname - 1] =
 		DirectFunctionCall1(namein, CStringGetDatum(dbname));
@@ -1822,9 +1819,6 @@ movedb(const char *dbname, const char *tblspcname)
 				newtuple;
 	Oid			src_tblspcoid,
 				dst_tblspcoid;
-	Datum		new_record[Natts_pg_database];
-	bool		new_record_nulls[Natts_pg_database];
-	bool		new_record_repl[Natts_pg_database];
 	ScanKeyData scankey;
 	SysScanDesc sysscan;
 	AclResult	aclresult;
@@ -2003,6 +1997,10 @@ movedb(const char *dbname, const char *tblspcname)
 	PG_ENSURE_ERROR_CLEANUP(movedb_failure_callback,
 							PointerGetDatum(&fparms));
 	{
+		Datum		new_record[Natts_pg_database] = {0};
+		bool		new_record_nulls[Natts_pg_database] = {0};
+		bool		new_record_repl[Natts_pg_database] = {0};
+
 		/*
 		 * Copy files from the old tablespace to the new one
 		 */
@@ -2042,10 +2040,6 @@ movedb(const char *dbname, const char *tblspcname)
 					(errcode(ERRCODE_UNDEFINED_DATABASE),
 					 errmsg("database \"%s\" does not exist", dbname)));
 
-		MemSet(new_record, 0, sizeof(new_record));
-		MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-		MemSet(new_record_repl, false, sizeof(new_record_repl));
-
 		new_record[Anum_pg_database_dattablespace - 1] = ObjectIdGetDatum(dst_tblspcoid);
 		new_record_repl[Anum_pg_database_dattablespace - 1] = true;
 
@@ -2194,9 +2188,9 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
 	DefElem    *dallowconnections = NULL;
 	DefElem    *dconnlimit = NULL;
 	DefElem    *dtablespace = NULL;
-	Datum		new_record[Natts_pg_database];
-	bool		new_record_nulls[Natts_pg_database];
-	bool		new_record_repl[Natts_pg_database];
+	Datum		new_record[Natts_pg_database] = {0};
+	bool		new_record_nulls[Natts_pg_database] = {0};
+	bool		new_record_repl[Natts_pg_database] = {0};
 
 	/* Extract options from the statement node tree */
 	foreach(option, stmt->options)
@@ -2305,10 +2299,6 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
 	/*
 	 * Build an updated tuple, perusing the information just obtained
 	 */
-	MemSet(new_record, 0, sizeof(new_record));
-	MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-	MemSet(new_record_repl, false, sizeof(new_record_repl));
-
 	if (distemplate)
 	{
 		new_record[Anum_pg_database_datistemplate - 1] = BoolGetDatum(dbistemplate);
@@ -2492,8 +2482,8 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
 	if (datForm->datdba != newOwnerId)
 	{
 		Datum		repl_val[Natts_pg_database];
-		bool		repl_null[Natts_pg_database];
-		bool		repl_repl[Natts_pg_database];
+		bool		repl_null[Natts_pg_database] = {0};
+		bool		repl_repl[Natts_pg_database] = {0};
 		Acl		   *newAcl;
 		Datum		aclDatum;
 		bool		isNull;
@@ -2521,9 +2511,6 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
 					(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
 					 errmsg("permission denied to change owner of database")));
 
-		memset(repl_null, false, sizeof(repl_null));
-		memset(repl_repl, false, sizeof(repl_repl));
-
 		repl_repl[Anum_pg_database_datdba - 1] = true;
 		repl_val[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(newOwnerId);
 
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index f46f86474a..eef3e5d56e 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1310,14 +1310,11 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
 	{
 		SQLDropObject *obj;
 		int			i = 0;
-		Datum		values[12];
-		bool		nulls[12];
+		Datum		values[12] = {0};
+		bool		nulls[12] = {0};
 
 		obj = slist_container(SQLDropObject, next, iter.cur);
 
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
-
 		/* classid */
 		values[i++] = ObjectIdGetDatum(obj->address.classId);
 
@@ -1840,7 +1837,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
 	{
 		CollectedCommand *cmd = lfirst(lc);
 		Datum		values[9];
-		bool		nulls[9];
+		bool		nulls[9] = {0};
 		ObjectAddress addr;
 		int			i = 0;
 
@@ -1858,8 +1855,6 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
 			!OidIsValid(cmd->d.simple.address.objectId))
 			continue;
 
-		MemSet(nulls, 0, sizeof(nulls));
-
 		switch (cmd->type)
 		{
 			case SCT_Simple:
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index b016eecb2c..f51cfe6df1 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1806,8 +1806,7 @@ CreateTransform(CreateTransformStmt *stmt)
 	AclResult	aclresult;
 	Form_pg_proc procstruct;
 	Datum		values[Natts_pg_transform];
-	bool		nulls[Natts_pg_transform];
-	bool		replaces[Natts_pg_transform];
+	bool		nulls[Natts_pg_transform] = {0};
 	Oid			transformid;
 	HeapTuple	tuple;
 	HeapTuple	newtuple;
@@ -1913,8 +1912,6 @@ CreateTransform(CreateTransformStmt *stmt)
 	values[Anum_pg_transform_trffromsql - 1] = ObjectIdGetDatum(fromsqlfuncid);
 	values[Anum_pg_transform_trftosql - 1] = ObjectIdGetDatum(tosqlfuncid);
 
-	MemSet(nulls, false, sizeof(nulls));
-
 	relation = table_open(TransformRelationId, RowExclusiveLock);
 
 	tuple = SearchSysCache2(TRFTYPELANG,
@@ -1922,6 +1919,8 @@ CreateTransform(CreateTransformStmt *stmt)
 							ObjectIdGetDatum(langid));
 	if (HeapTupleIsValid(tuple))
 	{
+		bool		replaces[Natts_pg_transform] = {0};
+
 		Form_pg_transform form = (Form_pg_transform) GETSTRUCT(tuple);
 
 		if (!stmt->replace)
@@ -1931,7 +1930,6 @@ CreateTransform(CreateTransformStmt *stmt)
 							format_type_be(typeid),
 							stmt->lang)));
 
-		MemSet(replaces, false, sizeof(replaces));
 		replaces[Anum_pg_transform_trffromsql - 1] = true;
 		replaces[Anum_pg_transform_trftosql - 1] = true;
 
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 2333aae467..579825c159 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -685,12 +685,10 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
 		{
 			TupleDesc	result_desc;
 			Datum		values[8];
-			bool		nulls[8];
+			bool		nulls[8] = {0};
 
 			result_desc = prep_stmt->plansource->resultDesc;
 
-			MemSet(nulls, 0, sizeof(nulls));
-
 			values[0] = CStringGetTextDatum(prep_stmt->stmt_name);
 			values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
 			values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index ef5b34a312..18f7a4ae86 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -9013,15 +9013,15 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
 						  bool recurse, bool recursing, LOCKMODE lockmode)
 {
 	Relation	pkrel;
-	int16		pkattnum[INDEX_MAX_KEYS];
-	int16		fkattnum[INDEX_MAX_KEYS];
-	Oid			pktypoid[INDEX_MAX_KEYS];
-	Oid			fktypoid[INDEX_MAX_KEYS];
-	Oid			opclasses[INDEX_MAX_KEYS];
-	Oid			pfeqoperators[INDEX_MAX_KEYS];
-	Oid			ppeqoperators[INDEX_MAX_KEYS];
-	Oid			ffeqoperators[INDEX_MAX_KEYS];
-	int16		fkdelsetcols[INDEX_MAX_KEYS];
+	int16		pkattnum[INDEX_MAX_KEYS] = {0};
+	int16		fkattnum[INDEX_MAX_KEYS] = {0};
+	Oid			pktypoid[INDEX_MAX_KEYS] = {0};
+	Oid			fktypoid[INDEX_MAX_KEYS] = {0};
+	Oid			opclasses[INDEX_MAX_KEYS] = {0};
+	Oid			pfeqoperators[INDEX_MAX_KEYS] = {0};
+	Oid			ppeqoperators[INDEX_MAX_KEYS] = {0};
+	Oid			ffeqoperators[INDEX_MAX_KEYS] = {0};
+	int16		fkdelsetcols[INDEX_MAX_KEYS] = {0};
 	int			i;
 	int			numfks,
 				numpks,
@@ -9113,16 +9113,6 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
 	 * Look up the referencing attributes to make sure they exist, and record
 	 * their attnums and type OIDs.
 	 */
-	MemSet(pkattnum, 0, sizeof(pkattnum));
-	MemSet(fkattnum, 0, sizeof(fkattnum));
-	MemSet(pktypoid, 0, sizeof(pktypoid));
-	MemSet(fktypoid, 0, sizeof(fktypoid));
-	MemSet(opclasses, 0, sizeof(opclasses));
-	MemSet(pfeqoperators, 0, sizeof(pfeqoperators));
-	MemSet(ppeqoperators, 0, sizeof(ppeqoperators));
-	MemSet(ffeqoperators, 0, sizeof(ffeqoperators));
-	MemSet(fkdelsetcols, 0, sizeof(fkdelsetcols));
-
 	numfks = transformColumnNameList(RelationGetRelid(rel),
 									 fkconstraint->fk_attrs,
 									 fkattnum, fktypoid);
@@ -11498,7 +11488,7 @@ validateForeignKeyConstraint(char *conname,
 {
 	TupleTableSlot *slot;
 	TableScanDesc scan;
-	Trigger		trig;
+	Trigger		trig = {0};
 	Snapshot	snapshot;
 	MemoryContext oldcxt;
 	MemoryContext perTupCxt;
@@ -11509,7 +11499,6 @@ validateForeignKeyConstraint(char *conname,
 	/*
 	 * Build a trigger call structure; we'll need it either way.
 	 */
-	MemSet(&trig, 0, sizeof(trig));
 	trig.tgoid = InvalidOid;
 	trig.tgname = conname;
 	trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
@@ -12783,15 +12772,11 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
 
 			int			one = 1;
 			bool		isNull;
-			Datum		valuesAtt[Natts_pg_attribute];
-			bool		nullsAtt[Natts_pg_attribute];
-			bool		replacesAtt[Natts_pg_attribute];
+			Datum		valuesAtt[Natts_pg_attribute] = {0};
+			bool		nullsAtt[Natts_pg_attribute] = {0};
+			bool		replacesAtt[Natts_pg_attribute] = {0};
 			HeapTuple	newTup;
 
-			MemSet(valuesAtt, 0, sizeof(valuesAtt));
-			MemSet(nullsAtt, false, sizeof(nullsAtt));
-			MemSet(replacesAtt, false, sizeof(replacesAtt));
-
 			missingval = array_get_element(missingval,
 										   1,
 										   &one,
@@ -19219,7 +19204,7 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
 		HeapTuple	tuple;
 		Form_pg_constraint constrForm;
 		Relation	rel;
-		Trigger		trig;
+		Trigger		trig = {0};
 
 		tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid));
 		if (!HeapTupleIsValid(tuple))
@@ -19232,7 +19217,6 @@ ATDetachCheckNoForeignKeyRefs(Relation partition)
 		/* prevent data changes into the referencing table until commit */
 		rel = table_open(constrForm->conrelid, ShareLock);
 
-		MemSet(&trig, 0, sizeof(trig));
 		trig.tgoid = InvalidOid;
 		trig.tgname = NameStr(constrForm->conname);
 		trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index c8bdd9992a..cb7d46089a 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -238,7 +238,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
 #ifdef HAVE_SYMLINK
 	Relation	rel;
 	Datum		values[Natts_pg_tablespace];
-	bool		nulls[Natts_pg_tablespace];
+	bool		nulls[Natts_pg_tablespace] = {0};
 	HeapTuple	tuple;
 	Oid			tablespaceoid;
 	char	   *location;
@@ -340,8 +340,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
 	 */
 	rel = table_open(TableSpaceRelationId, RowExclusiveLock);
 
-	MemSet(nulls, false, sizeof(nulls));
-
 	if (IsBinaryUpgrade)
 	{
 		/* Use binary-upgrade override for tablespace oid */
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 4f5e7c7ccb..4f58d29aa5 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -2570,9 +2570,9 @@ AlterDomainDefault(List *names, Node *defaultRaw)
 	Relation	rel;
 	char	   *defaultValue;
 	Node	   *defaultExpr = NULL; /* NULL if no default specified */
-	Datum		new_record[Natts_pg_type];
-	bool		new_record_nulls[Natts_pg_type];
-	bool		new_record_repl[Natts_pg_type];
+	Datum		new_record[Natts_pg_type] = {0};
+	bool		new_record_nulls[Natts_pg_type] = {0};
+	bool		new_record_repl[Natts_pg_type] = {0};
 	HeapTuple	newtuple;
 	Form_pg_type typTup;
 	ObjectAddress address;
@@ -2593,9 +2593,6 @@ AlterDomainDefault(List *names, Node *defaultRaw)
 	checkDomainOwner(tup);
 
 	/* Setup new tuple */
-	MemSet(new_record, (Datum) 0, sizeof(new_record));
-	MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-	MemSet(new_record_repl, false, sizeof(new_record_repl));
 
 	/* Store the new default into the tuple */
 	if (defaultRaw)
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 984305ba31..8f4cc86eda 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -74,8 +74,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
 	Relation	pg_authid_rel;
 	TupleDesc	pg_authid_dsc;
 	HeapTuple	tuple;
-	Datum		new_record[Natts_pg_authid];
-	bool		new_record_nulls[Natts_pg_authid];
+	Datum		new_record[Natts_pg_authid] = {0};
+	bool		new_record_nulls[Natts_pg_authid] = {0};
 	Oid			roleid;
 	ListCell   *item;
 	ListCell   *option;
@@ -338,12 +338,8 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
 	/*
 	 * Build a tuple to insert
 	 */
-	MemSet(new_record, 0, sizeof(new_record));
-	MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-
 	new_record[Anum_pg_authid_rolname - 1] =
 		DirectFunctionCall1(namein, CStringGetDatum(stmt->role));
-
 	new_record[Anum_pg_authid_rolsuper - 1] = BoolGetDatum(issuper);
 	new_record[Anum_pg_authid_rolinherit - 1] = BoolGetDatum(inherit);
 	new_record[Anum_pg_authid_rolcreaterole - 1] = BoolGetDatum(createrole);
@@ -492,9 +488,9 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
 Oid
 AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
 {
-	Datum		new_record[Natts_pg_authid];
-	bool		new_record_nulls[Natts_pg_authid];
-	bool		new_record_repl[Natts_pg_authid];
+	Datum		new_record[Natts_pg_authid] = {0};
+	bool		new_record_nulls[Natts_pg_authid] = {0};
+	bool		new_record_repl[Natts_pg_authid] = {0};
 	Relation	pg_authid_rel;
 	TupleDesc	pg_authid_dsc;
 	HeapTuple	tuple,
@@ -691,9 +687,6 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
 	/*
 	 * Build an updated tuple, perusing the information just obtained
 	 */
-	MemSet(new_record, 0, sizeof(new_record));
-	MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-	MemSet(new_record_repl, false, sizeof(new_record_repl));
 
 	/*
 	 * issuper/createrole/etc
@@ -1440,9 +1433,8 @@ AddRoleMems(const char *rolename, Oid roleid,
 		Oid			memberid = lfirst_oid(iditem);
 		HeapTuple	authmem_tuple;
 		HeapTuple	tuple;
-		Datum		new_record[Natts_pg_auth_members];
-		bool		new_record_nulls[Natts_pg_auth_members];
-		bool		new_record_repl[Natts_pg_auth_members];
+		Datum		new_record[Natts_pg_auth_members] = {0};
+		bool		new_record_nulls[Natts_pg_auth_members] = {0};
 
 		/*
 		 * pg_database_owner is never a role member.  Lifting this restriction
@@ -1500,10 +1492,6 @@ AddRoleMems(const char *rolename, Oid roleid,
 		}
 
 		/* Build a tuple to insert or update */
-		MemSet(new_record, 0, sizeof(new_record));
-		MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-		MemSet(new_record_repl, false, sizeof(new_record_repl));
-
 		new_record[Anum_pg_auth_members_roleid - 1] = ObjectIdGetDatum(roleid);
 		new_record[Anum_pg_auth_members_member - 1] = ObjectIdGetDatum(memberid);
 		new_record[Anum_pg_auth_members_grantor - 1] = ObjectIdGetDatum(grantorId);
@@ -1511,6 +1499,8 @@ AddRoleMems(const char *rolename, Oid roleid,
 
 		if (HeapTupleIsValid(authmem_tuple))
 		{
+			bool		new_record_repl[Natts_pg_auth_members] = {0};
+
 			new_record_repl[Anum_pg_auth_members_grantor - 1] = true;
 			new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
 			tuple = heap_modify_tuple(authmem_tuple, pg_authmem_dsc,
@@ -1614,15 +1604,11 @@ DelRoleMems(const char *rolename, Oid roleid,
 		{
 			/* Just turn off the admin option */
 			HeapTuple	tuple;
-			Datum		new_record[Natts_pg_auth_members];
-			bool		new_record_nulls[Natts_pg_auth_members];
-			bool		new_record_repl[Natts_pg_auth_members];
+			Datum		new_record[Natts_pg_auth_members] = {0};
+			bool		new_record_nulls[Natts_pg_auth_members] = {0};
+			bool		new_record_repl[Natts_pg_auth_members] = {0};
 
 			/* Build a tuple to update with */
-			MemSet(new_record, 0, sizeof(new_record));
-			MemSet(new_record_nulls, false, sizeof(new_record_nulls));
-			MemSet(new_record_repl, false, sizeof(new_record_repl));
-
 			new_record[Anum_pg_auth_members_admin_option - 1] = BoolGetDatum(false);
 			new_record_repl[Anum_pg_auth_members_admin_option - 1] = true;
 
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 2d9ab7edce..53fb7ca628 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -3022,7 +3022,7 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
 	struct sockaddr_in localaddr;
 	struct sockaddr_in remoteaddr;
 #endif
-	struct addrinfo hint;
+	struct addrinfo hint = {0};
 	struct addrinfo *serveraddrs;
 	int			port;
 	socklen_t	addrsize;
@@ -3038,7 +3038,6 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
 	if (identifier == NULL)
 		identifier = "postgresql";
 
-	MemSet(&hint, 0, sizeof(hint));
 	hint.ai_socktype = SOCK_DGRAM;
 	hint.ai_family = AF_UNSPEC;
 	port = atoi(portstr);
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 75392a8bb7..803d166640 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -331,7 +331,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 	char	   *service;
 	struct addrinfo *addrs = NULL,
 			   *addr;
-	struct addrinfo hint;
+	struct addrinfo hint = {0};
 	int			listen_index = 0;
 	int			added = 0;
 
@@ -343,7 +343,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
 #endif
 
 	/* Initialize hint structure */
-	MemSet(&hint, 0, sizeof(hint));
 	hint.ai_family = family;
 	hint.ai_flags = AI_PASSIVE;
 	hint.ai_socktype = SOCK_STREAM;
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index fcc26b01a4..1e0f1880c5 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2926,13 +2926,12 @@ cost_agg(Path *path, PlannerInfo *root,
 	double		output_tuples;
 	Cost		startup_cost;
 	Cost		total_cost;
-	AggClauseCosts dummy_aggcosts;
+	const AggClauseCosts dummy_aggcosts = {0};
 
 	/* Use all-zero per-aggregate costs if NULL is passed */
 	if (aggcosts == NULL)
 	{
 		Assert(aggstrategy == AGG_HASHED);
-		MemSet(&dummy_aggcosts, 0, sizeof(AggClauseCosts));
 		aggcosts = &dummy_aggcosts;
 	}
 
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 0ef70ad7f1..9c1b6305d3 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -238,9 +238,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 	List	   *bitindexpaths;
 	List	   *bitjoinpaths;
 	List	   *joinorclauses;
-	IndexClauseSet rclauseset;
-	IndexClauseSet jclauseset;
-	IndexClauseSet eclauseset;
 	ListCell   *lc;
 
 	/* Skip the whole mess if no indexes */
@@ -253,6 +250,9 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 	/* Examine each index in turn */
 	foreach(lc, rel->indexlist)
 	{
+		IndexClauseSet rclauseset = {0};
+		IndexClauseSet jclauseset = {0};
+		IndexClauseSet eclauseset = {0};
 		IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
 
 		/* Protect limited-size array in IndexClauseSets */
@@ -269,7 +269,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 		/*
 		 * Identify the restriction clauses that can match the index.
 		 */
-		MemSet(&rclauseset, 0, sizeof(rclauseset));
 		match_restriction_clauses_to_index(root, index, &rclauseset);
 
 		/*
@@ -286,7 +285,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 		 * step finds only "loose" join clauses that have not been merged into
 		 * EquivalenceClasses.  Also, collect join OR clauses for later.
 		 */
-		MemSet(&jclauseset, 0, sizeof(jclauseset));
 		match_join_clauses_to_index(root, rel, index,
 									&jclauseset, &joinorclauses);
 
@@ -294,7 +292,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
 		 * Look for EquivalenceClasses that can generate joinclauses matching
 		 * the index.
 		 */
-		MemSet(&eclauseset, 0, sizeof(eclauseset));
 		match_eclass_clauses_to_index(root, index,
 									  &eclauseset);
 
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 06ad856eac..77cbe681e5 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3350,9 +3350,8 @@ create_grouping_paths(PlannerInfo *root,
 	Query	   *parse = root->parse;
 	RelOptInfo *grouped_rel;
 	RelOptInfo *partially_grouped_rel;
-	AggClauseCosts agg_costs;
+	AggClauseCosts agg_costs = {0};
 
-	MemSet(&agg_costs, 0, sizeof(AggClauseCosts));
 	get_agg_clause_costs(root, AGGSPLIT_SIMPLE, &agg_costs);
 
 	/*
@@ -5908,16 +5907,14 @@ expression_planner_with_deps(Expr *expr,
 							 List **invalItems)
 {
 	Node	   *result;
-	PlannerGlobal glob;
-	PlannerInfo root;
+	PlannerGlobal glob = {0};
+	PlannerInfo root = {0};
 
 	/* Make up dummy planner state so we can use setrefs machinery */
-	MemSet(&glob, 0, sizeof(glob));
 	glob.type = T_PlannerGlobal;
 	glob.relationOids = NIL;
 	glob.invalItems = NIL;
 
-	MemSet(&root, 0, sizeof(root));
 	root.type = T_PlannerInfo;
 	root.glob = &glob;
 
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 9cef92cab2..f7fb2b3e6d 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -3285,18 +3285,16 @@ extract_query_dependencies(Node *query,
 						   List **invalItems,
 						   bool *hasRowSecurity)
 {
-	PlannerGlobal glob;
-	PlannerInfo root;
+	PlannerGlobal glob = {0};
+	PlannerInfo root = {0};
 
 	/* Make up dummy planner state so we can use this module's machinery */
-	MemSet(&glob, 0, sizeof(glob));
 	glob.type = T_PlannerGlobal;
 	glob.relationOids = NIL;
 	glob.invalItems = NIL;
 	/* Hack: we use glob.dependsOnRole to collect hasRowSecurity flags */
 	glob.dependsOnRole = false;
 
-	MemSet(&root, 0, sizeof(root));
 	root.type = T_PlannerInfo;
 	root.glob = &glob;
 
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 2a1d44b813..d69cb58b6a 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -1594,9 +1594,8 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
 					 * to.  We have to build an additional level of ParseState
 					 * to keep in step with varlevelsup in the subselect.
 					 */
-					ParseState	mypstate;
+					ParseState	mypstate = {0};
 
-					MemSet(&mypstate, 0, sizeof(mypstate));
 					mypstate.parentParseState = pstate;
 					mypstate.p_rtable = rte->subquery->rtable;
 					/* don't bother filling the rest of the fake pstate */
@@ -1649,10 +1648,9 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
 					 * in step with varlevelsup in the CTE; furthermore it
 					 * could be an outer CTE.
 					 */
-					ParseState	mypstate;
+					ParseState	mypstate = {0};
 					Index		levelsup;
 
-					MemSet(&mypstate, 0, sizeof(mypstate));
 					/* this loop must work, since GetCTEForRTE did */
 					for (levelsup = 0;
 						 levelsup < rte->ctelevelsup + netlevelsup;
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 2bdab53e19..3bbd522724 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -938,8 +938,8 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
 	for (i = 0; i < max_logical_replication_workers; i++)
 	{
 		/* for each row */
-		Datum		values[PG_STAT_GET_SUBSCRIPTION_COLS];
-		bool		nulls[PG_STAT_GET_SUBSCRIPTION_COLS];
+		Datum		values[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
+		bool		nulls[PG_STAT_GET_SUBSCRIPTION_COLS] = {0};
 		int			worker_pid;
 		LogicalRepWorker worker;
 
@@ -953,9 +953,6 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
 
 		worker_pid = worker.proc->pid;
 
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
-
 		values[0] = ObjectIdGetDatum(worker.subid);
 		if (OidIsValid(worker.relid))
 			values[1] = ObjectIdGetDatum(worker.relid);
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 3c407ab964..ef2ca3fef7 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -402,7 +402,7 @@ IdentifySystem(void)
 	TupOutputState *tstate;
 	TupleDesc	tupdesc;
 	Datum		values[4];
-	bool		nulls[4];
+	bool		nulls[4] = {0};
 	TimeLineID	currTLI;
 
 	/*
@@ -437,7 +437,6 @@ IdentifySystem(void)
 	}
 
 	dest = CreateDestReceiver(DestRemoteSimple);
-	MemSet(nulls, false, sizeof(nulls));
 
 	/* need a tuple descriptor representing four columns */
 	tupdesc = CreateTemplateTupleDesc(4);
@@ -483,7 +482,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
 	DestReceiver *dest;
 	TupOutputState *tstate;
 	TupleDesc	tupdesc;
-	Datum		values[READ_REPLICATION_SLOT_COLS];
+	Datum		values[READ_REPLICATION_SLOT_COLS] = {0};
 	bool		nulls[READ_REPLICATION_SLOT_COLS];
 
 	tupdesc = CreateTemplateTupleDesc(READ_REPLICATION_SLOT_COLS);
@@ -495,8 +494,7 @@ ReadReplicationSlot(ReadReplicationSlotCmd *cmd)
 	TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 3, "restart_tli",
 							  INT8OID, -1, 0);
 
-	MemSet(values, 0, READ_REPLICATION_SLOT_COLS * sizeof(Datum));
-	MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
+	memset(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
 
 	LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
 	slot = SearchNamedReplicationSlot(cmd->slotname, false);
@@ -859,13 +857,12 @@ StartReplication(StartReplicationCmd *cmd)
 		TupOutputState *tstate;
 		TupleDesc	tupdesc;
 		Datum		values[2];
-		bool		nulls[2];
+		bool		nulls[2] = {0};
 
 		snprintf(startpos_str, sizeof(startpos_str), "%X/%X",
 				 LSN_FORMAT_ARGS(sendTimeLineValidUpto));
 
 		dest = CreateDestReceiver(DestRemoteSimple);
-		MemSet(nulls, false, sizeof(nulls));
 
 		/*
 		 * Need a tuple descriptor representing two columns. int8 may seem
@@ -1043,7 +1040,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
 	TupOutputState *tstate;
 	TupleDesc	tupdesc;
 	Datum		values[4];
-	bool		nulls[4];
+	bool		nulls[4] = {0};
 
 	Assert(!MyReplicationSlot);
 
@@ -1178,7 +1175,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
 			 LSN_FORMAT_ARGS(MyReplicationSlot->data.confirmed_flush));
 
 	dest = CreateDestReceiver(DestRemoteSimple);
-	MemSet(nulls, false, sizeof(nulls));
 
 	/*----------
 	 * Need a tuple descriptor representing four columns:
@@ -3527,7 +3523,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
 			}
 		}
 
-		memset(nulls, 0, sizeof(nulls));
 		values[0] = Int32GetDatum(pid);
 
 		if (!has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_STATS))
@@ -3537,10 +3532,12 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
 			 * can see details. Other users only get the pid value to know
 			 * it's a walsender, but no details.
 			 */
-			MemSet(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
+			nulls[0] = false;
+			memset(&nulls[1], true, PG_STAT_GET_WAL_SENDERS_COLS - 1);
 		}
 		else
 		{
+			memset(nulls, 0, sizeof(nulls));
 			values[1] = CStringGetTextDatum(WalSndGetStateString(state));
 
 			if (XLogRecPtrIsInvalid(sentPtr))
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 185bf5fbff..a5a1fb887f 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -67,8 +67,7 @@ InsertRule(const char *rulname,
 	char	   *evqual = nodeToString(event_qual);
 	char	   *actiontree = nodeToString((Node *) action);
 	Datum		values[Natts_pg_rewrite];
-	bool		nulls[Natts_pg_rewrite];
-	bool		replaces[Natts_pg_rewrite];
+	bool		nulls[Natts_pg_rewrite] = {0};
 	NameData	rname;
 	Relation	pg_rewrite_desc;
 	HeapTuple	tup,
@@ -81,8 +80,6 @@ InsertRule(const char *rulname,
 	/*
 	 * Set up *nulls and *values arrays
 	 */
-	MemSet(nulls, false, sizeof(nulls));
-
 	namestrcpy(&rname, rulname);
 	values[Anum_pg_rewrite_rulename - 1] = NameGetDatum(&rname);
 	values[Anum_pg_rewrite_ev_class - 1] = ObjectIdGetDatum(eventrel_oid);
@@ -106,6 +103,8 @@ InsertRule(const char *rulname,
 
 	if (HeapTupleIsValid(oldtup))
 	{
+		bool		replaces[Natts_pg_rewrite] = {0};
+
 		if (!replace)
 			ereport(ERROR,
 					(errcode(ERRCODE_DUPLICATE_OBJECT),
@@ -115,7 +114,6 @@ InsertRule(const char *rulname,
 		/*
 		 * When replacing, we don't need to replace every attribute
 		 */
-		MemSet(replaces, false, sizeof(replaces));
 		replaces[Anum_pg_rewrite_ev_type - 1] = true;
 		replaces[Anum_pg_rewrite_is_instead - 1] = true;
 		replaces[Anum_pg_rewrite_ev_qual - 1] = true;
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 5f5803f681..ae6a1b1116 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -597,13 +597,12 @@ DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2)
 bool
 LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode)
 {
-	LOCALLOCKTAG localtag;
+	LOCALLOCKTAG localtag = {0};
 	LOCALLOCK  *locallock;
 
 	/*
 	 * See if there is a LOCALLOCK entry for this lock and lockmode
 	 */
-	MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
 	localtag.lock = *locktag;
 	localtag.mode = lockmode;
 
@@ -635,7 +634,7 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
 {
 	LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
 	LockMethod	lockMethodTable;
-	LOCALLOCKTAG localtag;
+	LOCALLOCKTAG localtag = {0};
 	LOCALLOCK  *locallock;
 	LOCK	   *lock;
 	PROCLOCK   *proclock;
@@ -658,7 +657,6 @@ LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
 	/*
 	 * Find the LOCALLOCK entry for this lock and lockmode
 	 */
-	MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
 	localtag.lock = *locktag;
 	localtag.mode = lockmode;
 
@@ -777,7 +775,7 @@ LockAcquireExtended(const LOCKTAG *locktag,
 {
 	LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
 	LockMethod	lockMethodTable;
-	LOCALLOCKTAG localtag;
+	LOCALLOCKTAG localtag = {0};
 	LOCALLOCK  *locallock;
 	LOCK	   *lock;
 	PROCLOCK   *proclock;
@@ -820,7 +818,6 @@ LockAcquireExtended(const LOCKTAG *locktag,
 	/*
 	 * Find or create a LOCALLOCK entry for this lock and lockmode
 	 */
-	MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
 	localtag.lock = *locktag;
 	localtag.mode = lockmode;
 
@@ -1976,7 +1973,7 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
 {
 	LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
 	LockMethod	lockMethodTable;
-	LOCALLOCKTAG localtag;
+	LOCALLOCKTAG localtag = {0};
 	LOCALLOCK  *locallock;
 	LOCK	   *lock;
 	PROCLOCK   *proclock;
@@ -1999,7 +1996,6 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
 	/*
 	 * Find the LOCALLOCK entry for this lock and lockmode
 	 */
-	MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */
 	localtag.lock = *locktag;
 	localtag.mode = lockmode;
 
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 38317edaf9..ce5e5c073f 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -384,7 +384,7 @@ print_lwlock_stats(int code, Datum arg)
 static lwlock_stats *
 get_lwlock_stats_entry(LWLock *lock)
 {
-	lwlock_stats_key key;
+	lwlock_stats_key key = {0};
 	lwlock_stats *lwstats;
 	bool		found;
 
@@ -397,7 +397,6 @@ get_lwlock_stats_entry(LWLock *lock)
 		return &lwlock_stats_dummy;
 
 	/* Fetch or create the entry. */
-	MemSet(&key, 0, sizeof(key));
 	key.tranche = lock->tranche;
 	key.instance = lock;
 	lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index b7fd3bcf05..6fa58dd8eb 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -1785,7 +1785,7 @@ aclexplode(PG_FUNCTION_ARGS)
 		{
 			Datum		result;
 			Datum		values[4];
-			bool		nulls[4];
+			bool		nulls[4] = {0};
 			HeapTuple	tuple;
 
 			values[0] = ObjectIdGetDatum(aidata->ai_grantor);
@@ -1793,8 +1793,6 @@ aclexplode(PG_FUNCTION_ARGS)
 			values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
 			values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
 
-			MemSet(nulls, 0, sizeof(nulls));
-
 			tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
 			result = HeapTupleGetDatum(tuple);
 
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index b0c37ede87..fb167f226a 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -742,11 +742,10 @@ ReadArrayStr(char *arrayStr,
 	bool		eoArray = false;
 	bool		hasnull;
 	int32		totbytes;
-	int			indx[MAXDIM],
+	int			indx[MAXDIM] = {0},
 				prod[MAXDIM];
 
 	mda_get_prod(ndim, dim, prod);
-	MemSet(indx, 0, sizeof(indx));
 
 	/* Initialize is-null markers to true */
 	memset(nulls, true, nitems * sizeof(bool));
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 4c12c4d663..8976f4e9f7 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4924,13 +4924,13 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
 	Datum		result;
 	HeapTuple	tuple;
 	Datum		values[3];
-	bool		nulls[3];
+	bool		nulls[3] = {0};
 	const datetkn *tp;
 	char		buffer[TOKMAXLEN + 1];
 	int			gmtoffset;
 	bool		is_dst;
 	unsigned char *p;
-	struct pg_itm_in itm_in;
+	struct pg_itm_in itm_in = {0};
 	Interval   *resInterval;
 
 	/* stuff done only on the first call of the function */
@@ -5011,8 +5011,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
 			break;
 	}
 
-	MemSet(nulls, 0, sizeof(nulls));
-
 	/*
 	 * Convert name to text, using upcasing conversion that is the inverse of
 	 * what ParseDateTime() uses.
@@ -5024,7 +5022,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
 	values[0] = CStringGetTextDatum(buffer);
 
 	/* Convert offset (in seconds) to an interval; can't overflow */
-	MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
 	itm_in.tm_usec = (int64) gmtoffset * USECS_PER_SEC;
 	resInterval = (Interval *) palloc(sizeof(Interval));
 	(void) itmin2interval(&itm_in, resInterval);
@@ -5051,13 +5048,13 @@ pg_timezone_names(PG_FUNCTION_ARGS)
 	pg_tzenum  *tzenum;
 	pg_tz	   *tz;
 	Datum		values[4];
-	bool		nulls[4];
+	bool		nulls[4] = {0};
 	int			tzoff;
 	struct pg_tm tm;
 	fsec_t		fsec;
 	const char *tzn;
 	Interval   *resInterval;
-	struct pg_itm_in itm_in;
+	struct pg_itm_in itm_in = {0};
 
 	SetSingleFuncCall(fcinfo, 0);
 
@@ -5088,13 +5085,10 @@ pg_timezone_names(PG_FUNCTION_ARGS)
 		if (tzn && strlen(tzn) > 31)
 			continue;
 
-		MemSet(nulls, 0, sizeof(nulls));
-
 		values[0] = CStringGetTextDatum(pg_get_timezone_name(tz));
 		values[1] = CStringGetTextDatum(tzn ? tzn : "");
 
 		/* Convert tzoff to an interval; can't overflow */
-		MemSet(&itm_in, 0, sizeof(struct pg_itm_in));
 		itm_in.tm_usec = (int64) -tzoff * USECS_PER_SEC;
 		resInterval = (Interval *) palloc(sizeof(Interval));
 		(void) itmin2interval(&itm_in, resInterval);
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index dedee7af5c..613f5f9bec 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -172,8 +172,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
 		LOCKMODE	mode = 0;
 		const char *locktypename;
 		char		tnbuf[32];
-		Datum		values[NUM_LOCK_STATUS_COLUMNS];
-		bool		nulls[NUM_LOCK_STATUS_COLUMNS];
+		Datum		values[NUM_LOCK_STATUS_COLUMNS] = {0};
+		bool		nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
 		HeapTuple	tuple;
 		Datum		result;
 		LockInstanceData *instance;
@@ -230,9 +230,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
 		/*
 		 * Form tuple with appropriate data.
 		 */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
-
 		if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
 			locktypename = LockTagTypeNames[instance->locktag.locktag_type];
 		else
@@ -359,8 +356,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
 
 		PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
 		SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
-		Datum		values[NUM_LOCK_STATUS_COLUMNS];
-		bool		nulls[NUM_LOCK_STATUS_COLUMNS];
+		Datum		values[NUM_LOCK_STATUS_COLUMNS] = {0};
+		bool		nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
 		HeapTuple	tuple;
 		Datum		result;
 
@@ -369,8 +366,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
 		/*
 		 * Form tuple with appropriate data.
 		 */
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, false, sizeof(nulls));
 
 		/* lock type */
 		lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.c
index 0243bc061f..109dc8023e 100644
--- a/src/backend/utils/adt/partitionfuncs.c
+++ b/src/backend/utils/adt/partitionfuncs.c
@@ -113,8 +113,8 @@ pg_partition_tree(PG_FUNCTION_ARGS)
 	if (funcctx->call_cntr < list_length(partitions))
 	{
 		Datum		result;
-		Datum		values[PG_PARTITION_TREE_COLS];
-		bool		nulls[PG_PARTITION_TREE_COLS];
+		Datum		values[PG_PARTITION_TREE_COLS] = {0};
+		bool		nulls[PG_PARTITION_TREE_COLS] = {0};
 		HeapTuple	tuple;
 		Oid			parentid = InvalidOid;
 		Oid			relid = list_nth_oid(partitions, funcctx->call_cntr);
@@ -126,8 +126,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
 		/*
 		 * Form tuple with appropriate data.
 		 */
-		MemSet(nulls, 0, sizeof(nulls));
-		MemSet(values, 0, sizeof(values));
 
 		/* relid */
 		values[0] = ObjectIdGetDatum(relid);
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 893690dad5..0a6369fdba 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -488,13 +488,10 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
 	{
 		LocalPgBackendStatus *local_beentry;
 		PgBackendStatus *beentry;
-		Datum		values[PG_STAT_GET_PROGRESS_COLS];
-		bool		nulls[PG_STAT_GET_PROGRESS_COLS];
+		Datum		values[PG_STAT_GET_PROGRESS_COLS] = {0};
+		bool		nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
 		int			i;
 
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
-
 		local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
 
 		if (!local_beentry)
@@ -551,17 +548,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
 	for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
 	{
 		/* for each row */
-		Datum		values[PG_STAT_GET_ACTIVITY_COLS];
-		bool		nulls[PG_STAT_GET_ACTIVITY_COLS];
+		Datum		values[PG_STAT_GET_ACTIVITY_COLS] = {0};
+		bool		nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
 		LocalPgBackendStatus *local_beentry;
 		PgBackendStatus *beentry;
 		PGPROC	   *proc;
 		const char *wait_event_type = NULL;
 		const char *wait_event = NULL;
 
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
-
 		/* Get the next one in the list */
 		local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
 		if (!local_beentry)
@@ -1747,15 +1741,11 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
 {
 #define PG_STAT_GET_WAL_COLS	9
 	TupleDesc	tupdesc;
-	Datum		values[PG_STAT_GET_WAL_COLS];
-	bool		nulls[PG_STAT_GET_WAL_COLS];
+	Datum		values[PG_STAT_GET_WAL_COLS] = {0};
+	bool		nulls[PG_STAT_GET_WAL_COLS] = {0};
 	char		buf[256];
 	PgStat_WalStats *wal_stats;
 
-	/* Initialise values and NULL flags arrays */
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	/* Initialise attributes information in the tuple descriptor */
 	tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
@@ -1827,7 +1817,7 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
 	{
 		/* for each row */
 		Datum		values[PG_STAT_GET_SLRU_COLS];
-		bool		nulls[PG_STAT_GET_SLRU_COLS];
+		bool		nulls[PG_STAT_GET_SLRU_COLS] = {0};
 		PgStat_SLRUStats stat;
 		const char *name;
 
@@ -1837,8 +1827,6 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
 			break;
 
 		stat = stats[i];
-		MemSet(values, 0, sizeof(values));
-		MemSet(nulls, 0, sizeof(nulls));
 
 		values[0] = PointerGetDatum(cstring_to_text(name));
 		values[1] = Int64GetDatum(stat.blocks_zeroed);
@@ -2201,14 +2189,10 @@ Datum
 pg_stat_get_archiver(PG_FUNCTION_ARGS)
 {
 	TupleDesc	tupdesc;
-	Datum		values[7];
-	bool		nulls[7];
+	Datum		values[7] = {0};
+	bool		nulls[7] = {0};
 	PgStat_ArchiverStats *archiver_stats;
 
-	/* Initialise values and NULL flags arrays */
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	/* Initialise attributes information in the tuple descriptor */
 	tupdesc = CreateTemplateTupleDesc(7);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
@@ -2274,15 +2258,11 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
 	text	   *slotname_text = PG_GETARG_TEXT_P(0);
 	NameData	slotname;
 	TupleDesc	tupdesc;
-	Datum		values[PG_STAT_GET_REPLICATION_SLOT_COLS];
-	bool		nulls[PG_STAT_GET_REPLICATION_SLOT_COLS];
+	Datum		values[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
+	bool		nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
 	PgStat_StatReplSlotEntry *slotent;
 	PgStat_StatReplSlotEntry allzero;
 
-	/* Initialise values and NULL flags arrays */
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	/* Initialise attributes information in the tuple descriptor */
 	tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_REPLICATION_SLOT_COLS);
 	TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
@@ -2348,8 +2328,8 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
 #define PG_STAT_GET_SUBSCRIPTION_STATS_COLS	4
 	Oid			subid = PG_GETARG_OID(0);
 	TupleDesc	tupdesc;
-	Datum		values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
-	bool		nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
+	Datum		values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
+	bool		nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
 	PgStat_StatSubEntry *subentry;
 	PgStat_StatSubEntry allzero;
 
@@ -2368,10 +2348,6 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
 					   TIMESTAMPTZOID, -1, 0);
 	BlessTupleDesc(tupdesc);
 
-	/* Initialise values and NULL flags arrays */
-	MemSet(values, 0, sizeof(values));
-	MemSet(nulls, 0, sizeof(nulls));
-
 	if (!subentry)
 	{
 		/* If the subscription is not found, initialise its stats */
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index fa1f589fad..6f99b5b243 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -6642,10 +6642,10 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 			   double *indexPages)
 {
 	IndexOptInfo *index = path->indexinfo;
-	GenericCosts costs;
+	GenericCosts costs = {0};
 	Oid			relid;
 	AttrNumber	colnum;
-	VariableStatData vardata;
+	VariableStatData vardata = {0};
 	double		numIndexTuples;
 	Cost		descentCost;
 	List	   *indexBoundQuals;
@@ -6797,7 +6797,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 	/*
 	 * Now do generic index cost estimation.
 	 */
-	MemSet(&costs, 0, sizeof(costs));
 	costs.numIndexTuples = numIndexTuples;
 
 	genericcostestimate(root, path, loop_count, &costs);
@@ -6842,8 +6841,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 	 * ordering, but don't negate it entirely.  Before 8.0 we divided the
 	 * correlation by the number of columns, but that seems too strong.)
 	 */
-	MemSet(&vardata, 0, sizeof(vardata));
-
 	if (index->indexkeys[0] != 0)
 	{
 		/* Simple variable --- look to stats for the underlying table */
@@ -6947,9 +6944,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 				 Selectivity *indexSelectivity, double *indexCorrelation,
 				 double *indexPages)
 {
-	GenericCosts costs;
-
-	MemSet(&costs, 0, sizeof(costs));
+	GenericCosts costs = {0};
 
 	genericcostestimate(root, path, loop_count, &costs);
 
@@ -6992,11 +6987,9 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 				 double *indexPages)
 {
 	IndexOptInfo *index = path->indexinfo;
-	GenericCosts costs;
+	GenericCosts costs = {0};
 	Cost		descentCost;
 
-	MemSet(&costs, 0, sizeof(costs));
-
 	genericcostestimate(root, path, loop_count, &costs);
 
 	/*
@@ -7049,11 +7042,9 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 				double *indexPages)
 {
 	IndexOptInfo *index = path->indexinfo;
-	GenericCosts costs;
+	GenericCosts costs = {0};
 	Cost		descentCost;
 
-	MemSet(&costs, 0, sizeof(costs));
-
 	genericcostestimate(root, path, loop_count, &costs);
 
 	/*
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index f70f829d83..0a17f45e92 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -2403,7 +2403,7 @@ interval_cmp_value(const Interval *interval)
 }
 
 static int
-interval_cmp_internal(Interval *interval1, Interval *interval2)
+interval_cmp_internal(const Interval *interval1, const Interval *interval2)
 {
 	INT128		span1 = interval_cmp_value(interval1);
 	INT128		span2 = interval_cmp_value(interval2);
@@ -5777,7 +5777,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
 		Timestamp	finish = PG_GETARG_TIMESTAMP(1);
 		Interval   *step = PG_GETARG_INTERVAL_P(2);
 		MemoryContext oldcontext;
-		Interval	interval_zero;
+		Interval	interval_zero = {0};
 
 		/* create a function context for cross-call persistence */
 		funcctx = SRF_FIRSTCALL_INIT();
@@ -5800,7 +5800,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
 		fctx->step = *step;
 
 		/* Determine sign of the interval */
-		MemSet(&interval_zero, 0, sizeof(Interval));
 		fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
 
 		if (fctx->step_sign == 0)
@@ -5857,7 +5856,7 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
 		TimestampTz finish = PG_GETARG_TIMESTAMPTZ(1);
 		Interval   *step = PG_GETARG_INTERVAL_P(2);
 		MemoryContext oldcontext;
-		Interval	interval_zero;
+		Interval	interval_zero = {0};
 
 		/* create a function context for cross-call persistence */
 		funcctx = SRF_FIRSTCALL_INIT();
@@ -5880,7 +5879,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
 		fctx->step = *step;
 
 		/* Determine sign of the interval */
-		MemSet(&interval_zero, 0, sizeof(Interval));
 		fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
 
 		if (fctx->step_sign == 0)
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index 3858fc5928..7d78219b62 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -853,7 +853,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
 	int			len,
 				i,
 				doclen = 0;
-	CoverExt	ext;
+	CoverExt	ext = {0};
 	double		Wdoc = 0.0;
 	double		invws[lengthof(weights)];
 	double		SumDist = 0.0,
@@ -883,7 +883,6 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
 		return 0.0;
 	}
 
-	MemSet(&ext, 0, sizeof(CoverExt));
 	while (Cover(doc, doclen, &qr, &ext))
 	{
 		double		Cpos = 0.0;
diff --git a/src/backend/utils/cache/relfilenumbermap.c b/src/backend/utils/cache/relfilenumbermap.c
index c4245d5ccd..ada0efa8f2 100644
--- a/src/backend/utils/cache/relfilenumbermap.c
+++ b/src/backend/utils/cache/relfilenumbermap.c
@@ -143,7 +143,7 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
 	SysScanDesc scandesc;
 	Relation	relation;
 	HeapTuple	ntp;
-	ScanKeyData skey[2];
+	ScanKeyData skey[2] = {0};
 	Oid			relid;
 
 	if (RelfilenumberMapHash == NULL)
@@ -153,7 +153,6 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
 	if (reltablespace == MyDatabaseTableSpace)
 		reltablespace = 0;
 
-	MemSet(&key, 0, sizeof(key));
 	key.reltablespace = reltablespace;
 	key.relfilenumber = relfilenumber;
 
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index 24808dfbb1..70e88fd228 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -414,7 +414,7 @@ lookup_ts_config_cache(Oid cfgId)
 		ScanKeyData mapskey;
 		SysScanDesc mapscan;
 		HeapTuple	maptup;
-		ListDictionary maplists[MAXTOKENTYPE + 1];
+		ListDictionary maplists[MAXTOKENTYPE + 1] = {0};
 		Oid			mapdicts[MAXDICTSPERTT];
 		int			maxtokentype;
 		int			ndicts;
@@ -468,7 +468,6 @@ lookup_ts_config_cache(Oid cfgId)
 		 * see the entries in maptokentype order, and in mapseqno order for
 		 * each token type, even though we didn't explicitly ask for that.
 		 */
-		MemSet(maplists, 0, sizeof(maplists));
 		maxtokentype = 0;
 		ndicts = 0;
 
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 8520ce76bb..264d0ab1df 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -376,7 +376,7 @@ set_ps_display(const char *activity)
 #ifdef PS_USE_CLOBBER_ARGV
 	/* pad unused memory; need only clobber remainder of old status string */
 	if (last_status_len > ps_buffer_cur_len)
-		MemSet(ps_buffer + ps_buffer_cur_len, PS_PADDING,
+		memset(ps_buffer + ps_buffer_cur_len, PS_PADDING,
 			   last_status_len - ps_buffer_cur_len);
 	last_status_len = ps_buffer_cur_len;
 #endif							/* PS_USE_CLOBBER_ARGV */
diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 6f5e08bc30..284b9153ea 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -211,13 +211,11 @@ schedule_alarm(TimestampTz now)
 {
 	if (num_active_timeouts > 0)
 	{
-		struct itimerval timeval;
+		struct itimerval timeval = {0};
 		TimestampTz nearest_timeout;
 		long		secs;
 		int			usecs;
 
-		MemSet(&timeval, 0, sizeof(struct itimerval));
-
 		/*
 		 * If we think there's a signal pending, but current time is more than
 		 * 10ms past when the signal was due, then assume that the timeout
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index d549f66d4a..3a161bdb88 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -1146,14 +1146,12 @@ pg_cursor(PG_FUNCTION_ARGS)
 	{
 		Portal		portal = hentry->portal;
 		Datum		values[6];
-		bool		nulls[6];
+		bool		nulls[6] = {0};
 
 		/* report only "visible" entries */
 		if (!portal->visible)
 			continue;
 
-		MemSet(nulls, 0, sizeof(nulls));
-
 		values[0] = CStringGetTextDatum(portal->name);
 		values[1] = CStringGetTextDatum(portal->sourceText);
 		values[2] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_HOLD);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 4445a86aee..79b23fa7d7 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -447,7 +447,7 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
 	{
 #ifndef WIN32
 		fd_set		fds;
-		struct timeval tv;
+		struct timeval tv = {0};
 		int			r;
 
 		/*
@@ -457,16 +457,13 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
 		FD_ZERO(&fds);
 		FD_SET(bgpipe[0], &fds);
 
-		MemSet(&tv, 0, sizeof(tv));
-
 		r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
 		if (r == 1)
 		{
-			char		xlogend[64];
+			char		xlogend[64] = {0};
 			uint32		hi,
 						lo;
 
-			MemSet(xlogend, 0, sizeof(xlogend));
 			r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
 			if (r < 0)
 				pg_fatal("could not read from ready pipe: %m");
@@ -528,11 +525,10 @@ typedef struct
 static int
 LogStreamerMain(logstreamer_param *param)
 {
-	StreamCtl	stream;
+	StreamCtl	stream = {0};
 
 	in_log_streamer = true;
 
-	MemSet(&stream, 0, sizeof(stream));
 	stream.startpos = param->startptr;
 	stream.timeline = param->timeline;
 	stream.sysidentifier = param->sysidentifier;
@@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
 	else
 		starttli = latesttli;
 	PQclear(res);
-	MemSet(xlogend, 0, sizeof(xlogend));
 
 	if (verbose && includewal != NO_WAL)
 		pg_log_info("write-ahead log start point: %s on timeline %u",
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index ea3902c971..f064cff4ab 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -564,11 +564,9 @@ StreamLog(void)
 {
 	XLogRecPtr	serverpos;
 	TimeLineID	servertli;
-	StreamCtl	stream;
+	StreamCtl	stream = {0};
 	char	   *sysidentifier;
 
-	MemSet(&stream, 0, sizeof(stream));
-
 	/*
 	 * Connect in replication mode to the server
 	 */
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index ef4c11277a..e90aa0ba37 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -1111,9 +1111,8 @@ tar_close(Walfile f, WalCloseMethod method)
 	padding = tarPaddingBytesRequired(filesize);
 	if (padding)
 	{
-		char		zerobuf[TAR_BLOCK_SIZE];
+		char		zerobuf[TAR_BLOCK_SIZE] = {0};
 
-		MemSet(zerobuf, 0, padding);
 		if (tar_write(f, zerobuf, padding) != padding)
 			return -1;
 	}
@@ -1222,7 +1221,7 @@ tar_existsfile(const char *pathname)
 static bool
 tar_finish(void)
 {
-	char		zerobuf[1024];
+	char		zerobuf[1024] = {0};
 
 	tar_clear_error();
 
@@ -1233,7 +1232,6 @@ tar_finish(void)
 	}
 
 	/* A tarfile always ends with two empty blocks */
-	MemSet(zerobuf, 0, sizeof(zerobuf));
 	if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
 	{
 		errno = 0;
diff --git a/src/common/ip.c b/src/common/ip.c
index cd73d49679..267103efb9 100644
--- a/src/common/ip.c
+++ b/src/common/ip.c
@@ -165,14 +165,12 @@ static int
 getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
 				 struct addrinfo **result)
 {
-	struct addrinfo hints;
+	struct addrinfo hints = {0};
 	struct addrinfo *aip;
 	struct sockaddr_un *unp;
 
 	*result = NULL;
 
-	MemSet(&hints, 0, sizeof(hints));
-
 	if (strlen(path) >= sizeof(unp->sun_path))
 		return EAI_FAIL;
 
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index dc49387d6c..0362500386 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2325,7 +2325,7 @@ keep_going:						/* We will come back to here until there is
 	if (conn->try_next_host)
 	{
 		pg_conn_host *ch;
-		struct addrinfo hint;
+		struct addrinfo hint = {0};
 		int			thisport;
 		int			ret;
 		char		portstr[MAXPGPATH];
@@ -2364,7 +2364,6 @@ keep_going:						/* We will come back to here until there is
 		ch = &conn->connhost[conn->whichhost];
 
 		/* Initialize hint structure */
-		MemSet(&hint, 0, sizeof(hint));
 		hint.ai_socktype = SOCK_STREAM;
 		conn->addrlist_family = hint.ai_family = AF_UNSPEC;
 
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index edb93ec1c4..6272e093c5 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1841,10 +1841,9 @@ plperl_call_handler(PG_FUNCTION_ARGS)
 	Datum		retval = (Datum) 0;
 	plperl_call_data *volatile save_call_data = current_call_data;
 	plperl_interp_desc *volatile oldinterp = plperl_active_interp;
-	plperl_call_data this_call_data;
+	plperl_call_data this_call_data = {0};
 
 	/* Initialize current-call status record */
-	MemSet(&this_call_data, 0, sizeof(this_call_data));
 	this_call_data.fcinfo = fcinfo;
 
 	PG_TRY();
@@ -1882,16 +1881,13 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
 {
 	LOCAL_FCINFO(fake_fcinfo, 0);
 	InlineCodeBlock *codeblock = (InlineCodeBlock *) PG_GETARG_POINTER(0);
-	FmgrInfo	flinfo;
-	plperl_proc_desc desc;
+	FmgrInfo	flinfo = {0};
+	plperl_proc_desc desc = {0};
 	plperl_call_data *volatile save_call_data = current_call_data;
 	plperl_interp_desc *volatile oldinterp = plperl_active_interp;
-	plperl_call_data this_call_data;
+	plperl_call_data this_call_data = {0};
 	ErrorContextCallback pl_error_context;
 
-	/* Initialize current-call status record */
-	MemSet(&this_call_data, 0, sizeof(this_call_data));
-
 	/* Set up a callback for error reporting */
 	pl_error_context.callback = plperl_inline_callback;
 	pl_error_context.previous = error_context_stack;
@@ -1904,8 +1900,6 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
 	 * with no arguments passed, and a result type of VOID.
 	 */
 	MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
-	MemSet(&flinfo, 0, sizeof(flinfo));
-	MemSet(&desc, 0, sizeof(desc));
 	fake_fcinfo->flinfo = &flinfo;
 	flinfo.fn_oid = InvalidOid;
 	flinfo.fn_mcxt = CurrentMemoryContext;
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index 190d286f1c..1f8c9edfa8 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -317,7 +317,7 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
 	LOCAL_FCINFO(fake_fcinfo, 0);
 	InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
 	PLpgSQL_function *func;
-	FmgrInfo	flinfo;
+	FmgrInfo	flinfo = {0};
 	EState	   *simple_eval_estate;
 	ResourceOwner simple_eval_resowner;
 	Datum		retval;
@@ -341,7 +341,6 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
 	 * with no arguments passed.
 	 */
 	MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
-	MemSet(&flinfo, 0, sizeof(flinfo));
 	fake_fcinfo->flinfo = &flinfo;
 	flinfo.fn_oid = InvalidOid;
 	flinfo.fn_mcxt = CurrentMemoryContext;
@@ -502,10 +501,10 @@ plpgsql_validator(PG_FUNCTION_ARGS)
 	if (check_function_bodies)
 	{
 		LOCAL_FCINFO(fake_fcinfo, 0);
-		FmgrInfo	flinfo;
+		FmgrInfo	flinfo = {0};
 		int			rc;
-		TriggerData trigdata;
-		EventTriggerData etrigdata;
+		TriggerData trigdata = {0};
+		EventTriggerData etrigdata = {0};
 
 		/*
 		 * Connect to SPI manager (is this needed for compilation?)
@@ -518,19 +517,16 @@ plpgsql_validator(PG_FUNCTION_ARGS)
 		 * plpgsql_compile().
 		 */
 		MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
-		MemSet(&flinfo, 0, sizeof(flinfo));
 		fake_fcinfo->flinfo = &flinfo;
 		flinfo.fn_oid = funcoid;
 		flinfo.fn_mcxt = CurrentMemoryContext;
 		if (is_dml_trigger)
 		{
-			MemSet(&trigdata, 0, sizeof(trigdata));
 			trigdata.type = T_TriggerData;
 			fake_fcinfo->context = (Node *) &trigdata;
 		}
 		else if (is_event_trigger)
 		{
-			MemSet(&etrigdata, 0, sizeof(etrigdata));
 			etrigdata.type = T_EventTriggerData;
 			fake_fcinfo->context = (Node *) &etrigdata;
 		}
diff --git a/src/pl/plpython/plpy_main.c b/src/pl/plpython/plpy_main.c
index 0bce106495..1df2dd536c 100644
--- a/src/pl/plpython/plpy_main.c
+++ b/src/pl/plpython/plpy_main.c
@@ -266,8 +266,8 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
 {
 	LOCAL_FCINFO(fake_fcinfo, 0);
 	InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
-	FmgrInfo	flinfo;
-	PLyProcedure proc;
+	FmgrInfo	flinfo = {0};
+	PLyProcedure proc = {0};
 	PLyExecutionContext *exec_ctx;
 	ErrorContextCallback plerrcontext;
 
@@ -278,12 +278,10 @@ plpython3_inline_handler(PG_FUNCTION_ARGS)
 		elog(ERROR, "SPI_connect failed");
 
 	MemSet(fcinfo, 0, SizeForFunctionCallInfo(0));
-	MemSet(&flinfo, 0, sizeof(flinfo));
 	fake_fcinfo->flinfo = &flinfo;
 	flinfo.fn_oid = InvalidOid;
 	flinfo.fn_mcxt = CurrentMemoryContext;
 
-	MemSet(&proc, 0, sizeof(PLyProcedure));
 	proc.mcxt = AllocSetContextCreate(TopMemoryContext,
 									  "__plpython_inline_block",
 									  ALLOCSET_DEFAULT_SIZES);
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index abb1c59770..d4cf368075 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -756,12 +756,10 @@ find_arguments(const char *format, va_list args,
 	int			longflag;
 	int			fmtpos;
 	int			i;
-	int			last_dollar;
-	PrintfArgType argtypes[PG_NL_ARGMAX + 1];
 
 	/* Initialize to "no dollar arguments known" */
-	last_dollar = 0;
-	MemSet(argtypes, 0, sizeof(argtypes));
+	int			last_dollar = 0;
+	PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};
 
 	/*
 	 * This loop must accept the same format strings as the one in dopr().
diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c
index 3b19e0eadc..2ce88cb624 100644
--- a/src/test/modules/test_predtest/test_predtest.c
+++ b/src/test/modules/test_predtest/test_predtest.c
@@ -50,7 +50,7 @@ test_predtest(PG_FUNCTION_ARGS)
 				strong_refuted_by,
 				weak_refuted_by;
 	Datum		values[8];
-	bool		nulls[8];
+	bool		nulls[8] = {0};
 	int			i;
 
 	/* We use SPI to parse, plan, and execute the test query */
@@ -204,7 +204,6 @@ test_predtest(PG_FUNCTION_ARGS)
 					   "w_r_holds", BOOLOID, -1, 0);
 	tupdesc = BlessTupleDesc(tupdesc);
 
-	MemSet(nulls, 0, sizeof(nulls));
 	values[0] = BoolGetDatum(strong_implied_by);
 	values[1] = BoolGetDatum(weak_implied_by);
 	values[2] = BoolGetDatum(strong_refuted_by);
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index ba3532a51e..b88d70b6fc 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1110,7 +1110,7 @@ test_enc_conversion(PG_FUNCTION_ARGS)
 	int			convertedbytes;
 	int			dstlen;
 	Datum		values[2];
-	bool		nulls[2];
+	bool		nulls[2] = {0};
 	HeapTuple	tuple;
 
 	if (src_encoding < 0)
@@ -1199,7 +1199,6 @@ test_enc_conversion(PG_FUNCTION_ARGS)
 		pfree(dst);
 	}
 
-	MemSet(nulls, 0, sizeof(nulls));
 	values[0] = Int32GetDatum(convertedbytes);
 	values[1] = PointerGetDatum(retval);
 	tuple = heap_form_tuple(tupdesc, values, nulls);