# HG changeset patch
# User Robert Marshall <rmarshall@gitlab.com>
# Date 1650318751 14400
#      Mon Apr 18 17:52:31 2022 -0400
# Node ID 5730836d59a43d89e087daed4ee31c1375b46a9f
# Parent  0c64f5dc3122c08ffea3e60e139897ddbcbfc0c7
Default to PG13 in new installations

- New installations using Omnibus GitLab will use PostgreSQL version
  13.3 by default

Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/6707

Changelog: changed

Signed-off-by: Robert Marshall <rmarshall@gitlab.com>

diff --git a/config/software/postgresql.rb b/config/software/postgresql.rb
--- a/config/software/postgresql.rb
+++ b/config/software/postgresql.rb
@@ -58,12 +58,6 @@
 
   make "world -j #{workers}", env: env
   make 'install-world', env: env
-
-  block 'link bin files' do
-    Dir.glob("#{prefix}/bin/*").each do |bin_file|
-      link bin_file, "#{install_dir}/embedded/bin/#{File.basename(bin_file)}"
-    end
-  end
 end
 
 # exclude headers and static libraries from package
diff --git a/config/software/postgresql_new.rb b/config/software/postgresql_new.rb
--- a/config/software/postgresql_new.rb
+++ b/config/software/postgresql_new.rb
@@ -61,6 +61,12 @@
   make 'install-world', env: env
 
   link "#{prefix}/lib/#{libpq}", "#{install_dir}/embedded/lib/#{libpq}"
+
+  block 'link bin files' do
+    Dir.glob("#{prefix}/bin/*").each do |bin_file|
+      link bin_file, "#{install_dir}/embedded/bin/#{File.basename(bin_file)}"
+    end
+  end
 end
 
 # exclude headers and static libraries from package
diff --git a/doc/settings/database.md b/doc/settings/database.md
--- a/doc/settings/database.md
+++ b/doc/settings/database.md
@@ -44,7 +44,7 @@
 Omnibus automatically enables SSL on the PostgreSQL server, but it will accept
 both encrypted and unencrypted connections by default. Enforcing SSL requires
 using the `hostssl` configuration in `pg_hba.conf`. For more details, see the
-[`pg_hba.conf` documentation](https://www.postgresql.org/docs/12/auth-pg-hba-conf.html).
+[`pg_hba.conf` documentation](https://www.postgresql.org/docs/13/auth-pg-hba-conf.html).
 
 SSL support depends on the following files:
 
@@ -489,6 +489,22 @@
 sudo touch /etc/gitlab/disable-postgresql-upgrade
 ```
 
+#### GitLab 15.0 and later
+
+As of GitLab 15.0, new installations will default to PostgreSQL 13.
+
+Existing single database node instances can update manually via:
+
+```shell
+sudo gitlab-ctl pg-upgrade -V 13
+```
+
+Until PostgreSQL 12 is removed, administrators may
+[pin the PostgreSQL version](#pin-the-packaged-postgresql-version-fresh-installs-only)
+if needed for compatibility or test environment reasons.
+
+[Fault tolerant and Geo installations require additional steps and planning](https://docs.gitlab.com/ee/administration/postgresql/replication_and_failover.html#upgrading-postgresql-major-version-in-a-patroni-cluster).
+
 #### GitLab 14.0 and later
 
 PostgreSQL versions 11 is no longer supported and the binaries have been
@@ -916,6 +932,7 @@
 ### Pin the packaged PostgreSQL version (fresh installs only)
 
 NOTE:
+GitLab 14.1 and onward shipped with both Postgres 12 and Postgres 13.
 GitLab 14.0 only ships with PostgreSQL 12. GitLab 13.3 and onward shipped both Postgres 11 and Postgres 12.
 GitLab 13.0 through 13.2 only shipped with PostgreSQL 11.
 
@@ -923,7 +940,7 @@
 
 To initialize PostgreSQL with a non-default version, you can set `postgresql['version']` to the major version one of
 the [packaged PostgreSQL versions](https://docs.gitlab.com/ee/administration/package_information/postgresql_versions.html) prior to the initial reconfigure.
-For example, in GitLab 13.7 you can use `postgresql['version'] = 11` to use PostgreSQL 11 instead of the default of PostgreSQL 12.
+For example, in GitLab 15.0 you can use `postgresql['version'] = 12` to use PostgreSQL 12 instead of the default of PostgreSQL 13.
 
 WARNING:
 Setting `postgresql['version']` while using the Omnibus packaged PostgreSQL after the initial reconfigure will
diff --git a/doc/update/gitlab_15_changes.md b/doc/update/gitlab_15_changes.md
--- a/doc/update/gitlab_15_changes.md
+++ b/doc/update/gitlab_15_changes.md
@@ -31,3 +31,9 @@
 In 14.10, [Gitaly introduced a new directory](gitlab_14_changes.md#gitaly-runtime-directory) that holds all runtime data Gitaly requires to operate correctly. This new directory replaces the old internal socket directory, and consequentially the usage of `gitaly['internal_socket_dir']` was deprecated in favor of `gitaly['runtime_dir']`.
 
 The old `gitaly['internal_socket_dir']` configuration was removed in this release.
+
+### PostgreSQL 13.3 support
+
+PostgreSQL 13.3 is being shipped as the default version for fresh installs.
+
+Users can manually upgrade to 13.3 following the [upgrade docs](../settings/database.md#gitlab-150-and-later).
diff --git a/docker/assets/wrapper b/docker/assets/wrapper
--- a/docker/assets/wrapper
+++ b/docker/assets/wrapper
@@ -172,7 +172,7 @@
 
 # This must be false when the opt-in PostgreSQL version is the default for pg-upgrade,
 # otherwise it must be true.
-ATTEMPT_AUTO_PG_UPGRADE='true'
+ATTEMPT_AUTO_PG_UPGRADE='false'
 
 # Make sure PostgreSQL is at the latest version.
 # If it fails, print a message with a workaround and exit
diff --git a/files/gitlab-ctl-commands/pg-upgrade.rb b/files/gitlab-ctl-commands/pg-upgrade.rb
--- a/files/gitlab-ctl-commands/pg-upgrade.rb
+++ b/files/gitlab-ctl-commands/pg-upgrade.rb
@@ -681,7 +681,7 @@
 end
 
 def default_version
-  PGVersion.parse(version_from_manifest('postgresql'))
+  PGVersion.parse(version_from_manifest('postgresql_new')) || PGVersion.parse(version_from_manifest('postgresql'))
 end
 
 def new_version
diff --git a/files/gitlab-ctl-commands/upgrade.rb b/files/gitlab-ctl-commands/upgrade.rb
--- a/files/gitlab-ctl-commands/upgrade.rb
+++ b/files/gitlab-ctl-commands/upgrade.rb
@@ -354,7 +354,7 @@
 def attempt_auto_pg_upgrade?
   # This must return false when the opt-in PostgreSQL version is the default for pg-upgrade,
   # otherwise it must be true.
-  true
+  false
 end
 
 def recommend_pg_upgrade?