-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-1515] Database. Upgrade the PostgreSQL version to 16. #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vladsha-dev
merged 11 commits into
main
from
OSDEV-1515-database-upgrade-the-postgresql-version-to-17
Jan 29, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9f1ae31
Upgraded the PostgreSQL version to 17 for local development and anony…
vladsha-dev 1440e8c
Upgrade Postgres version for each environment
vladsha-dev 8807445
Temporarily add 4 tasks to the Dev environment to avoid downtime.
vladsha-dev 9f22419
Downgrade Postgres version to 16 in Terraform
vladsha-dev 1f8d6ca
Downgrade Postgres version to 16 in Dockerfiles
vladsha-dev 91ed7a0
Update RELEASE-NOTES.md file
vladsha-dev 57d4e4f
Fix grammar mistake
vladsha-dev 9ebefe3
Set the latest tag version to refer to in the terraform-aws-postgresq…
vladsha-dev 6744638
Merge branch 'main' into OSDEV-1515-database-upgrade-the-postgresql-v…
vladsha-dev e217ce4
Merge branch 'main' into OSDEV-1515-database-upgrade-the-postgresql-v…
vladsha-dev 07df03a
Merge branch 'main' into OSDEV-1515-database-upgrade-the-postgresql-v…
vladsha-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...4_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Generated by Django 3.2.17 on 2025-01-24 15:21 | ||
|
|
||
| from django.db.migrations import Migration, RunPython | ||
| from django.db import connection | ||
| from api.migrations._migration_helper import MigrationHelper | ||
|
|
||
| helper = MigrationHelper(connection) | ||
|
|
||
|
|
||
| def refresh_pg_statistic_and_perform_upgrading_pg_extensions( | ||
| apps, schema_editor): | ||
| helper.run_sql_files([ | ||
| ('0164_refresh_pg_statistic_and_upgrade_postgres_extensions' | ||
| '_after_db_upgrade_to_postgres_16.sql') | ||
| ]) | ||
|
|
||
|
|
||
| class Migration(Migration): | ||
| ''' | ||
| This migration refreshes the pg_statistic table and upgrades the | ||
| PostgreSQL database extensions in light of the upgrade to Postgres 16. | ||
|
|
||
| Since this migration will be executed after the PostgreSQL major version | ||
| upgrade, the ANALYZE operation should be run to refresh the pg_statistic | ||
| table. Optimizer statistics aren't transferred during a major version | ||
| upgrade, so it is necessary to regenerate all statistics to avoid | ||
| performance issues. | ||
|
|
||
| Currently, the database uses the following extensions: | ||
| 1. postgis | ||
| 2. unaccent | ||
| 3. pg_trgm | ||
| 4. plpgsql | ||
| 5. btree_gin | ||
| 6. pgcrypto | ||
|
|
||
| Based on the available extension versions for PostgreSQL 16.3 in AWS RDS, | ||
| which will be used across all AWS environments after the database upgrade | ||
| to Postgres 16, it was found that the `pg_trgm` extensions can be upgraded | ||
| to version 1.6, respectively, in Production, Staging, Test, and | ||
| Development environments. If the specified versions are already installed | ||
| in the database, there will be no issues. | ||
| ''' | ||
|
|
||
| dependencies = [ | ||
| ('api', '0163_refresh_pg_statistic_and_upgrade_postgres_extensions'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| RunPython(refresh_pg_statistic_and_perform_upgrading_pg_extensions) | ||
| ] |
54 changes: 52 additions & 2 deletions
54
src/django/sqls/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,54 @@ | ||
| ANALYZE VERBOSE; | ||
|
|
||
| ALTER EXTENSION postgis UPDATE TO '3.4.2'; | ||
| ALTER EXTENSION pg_trgm UPDATE TO '1.5'; | ||
| DO $$ | ||
| DECLARE | ||
| -- Variables for postgis. | ||
| current_version_postgis TEXT; | ||
| target_version_postgis TEXT := '3.4.2'; | ||
|
|
||
| -- Variables for pg_trgm. | ||
| current_version_pg_trgm TEXT; | ||
| target_version_pg_trgm TEXT := '1.5'; | ||
mazursasha1990 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| BEGIN | ||
| -- Extension 1: Check and upgrade "postgis" to its target version. | ||
| SELECT | ||
| extversion | ||
| INTO | ||
| current_version_postgis | ||
| FROM | ||
| pg_extension | ||
| WHERE | ||
| extname = 'postgis'; | ||
|
|
||
| IF current_version_postgis IS NULL THEN | ||
| RAISE EXCEPTION 'Extension "postgis" is not installed.'; | ||
| ELSIF current_version_postgis < target_version_postgis | ||
| THEN | ||
| EXECUTE FORMAT('ALTER EXTENSION postgis UPDATE TO %L', target_version_postgis); | ||
| RAISE NOTICE 'Extension "postgis" has been upgraded from % to %.', current_version_postgis, target_version_postgis; | ||
| ELSE | ||
| RAISE NOTICE 'Extension "postgis" is already at the target version or higher.'; | ||
| END IF; | ||
|
|
||
| -- Extension 2: Check and upgrade "pg_trgm" to its target version. | ||
| SELECT | ||
| extversion | ||
| INTO | ||
| current_version_pg_trgm | ||
| FROM | ||
| pg_extension | ||
| WHERE | ||
| extname = 'pg_trgm'; | ||
|
|
||
| IF current_version_pg_trgm IS NULL | ||
| THEN | ||
| RAISE EXCEPTION 'Extension "pg_trgm" is not installed.'; | ||
| ELSIF current_version_pg_trgm < target_version_pg_trgm | ||
| THEN | ||
| EXECUTE FORMAT('ALTER EXTENSION pg_trgm UPDATE TO %L', target_version_pg_trgm); | ||
| RAISE NOTICE 'Extension "pg_trgm" has been upgraded from % to %.', current_version_pg_trgm, target_version_pg_trgm; | ||
| ELSE | ||
| RAISE NOTICE 'Extension "pg_trgm" is already at the target version or higher.'; | ||
| END IF; | ||
| END $$; | ||
30 changes: 30 additions & 0 deletions
30
..._refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ANALYZE VERBOSE; | ||
|
|
||
| DO $$ | ||
| DECLARE | ||
| -- Variables for pg_trgm. | ||
| current_version_pg_trgm TEXT; | ||
| target_version_pg_trgm TEXT := '1.6'; | ||
|
|
||
| BEGIN | ||
| -- Extension 1: Check and upgrade "pg_trgm" to its target version. | ||
| SELECT | ||
| extversion | ||
| INTO | ||
| current_version_pg_trgm | ||
| FROM | ||
| pg_extension | ||
| WHERE | ||
| extname = 'pg_trgm'; | ||
|
|
||
| IF current_version_pg_trgm IS NULL | ||
| THEN | ||
| RAISE EXCEPTION 'Extension "pg_trgm" is not installed.'; | ||
| ELSIF current_version_pg_trgm < target_version_pg_trgm | ||
| THEN | ||
| EXECUTE FORMAT('ALTER EXTENSION pg_trgm UPDATE TO %L', target_version_pg_trgm); | ||
| RAISE NOTICE 'Extension "pg_trgm" has been upgraded from % to %.', current_version_pg_trgm, target_version_pg_trgm; | ||
| ELSE | ||
| RAISE NOTICE 'Extension "pg_trgm" is already at the target version or higher.'; | ||
| END IF; | ||
| END $$; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.