From b79b48a261d82c425d734b97ec035e74f308f07f Mon Sep 17 00:00:00 2001
From: vignesh <vignesh@localhost.localdomain>
Date: Sun, 20 Oct 2019 18:06:10 +0530
Subject: [PATCH 3/3] Ordering of header files.

Ordering of header files that is included in source code.
---
 src/bin/pg_archivecleanup/pg_archivecleanup.c           |  6 ++----
 src/bin/pg_basebackup/pg_basebackup.c                   |  2 +-
 src/bin/pg_basebackup/pg_receivewal.c                   |  6 ++----
 src/bin/pg_basebackup/pg_recvlogical.c                  |  8 +++-----
 src/bin/pg_basebackup/receivelog.c                      | 10 ++++------
 src/bin/pg_basebackup/streamutil.c                      |  7 +++----
 src/bin/pg_basebackup/walmethods.c                      |  3 +--
 src/bin/pg_config/pg_config.c                           |  2 +-
 src/bin/pg_controldata/pg_controldata.c                 |  3 +--
 src/bin/pg_dump/common.c                                |  8 +++-----
 src/bin/pg_dump/parallel.c                              |  3 +--
 src/bin/pg_dump/pg_backup_archiver.c                    |  7 +++----
 src/bin/pg_dump/pg_backup_custom.c                      |  3 +--
 src/bin/pg_dump/pg_backup_db.c                          | 16 +++++++---------
 src/bin/pg_dump/pg_backup_directory.c                   |  8 ++++----
 src/bin/pg_dump/pg_backup_null.c                        |  5 ++---
 src/bin/pg_dump/pg_backup_tar.c                         | 14 +++++++-------
 src/bin/pg_dump/pg_dump.c                               | 13 +++++--------
 src/bin/pg_dump/pg_dump_sort.c                          |  3 +--
 src/bin/pg_dump/pg_dumpall.c                            |  7 +++----
 src/bin/pg_dump/pg_restore.c                            |  4 +---
 src/bin/pg_resetwal/pg_resetwal.c                       |  7 +++----
 src/bin/pg_rewind/copy_fetch.c                          |  2 +-
 src/bin/pg_rewind/datapagemap.c                         |  3 +--
 src/bin/pg_rewind/fetch.c                               |  2 +-
 src/bin/pg_rewind/file_ops.c                            |  2 +-
 src/bin/pg_rewind/filemap.c                             |  7 +++----
 src/bin/pg_rewind/libpq_fetch.c                         |  7 +++----
 src/bin/pg_rewind/parsexlog.c                           |  6 ++----
 src/bin/pg_rewind/pg_rewind.c                           |  9 ++++-----
 src/bin/pg_rewind/timeline.c                            |  1 -
 src/bin/pg_test_fsync/pg_test_fsync.c                   |  3 +--
 src/bin/pg_upgrade/check.c                              |  3 +--
 src/bin/pg_upgrade/controldata.c                        |  1 -
 src/bin/pg_upgrade/dump.c                               |  2 --
 src/bin/pg_upgrade/exec.c                               |  3 +--
 src/bin/pg_upgrade/file.c                               | 11 +++++------
 src/bin/pg_upgrade/function.c                           |  2 --
 src/bin/pg_upgrade/info.c                               |  2 --
 src/bin/pg_upgrade/option.c                             |  6 ++----
 src/bin/pg_upgrade/parallel.c                           |  4 +---
 src/bin/pg_upgrade/pg_upgrade.c                         | 10 +++++-----
 src/bin/pg_upgrade/relfilenode.c                        |  5 ++---
 src/bin/pg_upgrade/server.c                             |  3 +--
 src/bin/pg_upgrade/tablespace.c                         |  1 -
 src/bin/pg_upgrade/util.c                               |  3 +--
 src/bin/pg_upgrade/version.c                            |  3 ---
 src/bin/pg_waldump/compat.c                             |  2 +-
 src/bin/pg_waldump/pg_waldump.c                         |  3 +--
 src/bin/pgbench/pgbench.c                               | 15 ++++++++-------
 src/bin/psql/common.c                                   | 10 ++++------
 src/bin/psql/copy.c                                     |  8 +++-----
 src/bin/psql/crosstabview.c                             |  3 +--
 src/bin/psql/describe.c                                 |  7 ++-----
 src/bin/psql/help.c                                     |  3 +--
 src/bin/psql/input.c                                    |  5 ++---
 src/bin/psql/large_obj.c                                |  5 ++---
 src/bin/psql/mainloop.c                                 |  8 +++-----
 src/bin/psql/prompt.c                                   |  3 +--
 src/bin/psql/startup.c                                  | 10 +++-------
 src/bin/psql/variables.c                                |  4 +---
 src/common/f2s.c                                        |  3 +--
 src/fe_utils/print.c                                    |  4 +---
 src/fe_utils/recovery_gen.c                             |  3 +--
 src/fe_utils/string_utils.c                             |  4 +---
 src/interfaces/ecpg/compatlib/informix.c                | 16 ++++++++--------
 src/interfaces/ecpg/ecpglib/connect.c                   |  4 ++--
 src/interfaces/ecpg/ecpglib/data.c                      | 10 +++++-----
 src/interfaces/ecpg/ecpglib/descriptor.c                |  5 ++---
 src/interfaces/ecpg/ecpglib/error.c                     |  2 +-
 src/interfaces/ecpg/ecpglib/execute.c                   | 17 ++++++++---------
 src/interfaces/ecpg/ecpglib/memory.c                    |  4 ++--
 src/interfaces/ecpg/ecpglib/misc.c                      | 10 +++++-----
 src/interfaces/ecpg/ecpglib/prepare.c                   |  4 ++--
 src/interfaces/ecpg/ecpglib/sqlda.c                     |  9 ++++-----
 src/interfaces/ecpg/ecpglib/typename.c                  |  5 ++---
 src/interfaces/ecpg/pgtypeslib/common.c                 |  2 +-
 src/interfaces/ecpg/pgtypeslib/datetime.c               |  4 ++--
 src/interfaces/ecpg/pgtypeslib/dt_common.c              |  2 +-
 src/interfaces/ecpg/pgtypeslib/interval.c               |  4 ++--
 src/interfaces/ecpg/pgtypeslib/numeric.c                |  4 ++--
 src/interfaces/ecpg/pgtypeslib/timestamp.c              |  5 ++---
 src/interfaces/ecpg/preproc/c_keywords.c                |  5 ++---
 src/interfaces/ecpg/preproc/ecpg_keywords.c             |  5 ++---
 src/interfaces/libpq/fe-auth.c                          |  3 +--
 src/interfaces/libpq/fe-connect.c                       | 10 ++++------
 src/interfaces/libpq/fe-exec.c                          |  9 ++++-----
 src/interfaces/libpq/fe-misc.c                          |  3 +--
 src/interfaces/libpq/fe-protocol2.c                     |  8 +++-----
 src/interfaces/libpq/fe-protocol3.c                     | 10 ++++------
 src/interfaces/libpq/fe-secure-gssapi.c                 |  2 +-
 src/interfaces/libpq/fe-secure.c                        |  8 ++++----
 src/pl/plpgsql/src/pl_comp.c                            |  4 +---
 src/pl/plpgsql/src/pl_exec.c                            |  4 +---
 src/pl/plpgsql/src/pl_funcs.c                           |  4 +---
 src/pl/plpgsql/src/pl_handler.c                         |  4 +---
 src/port/pg_crc32c_armv8.c                              |  4 ++--
 src/port/pg_crc32c_sse42.c                              |  4 ++--
 src/port/tar.c                                          |  4 +++-
 src/test/isolation/isolationtester.c                    |  5 ++---
 .../modules/test_ginpostinglist/test_ginpostinglist.c   |  2 +-
 src/test/modules/test_integerset/test_integerset.c      |  6 +++---
 src/test/modules/test_rls_hooks/test_rls_hooks.c        |  7 ++-----
 src/test/modules/test_shm_mq/setup.c                    |  3 +--
 src/test/modules/worker_spi/worker_spi.c                | 16 +++++++---------
 src/test/regress/pg_regress.c                           |  3 +--
 src/test/regress/regress.c                              |  3 +--
 107 files changed, 238 insertions(+), 351 deletions(-)

diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index bb4257f..2917d7f 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -15,11 +15,9 @@
 #include <signal.h>
 #include <sys/time.h>
 
-#include "pg_getopt.h"
-
-#include "common/logging.h"
-
 #include "access/xlog_internal.h"
+#include "common/logging.h"
+#include "pg_getopt.h"
 
 const char *progname;
 
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 55ef139..a9d162a 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -35,9 +35,9 @@
 #include "fe_utils/string_utils.h"
 #include "getopt_long.h"
 #include "libpq-fe.h"
-#include "pqexpbuffer.h"
 #include "pgtar.h"
 #include "pgtime.h"
+#include "pqexpbuffer.h"
 #include "receivelog.h"
 #include "replication/basebackup.h"
 #include "streamutil.h"
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index f39c133..c0c8747 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -19,16 +19,14 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "access/xlog_internal.h"
 #include "common/file_perm.h"
 #include "common/logging.h"
-#include "libpq-fe.h"
-#include "access/xlog_internal.h"
 #include "getopt_long.h"
-
+#include "libpq-fe.h"
 #include "receivelog.h"
 #include "streamutil.h"
 
-
 /* Time to sleep between reconnection attempts */
 #define RECONNECT_SLEEP_TIME 5
 
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index af29dd7..fb5d875 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -11,6 +11,8 @@
  */
 
 #include "postgres_fe.h"
+/* local includes */
+#include "streamutil.h"
 
 #include <dirent.h>
 #include <sys/stat.h>
@@ -19,19 +21,15 @@
 #include <sys/select.h>
 #endif
 
-/* local includes */
-#include "streamutil.h"
-
 #include "access/xlog_internal.h"
-#include "common/file_perm.h"
 #include "common/fe_memutils.h"
+#include "common/file_perm.h"
 #include "common/logging.h"
 #include "getopt_long.h"
 #include "libpq-fe.h"
 #include "libpq/pqsignal.h"
 #include "pqexpbuffer.h"
 
-
 /* Time to sleep between reconnection attempts */
 #define RECONNECT_SLEEP_TIME 5
 
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index d73f614..69088d8 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -13,6 +13,9 @@
  */
 
 #include "postgres_fe.h"
+/* local includes */
+#include "receivelog.h"
+#include "streamutil.h"
 
 #include <sys/stat.h>
 #include <unistd.h>
@@ -20,15 +23,10 @@
 #include <sys/select.h>
 #endif
 
-/* local includes */
-#include "receivelog.h"
-#include "streamutil.h"
-
-#include "libpq-fe.h"
 #include "access/xlog_internal.h"
 #include "common/file_utils.h"
 #include "common/logging.h"
-
+#include "libpq-fe.h"
 
 /* fd and filename for currently open WAL file */
 static Walfile *walfile = NULL;
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 8d8ac11..f937a77 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -13,14 +13,13 @@
  */
 
 #include "postgres_fe.h"
-
-#include <sys/time.h>
-#include <unistd.h>
-
 /* local includes */
 #include "receivelog.h"
 #include "streamutil.h"
 
+#include <sys/time.h>
+#include <unistd.h>
+
 #include "access/xlog_internal.h"
 #include "common/fe_memutils.h"
 #include "common/file_perm.h"
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index 8ec12e6..d4d15b3 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -21,10 +21,9 @@
 #include <zlib.h>
 #endif
 
-#include "pgtar.h"
 #include "common/file_perm.h"
 #include "common/file_utils.h"
-
+#include "pgtar.h"
 #include "receivelog.h"
 #include "streamutil.h"
 
diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c
index 5279e7f..a1da918 100644
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -24,8 +24,8 @@
 
 #include "postgres_fe.h"
 
-#include "port.h"
 #include "common/config_info.h"
+#include "port.h"
 
 static const char *progname;
 
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index ff17804..b14767f 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -26,9 +26,8 @@
 #include "catalog/pg_control.h"
 #include "common/controldata_utils.h"
 #include "common/logging.h"
-#include "pg_getopt.h"
 #include "getopt_long.h"
-
+#include "pg_getopt.h"
 
 static void
 usage(const char *progname)
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index 3549f7b..37432a6 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -15,15 +15,13 @@
  */
 #include "postgres_fe.h"
 
-#include "pg_backup_archiver.h"
-#include "pg_backup_utils.h"
-#include "pg_dump.h"
-
 #include <ctype.h>
 
 #include "catalog/pg_class_d.h"
 #include "fe_utils/string_utils.h"
-
+#include "pg_backup_archiver.h"
+#include "pg_backup_utils.h"
+#include "pg_dump.h"
 
 /*
  * Variables for mapping DumpId to DumpableObject
diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c
index 03479f1..24239fa 100644
--- a/src/bin/pg_dump/parallel.c
+++ b/src/bin/pg_dump/parallel.c
@@ -61,10 +61,9 @@
 #include <sys/select.h>
 #endif
 
+#include "fe_utils/string_utils.h"
 #include "parallel.h"
 #include "pg_backup_utils.h"
-
-#include "fe_utils/string_utils.h"
 #include "port/pg_bswap.h"
 
 /* Mnemonic macros for indexing the fd array returned by pipe(2) */
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 6c739ce..d051f26 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -30,14 +30,13 @@
 #include <io.h>
 #endif
 
+#include "dumputils.h"
+#include "fe_utils/string_utils.h"
+#include "libpq/libpq-fs.h"
 #include "parallel.h"
 #include "pg_backup_archiver.h"
 #include "pg_backup_db.h"
 #include "pg_backup_utils.h"
-#include "dumputils.h"
-#include "fe_utils/string_utils.h"
-
-#include "libpq/libpq-fs.h"
 
 #define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n"
 #define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n"
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c
index 497b81b..fc742f5 100644
--- a/src/bin/pg_dump/pg_backup_custom.c
+++ b/src/bin/pg_dump/pg_backup_custom.c
@@ -25,11 +25,10 @@
  */
 #include "postgres_fe.h"
 
+#include "common/file_utils.h"
 #include "compress_io.h"
 #include "parallel.h"
 #include "pg_backup_utils.h"
-#include "common/file_utils.h"
-
 
 /*--------
  * Routines in the format interface
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index ee822c5..6dba7e1 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -11,21 +11,19 @@
  */
 #include "postgres_fe.h"
 
-#include "fe_utils/connect.h"
-#include "fe_utils/string_utils.h"
-
-#include "dumputils.h"
-#include "parallel.h"
-#include "pg_backup_archiver.h"
-#include "pg_backup_db.h"
-#include "pg_backup_utils.h"
-
 #include <unistd.h>
 #include <ctype.h>
 #ifdef HAVE_TERMIOS_H
 #include <termios.h>
 #endif
 
+#include "dumputils.h"
+#include "fe_utils/connect.h"
+#include "fe_utils/string_utils.h"
+#include "parallel.h"
+#include "pg_backup_archiver.h"
+#include "pg_backup_db.h"
+#include "pg_backup_utils.h"
 
 static void _check_database_version(ArchiveHandle *AH);
 static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser);
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index e1afecf..aa00bca 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -34,13 +34,13 @@
  */
 #include "postgres_fe.h"
 
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "common/file_utils.h"
 #include "compress_io.h"
 #include "parallel.h"
 #include "pg_backup_utils.h"
-#include "common/file_utils.h"
-
-#include <dirent.h>
-#include <sys/stat.h>
 
 typedef struct
 {
diff --git a/src/bin/pg_dump/pg_backup_null.c b/src/bin/pg_dump/pg_backup_null.c
index 32c911a..c62f943 100644
--- a/src/bin/pg_dump/pg_backup_null.c
+++ b/src/bin/pg_dump/pg_backup_null.c
@@ -23,11 +23,10 @@
  */
 #include "postgres_fe.h"
 
-#include "pg_backup_archiver.h"
-#include "pg_backup_utils.h"
 #include "fe_utils/string_utils.h"
-
 #include "libpq/libpq-fs.h"
+#include "pg_backup_archiver.h"
+#include "pg_backup_utils.h"
 
 static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
 static void _WriteBlobData(ArchiveHandle *AH, const void *data, size_t dLen);
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index dead8fc..fd74835 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -29,18 +29,18 @@
  */
 #include "postgres_fe.h"
 
-#include "pg_backup_archiver.h"
-#include "pg_backup_tar.h"
-#include "pg_backup_utils.h"
-#include "pgtar.h"
-#include "common/file_utils.h"
-#include "fe_utils/string_utils.h"
-
 #include <sys/stat.h>
 #include <ctype.h>
 #include <limits.h>
 #include <unistd.h>
 
+#include "common/file_utils.h"
+#include "fe_utils/string_utils.h"
+#include "pg_backup_archiver.h"
+#include "pg_backup_tar.h"
+#include "pg_backup_utils.h"
+#include "pgtar.h"
+
 static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te);
 static void _StartData(ArchiveHandle *AH, TocEntry *te);
 static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen);
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2a087d7..bf69adc 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -38,8 +38,6 @@
 #include <termios.h>
 #endif
 
-#include "getopt_long.h"
-
 #include "access/attnum.h"
 #include "access/sysattr.h"
 #include "access/transam.h"
@@ -54,17 +52,16 @@
 #include "catalog/pg_proc_d.h"
 #include "catalog/pg_trigger_d.h"
 #include "catalog/pg_type_d.h"
-#include "libpq/libpq-fs.h"
-#include "storage/block.h"
-
 #include "dumputils.h"
+#include "fe_utils/connect.h"
+#include "fe_utils/string_utils.h"
+#include "getopt_long.h"
+#include "libpq/libpq-fs.h"
 #include "parallel.h"
 #include "pg_backup_db.h"
 #include "pg_backup_utils.h"
 #include "pg_dump.h"
-#include "fe_utils/connect.h"
-#include "fe_utils/string_utils.h"
-
+#include "storage/block.h"
 
 typedef struct
 {
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index 31fc06a..ad01316 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -15,12 +15,11 @@
  */
 #include "postgres_fe.h"
 
+#include "catalog/pg_class_d.h"
 #include "pg_backup_archiver.h"
 #include "pg_backup_utils.h"
 #include "pg_dump.h"
 
-#include "catalog/pg_class_d.h"
-
 /*
  * Sort priority for database object types.
  * Objects are sorted by type, and within a type by name.
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 0981efc..1442ea9 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -18,14 +18,13 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "getopt_long.h"
-
-#include "dumputils.h"
-#include "pg_backup.h"
 #include "common/file_utils.h"
 #include "common/logging.h"
+#include "dumputils.h"
 #include "fe_utils/connect.h"
 #include "fe_utils/string_utils.h"
+#include "getopt_long.h"
+#include "pg_backup.h"
 
 /* version string we expect back from pg_dump */
 #define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 40a6b37..d1a36b1 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -45,13 +45,11 @@
 #include <termios.h>
 #endif
 
-#include "getopt_long.h"
-
 #include "dumputils.h"
+#include "getopt_long.h"
 #include "parallel.h"
 #include "pg_backup_utils.h"
 
-
 static void usage(const char *progname);
 
 int
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index f85ea2d..c83f865 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -44,9 +44,9 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "access/transam.h"
 #include "access/heaptoast.h"
 #include "access/multixact.h"
+#include "access/transam.h"
 #include "access/xlog.h"
 #include "access/xlog_internal.h"
 #include "common/controldata_utils.h"
@@ -55,10 +55,9 @@
 #include "common/logging.h"
 #include "common/restricted_token.h"
 #include "common/string.h"
-#include "storage/large_object.h"
-#include "pg_getopt.h"
 #include "getopt_long.h"
-
+#include "pg_getopt.h"
+#include "storage/large_object.h"
 
 static ControlFileData ControlFile; /* pg_control values */
 static XLogSegNo newXlogSegNo;	/* new XLOG segment # */
diff --git a/src/bin/pg_rewind/copy_fetch.c b/src/bin/pg_rewind/copy_fetch.c
index d74001e..2222a4e 100644
--- a/src/bin/pg_rewind/copy_fetch.c
+++ b/src/bin/pg_rewind/copy_fetch.c
@@ -8,6 +8,7 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <sys/stat.h>
 #include <dirent.h>
@@ -18,7 +19,6 @@
 #include "fetch.h"
 #include "file_ops.h"
 #include "filemap.h"
-#include "pg_rewind.h"
 
 static void recurse_dir(const char *datadir, const char *path,
 						process_file_callback_t callback);
diff --git a/src/bin/pg_rewind/datapagemap.c b/src/bin/pg_rewind/datapagemap.c
index 93165f6..c903dbb 100644
--- a/src/bin/pg_rewind/datapagemap.c
+++ b/src/bin/pg_rewind/datapagemap.c
@@ -12,9 +12,8 @@
 
 #include "postgres_fe.h"
 
-#include "datapagemap.h"
-
 #include "common/logging.h"
+#include "datapagemap.h"
 
 struct datapagemap_iterator
 {
diff --git a/src/bin/pg_rewind/fetch.c b/src/bin/pg_rewind/fetch.c
index 03a5fd6..775d162 100644
--- a/src/bin/pg_rewind/fetch.c
+++ b/src/bin/pg_rewind/fetch.c
@@ -15,11 +15,11 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <sys/stat.h>
 #include <unistd.h>
 
-#include "pg_rewind.h"
 #include "fetch.h"
 #include "file_ops.h"
 #include "filemap.h"
diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c
index f9e41b1..661e0a2 100644
--- a/src/bin/pg_rewind/file_ops.c
+++ b/src/bin/pg_rewind/file_ops.c
@@ -13,6 +13,7 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -21,7 +22,6 @@
 #include "common/file_perm.h"
 #include "file_ops.h"
 #include "filemap.h"
-#include "pg_rewind.h"
 
 /*
  * Currently open target file.
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index 601f7e9..a20eebf 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -9,16 +9,15 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "catalog/pg_tablespace_d.h"
+#include "common/string.h"
 #include "datapagemap.h"
 #include "filemap.h"
-#include "pg_rewind.h"
-
-#include "common/string.h"
-#include "catalog/pg_tablespace_d.h"
 #include "storage/fd.h"
 
 filemap_t  *filemap = NULL;
diff --git a/src/bin/pg_rewind/libpq_fetch.c b/src/bin/pg_rewind/libpq_fetch.c
index f4ebf7d..1482b07 100644
--- a/src/bin/pg_rewind/libpq_fetch.c
+++ b/src/bin/pg_rewind/libpq_fetch.c
@@ -8,20 +8,19 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <sys/stat.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "pg_rewind.h"
+#include "catalog/pg_type_d.h"
 #include "datapagemap.h"
+#include "fe_utils/connect.h"
 #include "fetch.h"
 #include "file_ops.h"
 #include "filemap.h"
-
-#include "catalog/pg_type_d.h"
-#include "fe_utils/connect.h"
 #include "port/pg_bswap.h"
 
 PGconn *conn = NULL;
diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c
index 264a8f4..c5f85e3 100644
--- a/src/bin/pg_rewind/parsexlog.c
+++ b/src/bin/pg_rewind/parsexlog.c
@@ -10,19 +10,17 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <unistd.h>
 
-#include "pg_rewind.h"
-#include "filemap.h"
-
 #include "access/rmgr.h"
 #include "access/xlog_internal.h"
 #include "access/xlogreader.h"
 #include "catalog/pg_control.h"
 #include "catalog/storage_xlog.h"
 #include "commands/dbcommands_xlog.h"
-
+#include "filemap.h"
 
 /*
  * RmgrNames is an array of resource manager names, to make error messages
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 875a43b..9dd0ae6 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -8,17 +8,13 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
+#include "pg_rewind.h"
 
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <time.h>
 #include <unistd.h>
 
-#include "pg_rewind.h"
-#include "fetch.h"
-#include "file_ops.h"
-#include "filemap.h"
-
 #include "access/timeline.h"
 #include "access/xlog_internal.h"
 #include "catalog/catversion.h"
@@ -28,6 +24,9 @@
 #include "common/file_utils.h"
 #include "common/restricted_token.h"
 #include "fe_utils/recovery_gen.h"
+#include "fetch.h"
+#include "file_ops.h"
+#include "filemap.h"
 #include "getopt_long.h"
 #include "storage/bufpage.h"
 
diff --git a/src/bin/pg_rewind/timeline.c b/src/bin/pg_rewind/timeline.c
index 987452c..3736523 100644
--- a/src/bin/pg_rewind/timeline.c
+++ b/src/bin/pg_rewind/timeline.c
@@ -8,7 +8,6 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
-
 #include "pg_rewind.h"
 
 #include "access/timeline.h"
diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c
index 225557e..2ca1608 100644
--- a/src/bin/pg_test_fsync/pg_test_fsync.c
+++ b/src/bin/pg_test_fsync/pg_test_fsync.c
@@ -12,10 +12,9 @@
 #include <unistd.h>
 #include <signal.h>
 
-#include "getopt_long.h"
 #include "access/xlogdefs.h"
 #include "common/logging.h"
-
+#include "getopt_long.h"
 
 /*
  * put the temp files in the local directory
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 87b9d32..6d227f0 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -8,12 +8,11 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_upgrade.h"
 
 #include "catalog/pg_authid_d.h"
 #include "fe_utils/string_utils.h"
 #include "mb/pg_wchar.h"
-#include "pg_upgrade.h"
-
 
 static void check_new_cluster_is_empty(void);
 static void check_databases_are_compatible(void);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 3823641..6bae08a 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -8,7 +8,6 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 #include <ctype.h>
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index c1429fe..6b642a6 100644
--- a/src/bin/pg_upgrade/dump.c
+++ b/src/bin/pg_upgrade/dump.c
@@ -8,12 +8,10 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 #include "fe_utils/string_utils.h"
 
-
 void
 generate_old_dump(void)
 {
diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c
index dba02c4..14c8dc2 100644
--- a/src/bin/pg_upgrade/exec.c
+++ b/src/bin/pg_upgrade/exec.c
@@ -8,11 +8,10 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_upgrade.h"
 
 #include <fcntl.h>
 
-#include "pg_upgrade.h"
-
 static void check_data_dir(ClusterInfo *cluster);
 static void check_bin_dir(ClusterInfo *cluster);
 static void get_bin_version(ClusterInfo *cluster);
diff --git a/src/bin/pg_upgrade/file.c b/src/bin/pg_upgrade/file.c
index c7fed24..3172d25 100644
--- a/src/bin/pg_upgrade/file.c
+++ b/src/bin/pg_upgrade/file.c
@@ -8,13 +8,7 @@
  */
 
 #include "postgres_fe.h"
-
-#include "access/visibilitymap.h"
-#include "common/file_perm.h"
 #include "pg_upgrade.h"
-#include "storage/bufpage.h"
-#include "storage/checksum.h"
-#include "storage/checksum_impl.h"
 
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -26,6 +20,11 @@
 #include <linux/fs.h>
 #endif
 
+#include "access/visibilitymap.h"
+#include "common/file_perm.h"
+#include "storage/bufpage.h"
+#include "storage/checksum.h"
+#include "storage/checksum_impl.h"
 
 #ifdef WIN32
 static int	win32_pghardlink(const char *src, const char *dst);
diff --git a/src/bin/pg_upgrade/function.c b/src/bin/pg_upgrade/function.c
index 3cbaab6..3138bfe 100644
--- a/src/bin/pg_upgrade/function.c
+++ b/src/bin/pg_upgrade/function.c
@@ -8,13 +8,11 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 #include "access/transam.h"
 #include "catalog/pg_language_d.h"
 
-
 /*
  * qsort comparator for pointers to library names
  *
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index 5c7b433..9224a11 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -8,13 +8,11 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 #include "access/transam.h"
 #include "catalog/pg_class_d.h"
 
-
 static void create_rel_filename_map(const char *old_data, const char *new_data,
 									const DbInfo *old_db, const DbInfo *new_db,
 									const RelInfo *old_rel, const RelInfo *new_rel,
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index da9e1da..f34290f 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -8,19 +8,17 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_upgrade.h"
 
 #include <time.h>
 #ifdef WIN32
 #include <io.h>
 #endif
 
-#include "getopt_long.h"
 #include "common/string.h"
+#include "getopt_long.h"
 #include "utils/pidfile.h"
 
-#include "pg_upgrade.h"
-
-
 static void usage(void);
 static void check_required_directory(char **dirpath,
 									 const char *envVarName, bool useCwd,
diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c
index 80ab1b8..682a9bb 100644
--- a/src/bin/pg_upgrade/parallel.c
+++ b/src/bin/pg_upgrade/parallel.c
@@ -8,15 +8,13 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_upgrade.h"
 
 #include <sys/wait.h>
 #ifdef WIN32
 #include <io.h>
 #endif
 
-#include "pg_upgrade.h"
-
-
 static int	parallel_jobs;
 
 #ifdef WIN32
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index 5b82e0c..5516e9e 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -36,18 +36,18 @@
 
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
+
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+
 #include "catalog/pg_class_d.h"
 #include "common/file_perm.h"
 #include "common/logging.h"
 #include "common/restricted_token.h"
 #include "fe_utils/string_utils.h"
 
-#ifdef HAVE_LANGINFO_H
-#include <langinfo.h>
-#endif
-
 static void prepare_new_cluster(void);
 static void prepare_new_globals(void);
 static void create_new_objects(void);
diff --git a/src/bin/pg_upgrade/relfilenode.c b/src/bin/pg_upgrade/relfilenode.c
index 0c78073..713149c 100644
--- a/src/bin/pg_upgrade/relfilenode.c
+++ b/src/bin/pg_upgrade/relfilenode.c
@@ -8,13 +8,12 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 #include <sys/stat.h>
-#include "catalog/pg_class_d.h"
-#include "access/transam.h"
 
+#include "access/transam.h"
+#include "catalog/pg_class_d.h"
 
 static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace);
 static void transfer_relfile(FileNameMap *map, const char *suffix, bool vm_must_add_frozenbit);
diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c
index 6ad4b14..8975e05 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -8,11 +8,10 @@
  */
 
 #include "postgres_fe.h"
+#include "pg_upgrade.h"
 
 #include "fe_utils/connect.h"
 #include "fe_utils/string_utils.h"
-#include "pg_upgrade.h"
-
 
 static PGconn *get_db_conn(ClusterInfo *cluster, const char *db_name);
 
diff --git a/src/bin/pg_upgrade/tablespace.c b/src/bin/pg_upgrade/tablespace.c
index dfe5bfd..c28807a 100644
--- a/src/bin/pg_upgrade/tablespace.c
+++ b/src/bin/pg_upgrade/tablespace.c
@@ -8,7 +8,6 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 static void get_tablespace_paths(void);
diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index d867995..40ca286 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -8,12 +8,11 @@
  */
 
 #include "postgres_fe.h"
-
-#include "common/username.h"
 #include "pg_upgrade.h"
 
 #include <signal.h>
 
+#include "common/username.h"
 
 LogOpts		log_opts;
 
diff --git a/src/bin/pg_upgrade/version.c b/src/bin/pg_upgrade/version.c
index b64171d..67930f1 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -8,14 +8,11 @@
  */
 
 #include "postgres_fe.h"
-
 #include "pg_upgrade.h"
 
 #include "catalog/pg_class_d.h"
 #include "fe_utils/string_utils.h"
 
-
-
 /*
  * new_9_0_populate_pg_largeobject_metadata()
  *	new >= 9.0, old <= 8.4
diff --git a/src/bin/pg_waldump/compat.c b/src/bin/pg_waldump/compat.c
index 0e0dca7..7b389a2 100644
--- a/src/bin/pg_waldump/compat.c
+++ b/src/bin/pg_waldump/compat.c
@@ -20,8 +20,8 @@
 
 #include <time.h>
 
-#include "utils/datetime.h"
 #include "lib/stringinfo.h"
+#include "utils/datetime.h"
 
 /* copied from timestamp.c */
 pg_time_t
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index b79208c..8e54d7f 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -16,16 +16,15 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "access/xlog_internal.h"
 #include "access/xlogreader.h"
 #include "access/xlogrecord.h"
-#include "access/xlog_internal.h"
 #include "access/transam.h"
 #include "common/fe_memutils.h"
 #include "common/logging.h"
 #include "getopt_long.h"
 #include "rmgrdesc.h"
 
-
 static const char *progname;
 
 static int	WalSegSz;
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index e72ad00..3d5df09 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -32,12 +32,7 @@
 #endif
 
 #include "postgres_fe.h"
-#include "common/int.h"
-#include "common/logging.h"
-#include "fe_utils/conditional.h"
-#include "getopt_long.h"
-#include "libpq-fe.h"
-#include "portability/instr_time.h"
+#include "pgbench.h"
 
 #include <ctype.h>
 #include <float.h>
@@ -63,11 +58,17 @@
 #endif
 #endif
 
+#include "common/int.h"
+#include "common/logging.h"
+#include "fe_utils/conditional.h"
+#include "getopt_long.h"
+#include "libpq-fe.h"
+#include "portability/instr_time.h"
+
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
-#include "pgbench.h"
 
 #define ERRCODE_UNDEFINED_TABLE  "42P01"
 
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 4b26793..90f6380 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -18,18 +18,16 @@
 #include <win32.h>
 #endif
 
-#include "common/logging.h"
-#include "fe_utils/mbprint.h"
-#include "fe_utils/string_utils.h"
-#include "portability/instr_time.h"
-
 #include "command.h"
 #include "common.h"
+#include "common/logging.h"
 #include "copy.h"
 #include "crosstabview.h"
+#include "fe_utils/mbprint.h"
+#include "fe_utils/string_utils.h"
+#include "portability/instr_time.h"
 #include "settings.h"
 
-
 static bool DescribeQuery(const char *query, double *elapsed_msec);
 static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec);
 static bool command_no_begin(const char *query);
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index f9e53d6..239f00a 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -16,16 +16,14 @@
 #include <io.h>					/* I think */
 #endif
 
+#include "common.h"
+#include "common/logging.h"
 #include "libpq-fe.h"
 #include "pqexpbuffer.h"
-
-#include "settings.h"
-#include "common.h"
 #include "prompt.h"
+#include "settings.h"
 #include "stringutils.h"
 
-#include "common/logging.h"
-
 /*
  * parse_slash_copy
  * -- parses \copy command line
diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c
index 83789cb..701ef34 100644
--- a/src/bin/psql/crosstabview.c
+++ b/src/bin/psql/crosstabview.c
@@ -8,13 +8,12 @@
 #include "postgres_fe.h"
 
 #include "common.h"
+#include "common/logging.h"
 #include "crosstabview.h"
 #include "pqexpbuffer.h"
 #include "psqlscanslash.h"
 #include "settings.h"
 
-#include "common/logging.h"
-
 /*
  * Value/position from the resultset that goes into the horizontal or vertical
  * crosstabview header.
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index d7c0fc0..b3b9313 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -18,18 +18,15 @@
 #include "catalog/pg_cast_d.h"
 #include "catalog/pg_class_d.h"
 #include "catalog/pg_default_acl_d.h"
-
+#include "common.h"
 #include "common/logging.h"
+#include "describe.h"
 #include "fe_utils/mbprint.h"
 #include "fe_utils/print.h"
 #include "fe_utils/string_utils.h"
-
-#include "common.h"
-#include "describe.h"
 #include "settings.h"
 #include "variables.h"
 
-
 static bool describeOneTableDetails(const char *schemaname,
 									const char *relationname,
 									const char *oid,
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 59ea8cc..0f58eeb 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -21,10 +21,9 @@
 #include <termios.h>
 #endif
 
+#include "common.h"
 #include "common/logging.h"
 #include "common/username.h"
-
-#include "common.h"
 #include "help.h"
 #include "input.h"
 #include "settings.h"
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 5a18ac9..5798e6e 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -13,12 +13,11 @@
 #include <fcntl.h>
 #include <limits.h>
 
+#include "common.h"
+#include "common/logging.h"
 #include "input.h"
 #include "settings.h"
 #include "tab-complete.h"
-#include "common.h"
-
-#include "common/logging.h"
 
 #ifndef WIN32
 #define PSQLHISTORY ".psql_history"
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c
index 2713f15..042403e 100644
--- a/src/bin/psql/large_obj.c
+++ b/src/bin/psql/large_obj.c
@@ -6,12 +6,11 @@
  * src/bin/psql/large_obj.c
  */
 #include "postgres_fe.h"
-#include "large_obj.h"
 
-#include "settings.h"
 #include "common.h"
-
 #include "common/logging.h"
+#include "large_obj.h"
+#include "settings.h"
 
 static void print_lo_result(const char *fmt,...) pg_attribute_printf(1, 2);
 
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index e386d98..b3a8407 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -6,18 +6,16 @@
  * src/bin/psql/mainloop.c
  */
 #include "postgres_fe.h"
-#include "mainloop.h"
 
 #include "command.h"
 #include "common.h"
+#include "common/logging.h"
 #include "input.h"
+#include "mainloop.h"
+#include "mb/pg_wchar.h"
 #include "prompt.h"
 #include "settings.h"
 
-#include "common/logging.h"
-#include "mb/pg_wchar.h"
-
-
 /* callback functions for our flex lexer */
 const PsqlScanCallbacks psqlscan_callbacks = {
 	psql_get_variable,
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 0fcb8c7..195192a 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -18,12 +18,11 @@
 #endif
 
 #include "common.h"
+#include "common/string.h"
 #include "input.h"
 #include "prompt.h"
 #include "settings.h"
 
-#include "common/string.h"
-
 /*--------------------------
  * get_prompt
  *
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index e4c0a7e..0d941ef 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -14,21 +14,17 @@
 #include <win32.h>
 #endif							/* WIN32 */
 
-#include "getopt_long.h"
-
-#include "common/logging.h"
-#include "fe_utils/print.h"
-
 #include "command.h"
 #include "common.h"
+#include "common/logging.h"
 #include "describe.h"
+#include "fe_utils/print.h"
+#include "getopt_long.h"
 #include "help.h"
 #include "input.h"
 #include "mainloop.h"
 #include "settings.h"
 
-
-
 /*
  * Global psql options
  */
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c
index 1d2a31c..3f7b641 100644
--- a/src/bin/psql/variables.c
+++ b/src/bin/psql/variables.c
@@ -8,10 +8,8 @@
 #include "postgres_fe.h"
 
 #include "common.h"
-#include "variables.h"
-
 #include "common/logging.h"
-
+#include "variables.h"
 
 /*
  * Check whether a variable's name is allowed.
diff --git a/src/common/f2s.c b/src/common/f2s.c
index e332557..ea5ca8d 100644
--- a/src/common/f2s.c
+++ b/src/common/f2s.c
@@ -39,9 +39,8 @@
 #endif
 
 #include "common/shortest_dec.h"
-
-#include "ryu_common.h"
 #include "digit_table.h"
+#include "ryu_common.h"
 
 #define FLOAT_MANTISSA_BITS 23
 #define FLOAT_EXPONENT_BITS 8
diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index e41f42e..1f8bde8 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -30,11 +30,9 @@
 #include <termios.h>
 #endif
 
-#include "fe_utils/print.h"
-
 #include "catalog/pg_type_d.h"
 #include "fe_utils/mbprint.h"
-
+#include "fe_utils/print.h"
 
 /*
  * If the calling program doesn't have any mechanism for setting
diff --git a/src/fe_utils/recovery_gen.c b/src/fe_utils/recovery_gen.c
index 6641f95..aec01c0 100644
--- a/src/fe_utils/recovery_gen.c
+++ b/src/fe_utils/recovery_gen.c
@@ -10,9 +10,8 @@
 #include "postgres_fe.h"
 
 #include "common/logging.h"
-#include "fe_utils/string_utils.h"
 #include "fe_utils/recovery_gen.h"
-
+#include "fe_utils/string_utils.h"
 
 static char *escape_quotes(const char *src);
 
diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c
index 8c3a603..b07f142 100644
--- a/src/fe_utils/string_utils.c
+++ b/src/fe_utils/string_utils.c
@@ -17,10 +17,8 @@
 
 #include <ctype.h>
 
-#include "fe_utils/string_utils.h"
-
 #include "common/keywords.h"
-
+#include "fe_utils/string_utils.h"
 
 static PQExpBuffer defaultGetLocalPQExpBuffer(void);
 
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index 6ef1fad..bbaf450 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -7,14 +7,14 @@
 #include <ctype.h>
 #include <limits.h>
 
-#include <ecpgtype.h>
-#include <ecpg_informix.h>
-#include <pgtypes_error.h>
-#include <pgtypes_date.h>
-#include <pgtypes_numeric.h>
-#include <sqltypes.h>
-#include <sqlca.h>
-#include <ecpgerrno.h>
+#include "ecpg_informix.h"
+#include "ecpgerrno.h"
+#include "ecpgtype.h"
+#include "pgtypes_date.h"
+#include "pgtypes_error.h"
+#include "pgtypes_numeric.h"
+#include "sqlca.h"
+#include "sqltypes.h"
 
 /* this is also defined in ecpglib/misc.c, by defining it twice we don't have to export the symbol */
 
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index b4f6089..1cb5211 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -4,10 +4,10 @@
 #include "postgres_fe.h"
 
 #include "ecpg-pthread-win32.h"
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpgtype.h"
 #include "sqlca.h"
 
 #ifdef ENABLE_THREAD_SAFETY
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 81f94cc..7d2a78a 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -5,15 +5,15 @@
 
 #include <math.h>
 
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
-#include "sqlca.h"
-#include "pgtypes_numeric.h"
+#include "ecpgtype.h"
 #include "pgtypes_date.h"
-#include "pgtypes_timestamp.h"
 #include "pgtypes_interval.h"
+#include "pgtypes_numeric.h"
+#include "pgtypes_timestamp.h"
+#include "sqlca.h"
 
 /* returns true if character c is a delimiter for the given array type */
 static bool
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index ef500a9..ead8778 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -7,12 +7,11 @@
 #include "postgres_fe.h"
 
 #include "catalog/pg_type_d.h"
-
 #include "ecpg-pthread-win32.h"
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpgtype.h"
 #include "sqlca.h"
 #include "sqlda.h"
 #include "sql3types.h"
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c
index 9c56991..a4e3c0d 100644
--- a/src/interfaces/ecpg/ecpglib/error.c
+++ b/src/interfaces/ecpg/ecpglib/error.c
@@ -4,9 +4,9 @@
 #include "postgres_fe.h"
 
 #include "ecpgerrno.h"
-#include "ecpgtype.h"
 #include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpgtype.h"
 #include "sqlca.h"
 
 void
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 7c9cb76..23cc869 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -19,19 +19,18 @@
 #include <math.h>
 
 #include "catalog/pg_type_d.h"
-
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
-#include "sqlca.h"
-#include "sqlda-native.h"
-#include "sqlda-compat.h"
-#include "sql3types.h"
-#include "pgtypes_numeric.h"
+#include "ecpgtype.h"
 #include "pgtypes_date.h"
-#include "pgtypes_timestamp.h"
 #include "pgtypes_interval.h"
+#include "pgtypes_numeric.h"
+#include "pgtypes_timestamp.h"
+#include "sql3types.h"
+#include "sqlca.h"
+#include "sqlda-compat.h"
+#include "sqlda-native.h"
 
 /*
  *	This function returns a newly malloced string that has ' and \
diff --git a/src/interfaces/ecpg/ecpglib/memory.c b/src/interfaces/ecpg/ecpglib/memory.c
index 52ca1c5..bd81251 100644
--- a/src/interfaces/ecpg/ecpglib/memory.c
+++ b/src/interfaces/ecpg/ecpglib/memory.c
@@ -4,10 +4,10 @@
 #include "postgres_fe.h"
 
 #include "ecpg-pthread-win32.h"
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpgtype.h"
 
 void
 ecpg_free(void *ptr)
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index 2eec54a..4fbb896 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -6,16 +6,16 @@
 #include <limits.h>
 #include <unistd.h>
 #include "ecpg-pthread-win32.h"
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
-#include "sqlca.h"
-#include "pgtypes_numeric.h"
+#include "ecpgtype.h"
 #include "pgtypes_date.h"
-#include "pgtypes_timestamp.h"
 #include "pgtypes_interval.h"
+#include "pgtypes_numeric.h"
+#include "pgtypes_timestamp.h"
 #include "pg_config_paths.h"
+#include "sqlca.h"
 
 #ifdef HAVE_LONG_LONG_INT
 #ifndef LONG_LONG_MIN
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index 6e7adb9..b9653c0 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -5,10 +5,10 @@
 
 #include <ctype.h>
 
-#include "ecpgtype.h"
-#include "ecpglib.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpgtype.h"
 #include "sqlca.h"
 
 #define STMTID_SIZE 32
diff --git a/src/interfaces/ecpg/ecpglib/sqlda.c b/src/interfaces/ecpg/ecpglib/sqlda.c
index 3fb0d82..081e326 100644
--- a/src/interfaces/ecpg/ecpglib/sqlda.c
+++ b/src/interfaces/ecpg/ecpglib/sqlda.c
@@ -10,16 +10,15 @@
 #include "postgres_fe.h"
 
 #include "catalog/pg_type_d.h"
-
-#include "ecpg-pthread-win32.h"
 #include "decimal.h"
-#include "ecpgtype.h"
-#include "ecpglib.h"
+#include "ecpg-pthread-win32.h"
 #include "ecpgerrno.h"
+#include "ecpglib.h"
 #include "ecpglib_extern.h"
+#include "ecpgtype.h"
 #include "sqlca.h"
-#include "sqlda-native.h"
 #include "sqlda-compat.h"
+#include "sqlda-native.h"
 
 /*
  * Compute the next variable's offset with
diff --git a/src/interfaces/ecpg/ecpglib/typename.c b/src/interfaces/ecpg/ecpglib/typename.c
index 9251450..1d482c4 100644
--- a/src/interfaces/ecpg/ecpglib/typename.c
+++ b/src/interfaces/ecpg/ecpglib/typename.c
@@ -4,12 +4,11 @@
 #include "postgres_fe.h"
 
 #include "catalog/pg_type_d.h"
-
-#include "ecpgtype.h"
 #include "ecpglib.h"
 #include "ecpglib_extern.h"
-#include "sqltypes.h"
+#include "ecpgtype.h"
 #include "sql3types.h"
+#include "sqltypes.h"
 
 /*
  * This function is used to generate the correct type names.
diff --git a/src/interfaces/ecpg/pgtypeslib/common.c b/src/interfaces/ecpg/pgtypeslib/common.c
index abcf7f5..8972229 100644
--- a/src/interfaces/ecpg/pgtypeslib/common.c
+++ b/src/interfaces/ecpg/pgtypeslib/common.c
@@ -2,8 +2,8 @@
 
 #include "postgres_fe.h"
 
-#include "pgtypeslib_extern.h"
 #include "pgtypes.h"
+#include "pgtypeslib_extern.h"
 
 /* Return value is zero-filled. */
 char *
diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c
index 9ee460b..71dc1a5 100644
--- a/src/interfaces/ecpg/pgtypeslib/datetime.c
+++ b/src/interfaces/ecpg/pgtypeslib/datetime.c
@@ -6,10 +6,10 @@
 #include <ctype.h>
 #include <limits.h>
 
-#include "pgtypeslib_extern.h"
 #include "dt.h"
-#include "pgtypes_error.h"
 #include "pgtypes_date.h"
+#include "pgtypes_error.h"
+#include "pgtypeslib_extern.h"
 
 date *
 PGTYPESdate_new(void)
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 29c1117..c22f657 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -7,9 +7,9 @@
 #include <math.h>
 
 #include "common/string.h"
-#include "pgtypeslib_extern.h"
 #include "dt.h"
 #include "pgtypes_timestamp.h"
+#include "pgtypeslib_extern.h"
 
 const int	day_tab[2][13] = {
 	{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0},
diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c
index 3ff8a10..5b3c9a7 100644
--- a/src/interfaces/ecpg/pgtypeslib/interval.c
+++ b/src/interfaces/ecpg/pgtypeslib/interval.c
@@ -1,6 +1,7 @@
 /* src/interfaces/ecpg/pgtypeslib/interval.c */
 
 #include "postgres_fe.h"
+
 #include <time.h>
 #include <math.h>
 #include <limits.h>
@@ -10,11 +11,10 @@
 #endif
 
 #include "common/string.h"
-
-#include "pgtypeslib_extern.h"
 #include "dt.h"
 #include "pgtypes_error.h"
 #include "pgtypes_interval.h"
+#include "pgtypeslib_extern.h"
 
 /* copy&pasted from .../src/backend/utils/adt/datetime.c
  * and changesd struct pg_tm to struct tm
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c
index 22088ba..9d3da4c 100644
--- a/src/interfaces/ecpg/pgtypeslib/numeric.c
+++ b/src/interfaces/ecpg/pgtypeslib/numeric.c
@@ -5,8 +5,9 @@
 #include <float.h>
 #include <limits.h>
 
-#include "pgtypeslib_extern.h"
 #include "pgtypes_error.h"
+#include "pgtypes_numeric.h"
+#include "pgtypeslib_extern.h"
 
 #define Max(x, y)				((x) > (y) ? (x) : (y))
 #define Min(x, y)				((x) < (y) ? (x) : (y))
@@ -20,7 +21,6 @@
 						  free(buf); \
 		  } while (0)
 
-#include "pgtypes_numeric.h"
 
 #if 0
 /* ----------
diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c
index 2be151f..7816e6f 100644
--- a/src/interfaces/ecpg/pgtypeslib/timestamp.c
+++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c
@@ -11,11 +11,10 @@
 #error -ffast-math is known to break this code
 #endif
 
-#include "pgtypeslib_extern.h"
 #include "dt.h"
-#include "pgtypes_timestamp.h"
 #include "pgtypes_date.h"
-
+#include "pgtypes_timestamp.h"
+#include "pgtypeslib_extern.h"
 
 static int64
 time2t(const int hour, const int min, const int sec, const fsec_t fsec)
diff --git a/src/interfaces/ecpg/preproc/c_keywords.c b/src/interfaces/ecpg/preproc/c_keywords.c
index 80aa7d5..e51c036 100644
--- a/src/interfaces/ecpg/preproc/c_keywords.c
+++ b/src/interfaces/ecpg/preproc/c_keywords.c
@@ -9,11 +9,10 @@
  */
 #include "postgres_fe.h"
 
-#include "preproc_extern.h"
-#include "preproc.h"
-
 /* ScanKeywordList lookup data for C keywords */
 #include "c_kwlist_d.h"
+#include "preproc_extern.h"
+#include "preproc.h"
 
 /* Token codes for C keywords */
 #define PG_KEYWORD(kwname, value) value,
diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c
index 4839c37..a2db06f 100644
--- a/src/interfaces/ecpg/preproc/ecpg_keywords.c
+++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c
@@ -13,11 +13,10 @@
 
 #include <ctype.h>
 
-#include "preproc_extern.h"
-#include "preproc.h"
-
 /* ScanKeywordList lookup data for ECPG keywords */
 #include "ecpg_kwlist_d.h"
+#include "preproc_extern.h"
+#include "preproc.h"
 
 /* Token codes for ECPG keywords */
 #define PG_KEYWORD(kwname, value) value,
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index a690f3b..2364dda 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -40,9 +40,8 @@
 
 #include "common/md5.h"
 #include "common/scram-common.h"
-#include "libpq-fe.h"
 #include "fe-auth.h"
-
+#include "libpq-fe.h"
 
 #ifdef ENABLE_GSS
 /*
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index f91f0f2..959082b 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -21,11 +21,6 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "libpq-fe.h"
-#include "libpq-int.h"
-#include "fe-auth.h"
-#include "pg_config_paths.h"
-
 #ifdef WIN32
 #include "win32.h"
 #ifdef _WIN32_IE
@@ -74,10 +69,13 @@ static int	ldapServiceLookup(const char *purl, PQconninfoOption *options,
 #include "common/link-canary.h"
 #include "common/scram-common.h"
 #include "common/string.h"
+#include "fe-auth.h"
+#include "libpq-fe.h"
+#include "libpq-int.h"
 #include "mb/pg_wchar.h"
+#include "pg_config_paths.h"
 #include "port/pg_bswap.h"
 
-
 #ifndef WIN32
 #define PGPASSFILE ".pgpass"
 #else
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index b3c59a0..051f548 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -18,17 +18,16 @@
 #include <fcntl.h>
 #include <limits.h>
 
-#include "libpq-fe.h"
-#include "libpq-int.h"
-
-#include "mb/pg_wchar.h"
-
 #ifdef WIN32
 #include "win32.h"
 #else
 #include <unistd.h>
 #endif
 
+#include "libpq-fe.h"
+#include "libpq-int.h"
+#include "mb/pg_wchar.h"
+
 /* keep this in same order as ExecStatusType in libpq-fe.h */
 char	   *const pgresStatus[] = {
 	"PGRES_EMPTY_QUERY",
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 18fec4a..a7c08c5 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -50,9 +50,8 @@
 #include "libpq-fe.h"
 #include "libpq-int.h"
 #include "mb/pg_wchar.h"
-#include "port/pg_bswap.h"
 #include "pg_config_paths.h"
-
+#include "port/pg_bswap.h"
 
 static int	pqPutMsgBytes(const void *buf, size_t len, PGconn *conn);
 static int	pqSendSome(PGconn *conn, int len);
diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c
index 0e36974..e71e25a 100644
--- a/src/interfaces/libpq/fe-protocol2.c
+++ b/src/interfaces/libpq/fe-protocol2.c
@@ -17,11 +17,6 @@
 #include <ctype.h>
 #include <fcntl.h>
 
-#include "libpq-fe.h"
-#include "libpq-int.h"
-#include "port/pg_bswap.h"
-
-
 #ifdef WIN32
 #include "win32.h"
 #else
@@ -31,6 +26,9 @@
 #endif
 #endif
 
+#include "libpq-fe.h"
+#include "libpq-int.h"
+#include "port/pg_bswap.h"
 
 static int	getRowDescriptions(PGconn *conn);
 static int	getAnotherTuple(PGconn *conn, bool binary);
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index b04f7ec..c97841e 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -17,12 +17,6 @@
 #include <ctype.h>
 #include <fcntl.h>
 
-#include "libpq-fe.h"
-#include "libpq-int.h"
-
-#include "mb/pg_wchar.h"
-#include "port/pg_bswap.h"
-
 #ifdef WIN32
 #include "win32.h"
 #else
@@ -32,6 +26,10 @@
 #endif
 #endif
 
+#include "libpq-fe.h"
+#include "libpq-int.h"
+#include "mb/pg_wchar.h"
+#include "port/pg_bswap.h"
 
 /*
  * This macro lists the backend message types that could be "long" (more
diff --git a/src/interfaces/libpq/fe-secure-gssapi.c b/src/interfaces/libpq/fe-secure-gssapi.c
index 095750d..a1c1d12 100644
--- a/src/interfaces/libpq/fe-secure-gssapi.c
+++ b/src/interfaces/libpq/fe-secure-gssapi.c
@@ -13,9 +13,9 @@
 
 #include "postgres_fe.h"
 
+#include "fe-gssapi-common.h"
 #include "libpq-fe.h"
 #include "libpq-int.h"
-#include "fe-gssapi-common.h"
 #include "port/pg_bswap.h"
 
 /*
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index b8191b4..e55b375 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -28,10 +28,6 @@
 #include <fcntl.h>
 #include <ctype.h>
 
-#include "libpq-fe.h"
-#include "fe-auth.h"
-#include "libpq-int.h"
-
 #ifdef WIN32
 #include "win32.h"
 #else
@@ -55,6 +51,10 @@
 #endif
 #endif
 
+#include "fe-auth.h"
+#include "libpq-fe.h"
+#include "libpq-int.h"
+
 /*
  * Macros to handle disabling and then restoring the state of SIGPIPE handling.
  * On Windows, these are all no-ops since there's no SIGPIPEs.
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index 0c24ba6..3fb8fc7 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -24,6 +24,7 @@
 #include "funcapi.h"
 #include "nodes/makefuncs.h"
 #include "parser/parse_type.h"
+#include "plpgsql.h"
 #include "utils/builtins.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
@@ -33,9 +34,6 @@
 #include "utils/syscache.h"
 #include "utils/typcache.h"
 
-#include "plpgsql.h"
-
-
 /* ----------
  * Our own local and global variables
  * ----------
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 345065e..fd799b7 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -34,6 +34,7 @@
 #include "parser/parse_coerce.h"
 #include "parser/parse_type.h"
 #include "parser/scansup.h"
+#include "plpgsql.h"
 #include "storage/proc.h"
 #include "tcop/tcopprot.h"
 #include "tcop/utility.h"
@@ -48,9 +49,6 @@
 #include "utils/syscache.h"
 #include "utils/typcache.h"
 
-#include "plpgsql.h"
-
-
 typedef struct
 {
 	int			nargs;			/* number of arguments */
diff --git a/src/pl/plpgsql/src/pl_funcs.c b/src/pl/plpgsql/src/pl_funcs.c
index 053f83d..2d4616c 100644
--- a/src/pl/plpgsql/src/pl_funcs.c
+++ b/src/pl/plpgsql/src/pl_funcs.c
@@ -15,10 +15,8 @@
 
 #include "postgres.h"
 
-#include "utils/memutils.h"
-
 #include "plpgsql.h"
-
+#include "utils/memutils.h"
 
 /* ----------
  * Local variables for namespace handling
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index ce03f1e..e92deb3 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -20,15 +20,13 @@
 #include "catalog/pg_type.h"
 #include "funcapi.h"
 #include "miscadmin.h"
+#include "plpgsql.h"
 #include "utils/builtins.h"
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
 #include "utils/varlena.h"
 
-#include "plpgsql.h"
-
-
 static bool plpgsql_extra_checks_check_hook(char **newvalue, void **extra, GucSource source);
 static void plpgsql_extra_warnings_assign_hook(const char *newvalue, void *extra);
 static void plpgsql_extra_errors_assign_hook(const char *newvalue, void *extra);
diff --git a/src/port/pg_crc32c_armv8.c b/src/port/pg_crc32c_armv8.c
index ebe449e..de725d3 100644
--- a/src/port/pg_crc32c_armv8.c
+++ b/src/port/pg_crc32c_armv8.c
@@ -14,10 +14,10 @@
  */
 #include "c.h"
 
-#include "port/pg_crc32c.h"
-
 #include <arm_acle.h>
 
+#include "port/pg_crc32c.h"
+
 pg_crc32c
 pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)
 {
diff --git a/src/port/pg_crc32c_sse42.c b/src/port/pg_crc32c_sse42.c
index ef56cff..a81718b 100644
--- a/src/port/pg_crc32c_sse42.c
+++ b/src/port/pg_crc32c_sse42.c
@@ -14,10 +14,10 @@
  */
 #include "c.h"
 
-#include "port/pg_crc32c.h"
-
 #include <nmmintrin.h>
 
+#include "port/pg_crc32c.h"
+
 pg_crc32c
 pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len)
 {
diff --git a/src/port/tar.c b/src/port/tar.c
index f1da959..4afe9f2 100644
--- a/src/port/tar.c
+++ b/src/port/tar.c
@@ -1,7 +1,9 @@
 #include "c.h"
-#include "pgtar.h"
+
 #include <sys/stat.h>
 
+#include "pgtar.h"
+
 /*
  * Print a numeric field in a tar header.  The field starts at *s and is of
  * length len; val is the value to be written.
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c
index 556b46d..b50c189 100644
--- a/src/test/isolation/isolationtester.c
+++ b/src/test/isolation/isolationtester.c
@@ -13,11 +13,10 @@
 #endif
 
 #include "datatype/timestamp.h"
+#include "isolationtester.h"
 #include "libpq-fe.h"
-#include "pqexpbuffer.h"
 #include "pg_getopt.h"
-
-#include "isolationtester.h"
+#include "pqexpbuffer.h"
 
 #define PREP_WAITING "isolationtester_waiting"
 
diff --git a/src/test/modules/test_ginpostinglist/test_ginpostinglist.c b/src/test/modules/test_ginpostinglist/test_ginpostinglist.c
index bab073b..7e9d7de 100644
--- a/src/test/modules/test_ginpostinglist/test_ginpostinglist.c
+++ b/src/test/modules/test_ginpostinglist/test_ginpostinglist.c
@@ -12,10 +12,10 @@
  */
 #include "postgres.h"
 
-#include "fmgr.h"
 #include "access/ginblock.h"
 #include "access/gin_private.h"
 #include "access/htup_details.h"
+#include "fmgr.h"
 
 PG_MODULE_MAGIC;
 
diff --git a/src/test/modules/test_integerset/test_integerset.c b/src/test/modules/test_integerset/test_integerset.c
index e3925a1..82d8563 100644
--- a/src/test/modules/test_integerset/test_integerset.c
+++ b/src/test/modules/test_integerset/test_integerset.c
@@ -14,12 +14,12 @@
 
 #include "fmgr.h"
 #include "lib/integerset.h"
+#include "miscadmin.h"
 #include "nodes/bitmapset.h"
-#include "utils/memutils.h"
-#include "utils/timestamp.h"
 #include "storage/block.h"
 #include "storage/itemptr.h"
-#include "miscadmin.h"
+#include "utils/memutils.h"
+#include "utils/timestamp.h"
 
 /*
  * If you enable this, the "pattern" tests will print information about
diff --git a/src/test/modules/test_rls_hooks/test_rls_hooks.c b/src/test/modules/test_rls_hooks/test_rls_hooks.c
index 10379bc..f576ecb 100644
--- a/src/test/modules/test_rls_hooks/test_rls_hooks.c
+++ b/src/test/modules/test_rls_hooks/test_rls_hooks.c
@@ -13,19 +13,16 @@
 
 #include "postgres.h"
 
+#include "catalog/pg_type.h"
 #include "fmgr.h"
 #include "miscadmin.h"
-
-#include "test_rls_hooks.h"
-
-#include "catalog/pg_type.h"
-#include "nodes/makefuncs.h"
 #include "nodes/makefuncs.h"
 #include "parser/parse_clause.h"
 #include "parser/parse_collate.h"
 #include "parser/parse_node.h"
 #include "parser/parse_relation.h"
 #include "rewrite/rowsecurity.h"
+#include "test_rls_hooks.h"
 #include "utils/acl.h"
 #include "utils/rel.h"
 #include "utils/relcache.h"
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index a318168..c1a0fa4 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -20,9 +20,8 @@
 #include "postmaster/bgworker.h"
 #include "storage/procsignal.h"
 #include "storage/shm_toc.h"
-#include "utils/memutils.h"
-
 #include "test_shm_mq.h"
+#include "utils/memutils.h"
 
 typedef struct
 {
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index bc9ef64..70ae3cb 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -22,24 +22,22 @@
  */
 #include "postgres.h"
 
-/* These are always necessary for a bgworker */
+/* these headers are used by this particular worker's code */
+#include "access/xact.h"
+#include "executor/spi.h"
+#include "fmgr.h"
+#include "lib/stringinfo.h"
 #include "miscadmin.h"
+#include "pgstat.h"
 #include "postmaster/bgworker.h"
 #include "storage/ipc.h"
 #include "storage/latch.h"
 #include "storage/lwlock.h"
 #include "storage/proc.h"
 #include "storage/shmem.h"
-
-/* these headers are used by this particular worker's code */
-#include "access/xact.h"
-#include "executor/spi.h"
-#include "fmgr.h"
-#include "lib/stringinfo.h"
-#include "pgstat.h"
+#include "tcop/utility.h"
 #include "utils/builtins.h"
 #include "utils/snapmgr.h"
-#include "tcop/utility.h"
 
 PG_MODULE_MAGIC;
 
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 3a39472..6554ce2 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -29,14 +29,13 @@
 #include <sys/resource.h>
 #endif
 
-#include "pg_regress.h"
-
 #include "common/logging.h"
 #include "common/restricted_token.h"
 #include "common/username.h"
 #include "getopt_long.h"
 #include "libpq/pqcomm.h"		/* needed for UNIXSOCK_PATH() */
 #include "pg_config_paths.h"
+#include "pg_regress.h"
 #include "portability/instr_time.h"
 
 /* for resultmap we need a list of pairs of strings */
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index cb8ef53..2f66d76 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -36,10 +36,9 @@
 #include "port/atomics.h"
 #include "utils/builtins.h"
 #include "utils/geo_decls.h"
+#include "utils/memutils.h"
 #include "utils/rel.h"
 #include "utils/typcache.h"
-#include "utils/memutils.h"
-
 
 #define EXPECT_TRUE(expr)	\
 	do { \
-- 
1.8.3.1

