diff --git a/contrib/fuzzystrmatch/fuzzystrmatch.c b/contrib/fuzzystrmatch/fuzzystrmatch.c
index d237772a3b..a025e1dd80 100644
--- a/contrib/fuzzystrmatch/fuzzystrmatch.c
+++ b/contrib/fuzzystrmatch/fuzzystrmatch.c
@@ -360,7 +360,7 @@ _metaphone(char *word,			/* IN */
 		elog(ERROR, "metaphone: Requested output length must be > 0");
 
 	/* Empty/null string is meaningless */
-	if ((word == NULL) || !(strlen(word) > 0))
+	if (word == NULL || word[0] == '\0')
 		/* internal error */
 		elog(ERROR, "metaphone: Input string length must be > 0");
 
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index b98deb72ec..535347c964 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -727,7 +727,7 @@ pg_backup_start_time(PG_FUNCTION_ARGS)
 				(errcode_for_file_access(),
 				 errmsg("could not close file \"%s\": %m", BACKUP_LABEL_FILE)));
 
-	if (strlen(backup_start_time) == 0)
+	if (backup_start_time[0] == '\0')
 		ereport(ERROR,
 				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
 				 errmsg("invalid data in file \"%s\"", BACKUP_LABEL_FILE)));
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c
index 834f1a2a3f..cd68152874 100644
--- a/src/backend/commands/comment.c
+++ b/src/backend/commands/comment.c
@@ -153,7 +153,7 @@ CreateComments(Oid oid, Oid classoid, int32 subid, const char *comment)
 	int			i;
 
 	/* Reduce empty-string to NULL case */
-	if (comment != NULL && strlen(comment) == 0)
+	if (comment != NULL && comment[0] == '\0')
 		comment = NULL;
 
 	/* Prepare to form or update a tuple, if necessary */
@@ -248,7 +248,7 @@ CreateSharedComments(Oid oid, Oid classoid, const char *comment)
 	int			i;
 
 	/* Reduce empty-string to NULL case */
-	if (comment != NULL && strlen(comment) == 0)
+	if (comment != NULL && comment[0] == '\0')
 		comment = NULL;
 
 	/* Prepare to form or update a tuple, if necessary */
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 79d875ab10..5ae9fb3817 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1004,7 +1004,7 @@ interpret_AS_clause(Oid languageOid, const char *languageName,
 			 * modicum of backwards compatibility, accept an empty "prosrc"
 			 * value as meaning the supplied SQL function name.
 			 */
-			if (strlen(*prosrc_str_p) == 0)
+			if (**prosrc_str_p == '\0')
 				*prosrc_str_p = funcname;
 		}
 	}
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 8cc23ef7fb..96ca8dc6ed 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -1108,7 +1108,7 @@ pg_GSS_checkauth(Port *port)
 			*cp = '\0';
 		cp++;
 
-		if (port->hba->krb_realm != NULL && strlen(port->hba->krb_realm))
+		if (port->hba->krb_realm != NULL && port->hba->krb_realm[0] != '\0')
 		{
 			/*
 			 * Match the realm part of the name first
@@ -1129,7 +1129,7 @@ pg_GSS_checkauth(Port *port)
 			}
 		}
 	}
-	else if (port->hba->krb_realm && strlen(port->hba->krb_realm))
+	else if (port->hba->krb_realm && port->hba->krb_realm[0] != '\0')
 	{
 		elog(DEBUG2,
 			 "GSSAPI did not return realm but realm matching was requested");
@@ -1453,7 +1453,7 @@ pg_SSPI_recvauth(Port *port)
 	 * Compare realm/domain if requested. In SSPI, always compare case
 	 * insensitive.
 	 */
-	if (port->hba->krb_realm && strlen(port->hba->krb_realm))
+	if (port->hba->krb_realm && port->hba->krb_realm[0] != '\0')
 	{
 		if (pg_strcasecmp(port->hba->krb_realm, domainname) != 0)
 		{
@@ -1968,7 +1968,7 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message **msg,
 		switch (msg[i]->msg_style)
 		{
 			case PAM_PROMPT_ECHO_OFF:
-				if (strlen(passwd) == 0)
+				if (passwd[0] == '\0')
 				{
 					/*
 					 * Password wasn't passed to PAM the first time around -
@@ -2766,7 +2766,7 @@ CheckCertAuth(Port *port)
 
 	/* Make sure we have received a username in the certificate */
 	if (peer_username == NULL ||
-		strlen(peer_username) <= 0)
+		peer_username[0] == '\0')
 	{
 		ereport(LOG,
 				(errmsg("certificate authentication failed for user \"%s\": client certificate contains no user name",
diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
index 19ea159af4..b489a2356c 100644
--- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
+++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
@@ -325,11 +325,11 @@ libpqrcv_get_senderinfo(WalReceiverConn *conn, char **sender_host,
 	Assert(conn->streamConn != NULL);
 
 	ret = PQhost(conn->streamConn);
-	if (ret && strlen(ret) != 0)
+	if (ret && ret[0] != '\0')
 		*sender_host = pstrdup(ret);
 
 	ret = PQport(conn->streamConn);
-	if (ret && strlen(ret) != 0)
+	if (ret && ret[0] != '\0')
 		*sender_port = atoi(ret);
 }
 
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 33e9acab4a..7c1a0003f4 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -173,7 +173,7 @@ ReplicationSlotValidateName(const char *name, int elevel)
 {
 	const char *cp;
 
-	if (strlen(name) == 0)
+	if (name[0] == '\0')
 	{
 		ereport(elevel,
 				(errcode(ERRCODE_INVALID_NAME),
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index a340a5f6af..73cb47bea4 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -3660,7 +3660,7 @@ fsync_parent_path(const char *fname, int elevel)
 	 * just a file name (see comments in path.c), so handle that as being the
 	 * current directory.
 	 */
-	if (strlen(parentpath) == 0)
+	if (parentpath[0] == '\0')
 		strlcpy(parentpath, ".", MAXPGPATH);
 
 	if (fsync_fname_ext(parentpath, true, false, elevel) != 0)
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 3ae5cfac9e..350b4af6dd 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -2631,13 +2631,13 @@ xmldata_root_element_start(StringInfo result, const char *eltname,
 	if (top_level)
 	{
 		appendStringInfoString(result, " xmlns:xsi=\"" NAMESPACE_XSI "\"");
-		if (strlen(targetns) > 0)
+		if (targetns[0] != '\0')
 			appendStringInfo(result, " xmlns=\"%s\"", targetns);
 	}
 	if (xmlschema)
 	{
 		/* FIXME: better targets */
-		if (strlen(targetns) > 0)
+		if (targetns[0] != '\0')
 			appendStringInfo(result, " xsi:schemaLocation=\"%s #\"", targetns);
 		else
 			appendStringInfoString(result, " xsi:noNamespaceSchemaLocation=\"#\"");
@@ -2900,7 +2900,7 @@ xsd_schema_element_start(StringInfo result, const char *targetns)
 	appendStringInfoString(result,
 						   "<xsd:schema\n"
 						   "    xmlns:xsd=\"" NAMESPACE_XSD "\"");
-	if (strlen(targetns) > 0)
+	if (targetns[0] != '\0')
 		appendStringInfo(result,
 						 "\n"
 						 "    targetNamespace=\"%s\"\n"
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index e8c6cdde97..bf675b89c0 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -594,7 +594,7 @@ find_in_dynamic_libpath(const char *basename)
 	AssertState(Dynamic_library_path != NULL);
 
 	p = Dynamic_library_path;
-	if (strlen(p) == 0)
+	if (p[0] == '\0')
 		return NULL;
 
 	baselen = strlen(basename);
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index ea67e52a3f..c1848ff31b 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -74,14 +74,14 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
 				secondsql;
 	bool		found_owner_privs = false;
 
-	if (strlen(acls) == 0 && strlen(racls) == 0)
+	if (acls[0] == '\0' && racls[0] == '\0')
 		return true;			/* object has default permissions */
 
 	/* treat empty-string owner same as NULL */
 	if (owner && *owner == '\0')
 		owner = NULL;
 
-	if (strlen(acls) != 0)
+	if (acls[0] != '\0')
 	{
 		if (!parsePGArray(acls, &aclitems, &naclitems))
 		{
@@ -91,7 +91,7 @@ buildACLCommands(const char *name, const char *subname, const char *nspname,
 		}
 	}
 
-	if (strlen(racls) != 0)
+	if (racls[0] != '\0')
 	{
 		if (!parsePGArray(racls, &raclitems, &nraclitems))
 		{
@@ -403,7 +403,7 @@ buildDefaultACLCommands(const char *type, const char *nspname,
 	if (nspname)
 		appendPQExpBuffer(prefix, "IN SCHEMA %s ", fmtId(nspname));
 
-	if (strlen(initacls) != 0 || strlen(initracls) != 0)
+	if (initacls[0] != '\0' || initracls[0] != '\0')
 	{
 		appendPQExpBufferStr(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
 		if (!buildACLCommands("", NULL, NULL, type,
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index ee06dc6822..913c2c6b8a 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -765,9 +765,9 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
 	/* Dump any relevant dump warnings to stderr */
 	if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0)
 	{
-		if (!ropt->dataOnly && te->defn != NULL && strlen(te->defn) != 0)
+		if (!ropt->dataOnly && te->defn != NULL && te->defn[0] != '\0')
 			pg_log_warning("warning from original dump file: %s", te->defn);
-		else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0)
+		else if (te->copyStmt != NULL && te->copyStmt[0] != '\0')
 			pg_log_warning("warning from original dump file: %s", te->copyStmt);
 	}
 
@@ -916,7 +916,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
 					/*
 					 * If we have a copy statement, use it.
 					 */
-					if (te->copyStmt && strlen(te->copyStmt) > 0)
+					if (te->copyStmt && te->copyStmt[0] != '\0')
 					{
 						ahprintf(AH, "%s", te->copyStmt);
 						AH->outputKind = OUTPUT_COPYDATA;
@@ -3519,7 +3519,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
 		free(sanitized_schema);
 		free(sanitized_owner);
 
-		if (te->tablespace && strlen(te->tablespace) > 0 && !ropt->noTablespace)
+		if (te->tablespace && te->tablespace[0] != '\0' && !ropt->noTablespace)
 		{
 			char	   *sanitized_tablespace;
 
@@ -3549,7 +3549,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
 	}
 	else
 	{
-		if (te->defn && strlen(te->defn) > 0)
+		if (te->defn && te->defn[0] != '\0')
 			ahprintf(AH, "%s\n\n", te->defn);
 	}
 
@@ -3565,8 +3565,8 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
 		(!ropt->use_setsessauth ||
 		 (strcmp(te->desc, "SCHEMA") == 0 &&
 		  strncmp(te->defn, "--", 2) == 0)) &&
-		te->owner && strlen(te->owner) > 0 &&
-		te->dropStmt && strlen(te->dropStmt) > 0)
+		te->owner && te->owner[0] != '\0' &&
+		te->dropStmt && te->dropStmt[0] != '\0')
 	{
 		if (strcmp(te->desc, "AGGREGATE") == 0 ||
 			strcmp(te->desc, "BLOB") == 0 ||
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index fb8c7713a5..919902f8c6 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -289,7 +289,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
 	}
 
 	tctx->filename = ReadStr(AH);
-	if (strlen(tctx->filename) == 0)
+	if (tctx->filename[0] == '\0')
 	{
 		free(tctx->filename);
 		tctx->filename = NULL;
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 65bcb41a2f..2cc669d77f 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -289,7 +289,7 @@ _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
 	}
 
 	ctx->filename = ReadStr(AH);
-	if (strlen(ctx->filename) == 0)
+	if (ctx->filename[0] == '\0')
 	{
 		free(ctx->filename);
 		ctx->filename = NULL;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 34b91bb226..e6b27f43a1 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -2983,24 +2983,24 @@ dumpDatabase(Archive *fout)
 	 */
 	appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0",
 					  qdatname);
-	if (strlen(encoding) > 0)
+	if (encoding[0] != '\0')
 	{
 		appendPQExpBufferStr(creaQry, " ENCODING = ");
 		appendStringLiteralAH(creaQry, encoding, fout);
 	}
-	if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
+	if (collate[0] != '\0' && strcmp(collate, ctype) == 0)
 	{
 		appendPQExpBufferStr(creaQry, " LOCALE = ");
 		appendStringLiteralAH(creaQry, collate, fout);
 	}
 	else
 	{
-		if (strlen(collate) > 0)
+		if (collate[0] != '\0')
 		{
 			appendPQExpBufferStr(creaQry, " LC_COLLATE = ");
 			appendStringLiteralAH(creaQry, collate, fout);
 		}
-		if (strlen(ctype) > 0)
+		if (ctype[0] != '\0')
 		{
 			appendPQExpBufferStr(creaQry, " LC_CTYPE = ");
 			appendStringLiteralAH(creaQry, ctype, fout);
@@ -3015,7 +3015,7 @@ dumpDatabase(Archive *fout)
 	 * tablespace selection logic work ... but CREATE DATABASE doesn't pay
 	 * attention to default_tablespace, so that won't work.
 	 */
-	if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0 &&
+	if (tablespace[0] != '\0' && strcmp(tablespace, "pg_default") != 0 &&
 		!dopt->outputNoTablespaces)
 		appendPQExpBuffer(creaQry, " TABLESPACE = %s",
 						  fmtId(tablespace));
@@ -3121,7 +3121,7 @@ dumpDatabase(Archive *fout)
 	resetPQExpBuffer(creaQry);
 	resetPQExpBuffer(delQry);
 
-	if (strlen(datconnlimit) > 0 && strcmp(datconnlimit, "-1") != 0)
+	if (datconnlimit[0] != '\0' && strcmp(datconnlimit, "-1") != 0)
 		appendPQExpBuffer(creaQry, "ALTER DATABASE %s CONNECTION LIMIT = %s;\n",
 						  qdatname, datconnlimit);
 
@@ -4050,7 +4050,7 @@ getPublications(Archive *fout, int *numPublications)
 		pubinfo[i].pubviaroot =
 			(strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
 
-		if (strlen(pubinfo[i].rolname) == 0)
+		if (pubinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of publication \"%s\" appears to be invalid",
 						   pubinfo[i].dobj.name);
 
@@ -4424,7 +4424,7 @@ getSubscriptions(Archive *fout)
 		subinfo[i].subtwophasestate =
 			pg_strdup(PQgetvalue(res, i, i_subtwophasestate));
 
-		if (strlen(subinfo[i].rolname) == 0)
+		if (subinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of subscription \"%s\" appears to be invalid",
 						   subinfo[i].dobj.name);
 
@@ -4980,7 +4980,7 @@ getNamespaces(Archive *fout, int *numNamespaces)
 			PQgetisnull(res, i, i_initrnspacl))
 			nsinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
 
-		if (strlen(nsinfo[i].rolname) == 0)
+		if (nsinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of schema \"%s\" appears to be invalid",
 						   nsinfo[i].dobj.name);
 	}
@@ -5332,7 +5332,7 @@ getTypes(Archive *fout, int *numTypes)
 			stinfo->dobj.dump = DUMP_COMPONENT_NONE;
 		}
 
-		if (strlen(tyinfo[i].rolname) == 0)
+		if (tyinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of data type \"%s\" appears to be invalid",
 						   tyinfo[i].dobj.name);
 	}
@@ -5416,7 +5416,7 @@ getOperators(Archive *fout, int *numOprs)
 		/* Operators do not currently have ACLs. */
 		oprinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
 
-		if (strlen(oprinfo[i].rolname) == 0)
+		if (oprinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of operator \"%s\" appears to be invalid",
 						   oprinfo[i].dobj.name);
 	}
@@ -5715,7 +5715,7 @@ getOpclasses(Archive *fout, int *numOpclasses)
 		/* Op Classes do not currently have ACLs. */
 		opcinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
 
-		if (strlen(opcinfo[i].rolname) == 0)
+		if (opcinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of operator class \"%s\" appears to be invalid",
 						   opcinfo[i].dobj.name);
 	}
@@ -5798,7 +5798,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
 		/* Extensions do not currently have ACLs. */
 		opfinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
 
-		if (strlen(opfinfo[i].rolname) == 0)
+		if (opfinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of operator family \"%s\" appears to be invalid",
 						   opfinfo[i].dobj.name);
 	}
@@ -5966,7 +5966,7 @@ getAggregates(Archive *fout, int *numAggs)
 		agginfo[i].aggfn.dobj.namespace =
 			findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)));
 		agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
-		if (strlen(agginfo[i].aggfn.rolname) == 0)
+		if (agginfo[i].aggfn.rolname[0] == '\0')
 			pg_log_warning("owner of aggregate function \"%s\" appears to be invalid",
 						   agginfo[i].aggfn.dobj.name);
 		agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
@@ -6225,7 +6225,7 @@ getFuncs(Archive *fout, int *numFuncs)
 			PQgetisnull(res, i, i_initrproacl))
 			finfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL;
 
-		if (strlen(finfo[i].rolname) == 0)
+		if (finfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of function \"%s\" appears to be invalid",
 						   finfo[i].dobj.name);
 	}
@@ -7053,7 +7053,7 @@ getTables(Archive *fout, int *numTables)
 		}
 
 		/* Emit notice if join for owner failed */
-		if (strlen(tblinfo[i].rolname) == 0)
+		if (tblinfo[i].rolname[0] == '\0')
 			pg_log_warning("owner of table \"%s\" appears to be invalid",
 						   tblinfo[i].dobj.name);
 	}
@@ -13402,7 +13402,7 @@ dumpOpclass(Archive *fout, const OpclassInfo *opcinfo)
 	appendPQExpBuffer(q, "FOR TYPE %s USING %s",
 					  opcintype,
 					  fmtId(amname));
-	if (strlen(opcfamilyname) > 0)
+	if (opcfamilyname[0] != '\0')
 	{
 		appendPQExpBufferStr(q, " FAMILY ");
 		appendPQExpBuffer(q, "%s.", fmtId(opcfamilynsp));
@@ -13520,7 +13520,7 @@ dumpOpclass(Archive *fout, const OpclassInfo *opcinfo)
 		appendPQExpBuffer(q, "OPERATOR %s %s",
 						  amopstrategy, amopopr);
 
-		if (strlen(sortfamily) > 0)
+		if (sortfamily[0] != '\0')
 		{
 			appendPQExpBufferStr(q, " FOR ORDER BY ");
 			appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp));
@@ -13840,7 +13840,7 @@ dumpOpfamily(Archive *fout, const OpfamilyInfo *opfinfo)
 			appendPQExpBuffer(q, "OPERATOR %s %s",
 							  amopstrategy, amopopr);
 
-			if (strlen(sortfamily) > 0)
+			if (sortfamily[0] != '\0')
 			{
 				appendPQExpBufferStr(q, " FOR ORDER BY ");
 				appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp));
@@ -14918,7 +14918,7 @@ dumpForeignDataWrapper(Archive *fout, const FdwInfo *fdwinfo)
 	if (strcmp(fdwinfo->fdwvalidator, "-") != 0)
 		appendPQExpBuffer(q, " VALIDATOR %s", fdwinfo->fdwvalidator);
 
-	if (strlen(fdwinfo->fdwoptions) > 0)
+	if (fdwinfo->fdwoptions[0] != '\0')
 		appendPQExpBuffer(q, " OPTIONS (\n    %s\n)", fdwinfo->fdwoptions);
 
 	appendPQExpBufferStr(q, ";\n");
@@ -14994,12 +14994,12 @@ dumpForeignServer(Archive *fout, const ForeignServerInfo *srvinfo)
 	fdwname = PQgetvalue(res, 0, 0);
 
 	appendPQExpBuffer(q, "CREATE SERVER %s", qsrvname);
-	if (srvinfo->srvtype && strlen(srvinfo->srvtype) > 0)
+	if (srvinfo->srvtype && srvinfo->srvtype[0] != '\0')
 	{
 		appendPQExpBufferStr(q, " TYPE ");
 		appendStringLiteralAH(q, srvinfo->srvtype, fout);
 	}
-	if (srvinfo->srvversion && strlen(srvinfo->srvversion) > 0)
+	if (srvinfo->srvversion && srvinfo->srvversion[0] != '\0')
 	{
 		appendPQExpBufferStr(q, " VERSION ");
 		appendStringLiteralAH(q, srvinfo->srvversion, fout);
@@ -15008,7 +15008,7 @@ dumpForeignServer(Archive *fout, const ForeignServerInfo *srvinfo)
 	appendPQExpBufferStr(q, " FOREIGN DATA WRAPPER ");
 	appendPQExpBufferStr(q, fmtId(fdwname));
 
-	if (srvinfo->srvoptions && strlen(srvinfo->srvoptions) > 0)
+	if (srvinfo->srvoptions && srvinfo->srvoptions[0] != '\0')
 		appendPQExpBuffer(q, " OPTIONS (\n    %s\n)", srvinfo->srvoptions);
 
 	appendPQExpBufferStr(q, ";\n");
@@ -15124,7 +15124,7 @@ dumpUserMappings(Archive *fout,
 		appendPQExpBuffer(q, "CREATE USER MAPPING FOR %s", fmtId(usename));
 		appendPQExpBuffer(q, " SERVER %s", fmtId(servername));
 
-		if (umoptions && strlen(umoptions) > 0)
+		if (umoptions && umoptions[0] != '\0')
 			appendPQExpBuffer(q, " OPTIONS (\n    %s\n)", umoptions);
 
 		appendPQExpBufferStr(q, ";\n");
@@ -15289,7 +15289,7 @@ dumpACL(Archive *fout, DumpId objDumpId, DumpId altDumpId,
 	 * are to be recorded by calling binary_upgrade_set_record_init_privs()
 	 * before and after.
 	 */
-	if (strlen(initacls) != 0 || strlen(initracls) != 0)
+	if (initacls[0] != '\0' || initracls[0] != '\0')
 	{
 		appendPQExpBufferStr(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
 		if (!buildACLCommands(name, subname, nspname, type,
@@ -16849,7 +16849,7 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
 		 * If the index has any statistics on some of its columns, generate
 		 * the associated ALTER INDEX queries.
 		 */
-		if (strlen(indstatcols) != 0 || strlen(indstatvals) != 0)
+		if (indstatcols[0] != '\0' || indstatvals[0] != '\0')
 		{
 			int			j;
 
@@ -18344,7 +18344,7 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[],
 									curext->dobj.catId.oid))
 			continue;
 
-		if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
+		if (extconfig[0] != '\0' || extcondition[0] != '\0')
 		{
 			int			j;
 
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 589b4aed53..fb5c574c90 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -172,11 +172,11 @@ main(int argc, char **argv)
 				opts->filename = pg_strdup(optarg);
 				break;
 			case 'F':
-				if (strlen(optarg) != 0)
+				if (optarg[0] != '\0')
 					opts->formatName = pg_strdup(optarg);
 				break;
 			case 'h':
-				if (strlen(optarg) != 0)
+				if (optarg[0] != '\0')
 					opts->cparams.pghost = pg_strdup(optarg);
 				break;
 
@@ -205,7 +205,7 @@ main(int argc, char **argv)
 				break;
 
 			case 'p':
-				if (strlen(optarg) != 0)
+				if (optarg[0] != '\0')
 					opts->cparams.pgport = pg_strdup(optarg);
 				break;
 			case 'R':
@@ -230,7 +230,7 @@ main(int argc, char **argv)
 				opts->schemaOnly = 1;
 				break;
 			case 'S':			/* Superuser username */
-				if (strlen(optarg) != 0)
+				if (optarg[0] != '\0')
 					opts->superuser = pg_strdup(optarg);
 				break;
 			case 't':			/* Dump specified table(s) only */
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 0c47a6b8cc..f6cb10c088 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -589,7 +589,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
 		 * Do the old cluster's per-database directories share a directory
 		 * with a new version-specific tablespace?
 		 */
-		if (strlen(old_cluster.tablespace_suffix) == 0)
+		if (old_cluster.tablespace_suffix[0] == '\0')
 		{
 			/* delete per-database directories */
 			int			dbnum;
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 5d9a26cf82..acc9736a1d 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -168,7 +168,7 @@ create_rel_filename_map(const char *old_data, const char *new_data,
 						FileNameMap *map)
 {
 	/* In case old/new tablespaces don't match, do them separately. */
-	if (strlen(old_rel->tablespace) == 0)
+	if (old_rel->tablespace[0] == '\0')
 	{
 		/*
 		 * relation belongs to the default tablespace, hence relfiles should
@@ -185,7 +185,7 @@ create_rel_filename_map(const char *old_data, const char *new_data,
 	}
 
 	/* Do the same for new tablespaces */
-	if (strlen(new_rel->tablespace) == 0)
+	if (new_rel->tablespace[0] == '\0')
 	{
 		map->new_tablespace = new_data;
 		map->new_tablespace_suffix = "/base";
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index 64bbda5650..d0880e9688 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -360,7 +360,7 @@ check_required_directory(char **dirpath, const char *envVarName, bool useCwd,
 						 const char *cmdLineOption, const char *description,
 						 bool missingOk)
 {
-	if (*dirpath == NULL || strlen(*dirpath) == 0)
+	if (*dirpath == NULL || **dirpath == '\0')
 	{
 		const char *envVar;
 
diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c
index 7fed0ae108..5db69620fe 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -373,7 +373,7 @@ check_pghost_envvar(void)
 		{
 			const char *value = getenv(option->envvar);
 
-			if (value && strlen(value) > 0 &&
+			if (value && value[0] != '\0' &&
 			/* check for 'local' host values */
 				(strcmp(value, "localhost") != 0 && strcmp(value, "127.0.0.1") != 0 &&
 				 strcmp(value, "::1") != 0 && value[0] != '/'))
diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index fc20472fe7..0e51c48aee 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -75,7 +75,7 @@ prep_status(const char *fmt,...)
 	vsnprintf(message, sizeof(message), fmt, args);
 	va_end(args);
 
-	if (strlen(message) > 0 && message[strlen(message) - 1] == '\n')
+	if (message[0] != '\0' && message[strlen(message) - 1] == '\n')
 		pg_log(PG_REPORT, "%s", message);
 	else
 		/* trim strings that don't end in a newline */
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 5640786678..415d88ce67 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -2257,7 +2257,7 @@ expand_tilde(char **filename)
 			strlcpy(home, pw->pw_dir, sizeof(home));	/* ~user */
 
 		*p = oldp;
-		if (strlen(home) != 0)
+		if (home[0] != '\0')
 		{
 			char	   *newfn;
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index d3fda67edd..b2cf5d1f2e 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -530,7 +530,7 @@ helpSQL(const char *topic, unsigned short int pager)
 {
 #define VALUE_OR_NULL(a) ((a) ? (a) : "")
 
-	if (!topic || strlen(topic) == 0)
+	if (!topic || topic[0] == '\0')
 	{
 		/* Print all the available command names */
 		int			screen_width;
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index f926bc98dc..74b25fe643 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -368,7 +368,7 @@ initializeInput(int flags)
 			char	   *envhist;
 
 			envhist = getenv("PSQL_HISTORY");
-			if (envhist != NULL && strlen(envhist) > 0)
+			if (envhist != NULL && envhist[0] != '\0')
 				histfile = envhist;
 		}
 
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 2931530f33..34903d78dc 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -790,7 +790,7 @@ process_psqlrc(char *argv0)
 	snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
 	process_psqlrc_file(rc_file);
 
-	if (envrc != NULL && strlen(envrc) > 0)
+	if (envrc != NULL && envrc[0] != '\0')
 	{
 		/* might need to free() this */
 		char	   *envrc_alloc = pstrdup(envrc);
diff --git a/src/common/file_utils.c b/src/common/file_utils.c
index 40b73bbe1a..fa9e780744 100644
--- a/src/common/file_utils.c
+++ b/src/common/file_utils.c
@@ -328,7 +328,7 @@ fsync_parent_path(const char *fname)
 	 * just a file name (see comments in path.c), so handle that as being the
 	 * current directory.
 	 */
-	if (strlen(parentpath) == 0)
+	if (parentpath[0] == '\0')
 		strlcpy(parentpath, ".", MAXPGPATH);
 
 	if (fsync_fname(parentpath, true) != 0)
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 60564b176c..de35a5ef70 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -446,7 +446,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 				*tmp = '\0';
 			}
 
-			if (strlen(dbname) > 0)
+			if (dbname[0] != '\0')
 			{
 				realname = ecpg_strdup(dbname, lineno);
 				connect_params++;
@@ -486,7 +486,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 			 host ? host : "<DEFAULT>",
 			 port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
 			 options ? "with options " : "", options ? options : "",
-			 (user && strlen(user) > 0) ? "for user " : "", user ? user : "");
+			 (user && user[0] != '\0') ? "for user " : "", user ? user : "");
 
 	/* count options (this may produce an overestimate, it's ok) */
 	if (options)
@@ -494,9 +494,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 			if (options[i] == '=')
 				connect_params++;
 
-	if (user && strlen(user) > 0)
+	if (user && user[0] != '\0')
 		connect_params++;
-	if (passwd && strlen(passwd) > 0)
+	if (passwd && passwd[0] != '\0')
 		connect_params++;
 
 	/* allocate enough space for all connection parameters */
@@ -541,13 +541,13 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 		conn_values[i] = port;
 		i++;
 	}
-	if (user && strlen(user) > 0)
+	if (user && user[0] != '\0')
 	{
 		conn_keywords[i] = "user";
 		conn_values[i] = user;
 		i++;
 	}
-	if (passwd && strlen(passwd) > 0)
+	if (passwd && passwd[0] != '\0')
 	{
 		conn_keywords[i] = "password";
 		conn_values[i] = passwd;
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index d4b4da5ffc..84c40d3eac 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -565,7 +565,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
 		 * If size i.e. the size of structure of which this variable is part
 		 * of, that gives the offset to the next element, if required
 		 */
-		if (size == NULL || strlen(size) == 0)
+		if (size == NULL || size[0] == '\0')
 			fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
 		else
 			fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, size);
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index e950b41374..c93144f06c 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -7151,7 +7151,7 @@ sslVerifyProtocolVersion(const char *version)
 	 * An empty string and a NULL value are considered valid as it is
 	 * equivalent to ignoring the parameter.
 	 */
-	if (!version || strlen(version) == 0)
+	if (!version || version[0] == '\0')
 		return true;
 
 	if (pg_strcasecmp(version, "TLSv1") == 0 ||
@@ -7177,7 +7177,7 @@ sslVerifyProtocolRange(const char *min, const char *max)
 		   sslVerifyProtocolVersion(max));
 
 	/* If at least one of the bounds is not set, the range is valid */
-	if (min == NULL || max == NULL || strlen(min) == 0 || strlen(max) == 0)
+	if (min == NULL || max == NULL || min[0] == '\0' || max[0] == '\0')
 		return true;
 
 	/*
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index 2ee5a0a40a..629e690d54 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -802,11 +802,11 @@ initialize_SSL(PGconn *conn)
 	 * defaulted.  If pqGetHomeDirectory fails, act as though none of the
 	 * files could be found.
 	 */
-	if (!(conn->sslcert && strlen(conn->sslcert) > 0) ||
-		!(conn->sslkey && strlen(conn->sslkey) > 0) ||
-		!(conn->sslrootcert && strlen(conn->sslrootcert) > 0) ||
-		!((conn->sslcrl && strlen(conn->sslcrl) > 0) ||
-		  (conn->sslcrldir && strlen(conn->sslcrldir) > 0)))
+	if (!(conn->sslcert && conn->sslcert[0] != '\0') ||
+		!(conn->sslkey && conn->sslkey[0] != '\0') ||
+		!(conn->sslrootcert && conn->sslrootcert[0] != '\0') ||
+		!((conn->sslcrl && conn->sslcrl[0] != '\0') ||
+		  (conn->sslcrldir && conn->sslcrldir[0] != '\0')))
 		have_homedir = pqGetHomeDirectory(homedir, sizeof(homedir));
 	else						/* won't need it */
 		have_homedir = false;
@@ -843,7 +843,7 @@ initialize_SSL(PGconn *conn)
 	 * harmless.
 	 */
 	if (PQsslKeyPassHook
-		|| (conn->sslpassword && strlen(conn->sslpassword) > 0))
+		|| (conn->sslpassword && conn->sslpassword[0] != '\0'))
 	{
 		SSL_CTX_set_default_passwd_cb(SSL_context, PQssl_passwd_cb);
 		SSL_CTX_set_default_passwd_cb_userdata(SSL_context, conn);
@@ -854,7 +854,7 @@ initialize_SSL(PGconn *conn)
 
 	/* Set the minimum and maximum protocol versions if necessary */
 	if (conn->ssl_min_protocol_version &&
-		strlen(conn->ssl_min_protocol_version) != 0)
+		conn->ssl_min_protocol_version[0] != '\0')
 	{
 		int			ssl_min_ver;
 
@@ -883,7 +883,7 @@ initialize_SSL(PGconn *conn)
 	}
 
 	if (conn->ssl_max_protocol_version &&
-		strlen(conn->ssl_max_protocol_version) != 0)
+		conn->ssl_max_protocol_version[0] != '\0')
 	{
 		int			ssl_max_ver;
 
@@ -922,7 +922,7 @@ initialize_SSL(PGconn *conn)
 	 * verification. If sslmode is "verify-full" we will also do further
 	 * verification after the connection has been completed.
 	 */
-	if (conn->sslrootcert && strlen(conn->sslrootcert) > 0)
+	if (conn->sslrootcert && conn->sslrootcert[0] != '\0')
 		strlcpy(fnbuf, conn->sslrootcert, sizeof(fnbuf));
 	else if (have_homedir)
 		snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CERT_FILE);
@@ -951,9 +951,9 @@ initialize_SSL(PGconn *conn)
 			char	   *fname = NULL;
 			char	   *dname = NULL;
 
-			if (conn->sslcrl && strlen(conn->sslcrl) > 0)
+			if (conn->sslcrl && conn->sslcrl[0] != '\0')
 				fname = conn->sslcrl;
-			if (conn->sslcrldir && strlen(conn->sslcrldir) > 0)
+			if (conn->sslcrldir && conn->sslcrldir[0] != '\0')
 				dname = conn->sslcrldir;
 
 			/* defaults to use the default CRL file */
@@ -1005,7 +1005,7 @@ initialize_SSL(PGconn *conn)
 	}
 
 	/* Read the client certificate file */
-	if (conn->sslcert && strlen(conn->sslcert) > 0)
+	if (conn->sslcert && conn->sslcert[0] != '\0')
 		strlcpy(fnbuf, conn->sslcert, sizeof(fnbuf));
 	else if (have_homedir)
 		snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_CERT_FILE);
@@ -1119,7 +1119,7 @@ initialize_SSL(PGconn *conn)
 	 * colon in the name. The exception is if the second character is a colon,
 	 * in which case it can be a Windows filename with drive specification.
 	 */
-	if (have_cert && conn->sslkey && strlen(conn->sslkey) > 0)
+	if (have_cert && conn->sslkey && conn->sslkey[0] != '\0')
 	{
 #ifdef USE_SSL_ENGINE
 		if (strchr(conn->sslkey, ':')
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index 3d47d37eae..105b9e080a 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -411,7 +411,7 @@ pg_get_encoding_from_locale(const char *ctype, bool write_message)
 	 * Current macOS has many locales that report an empty string for CODESET,
 	 * but they all seem to actually use UTF-8.
 	 */
-	if (strlen(sys) == 0)
+	if (sys[0] == '\0')
 	{
 		free(sys);
 		return PG_UTF8;
