Neon Postgres offers a robust, cloud-native PostgreSQL experience, but understanding which versions are supported and how to navigate upgrades is crucial for maintaining a stable and performant database.
Here’s a look at Neon’s supported PostgreSQL versions and the upgrade process:
Supported PostgreSQL Versions
Neon primarily supports the latest stable releases of PostgreSQL. As of my last update, this typically includes:
- PostgreSQL 16: The most recent major version, offering performance improvements and new features.
- PostgreSQL 15: A widely adopted and stable version with significant enhancements over its predecessor.
- PostgreSQL 14: Still a strong contender, offering a mature feature set.
Neon’s strategy is to stay close to upstream PostgreSQL releases, providing access to the newest capabilities and security patches. It’s important to note that older, end-of-life PostgreSQL versions are generally not supported. This ensures that users benefit from the latest advancements and security hardening.
Why Stay Current?
- New Features: Each major PostgreSQL release introduces new SQL functions, data types, performance optimizations, and developer-friendly features.
- Performance Improvements: Newer versions often include significant performance enhancements, especially in areas like query planning, indexing, and concurrency.
- Security Patches: Staying on supported versions ensures you receive timely security updates, protecting your data from vulnerabilities.
- Bug Fixes: Newer releases address known bugs and stability issues present in older versions.
Upgrading Your Neon Postgres Database
Neon simplifies the upgrade process significantly compared to traditional self-managed PostgreSQL. The primary method involves creating a new compute endpoint connected to a newer PostgreSQL version and then migrating your data.
The Recommended Upgrade Path:
-
Create a New Compute Endpoint:
- Navigate to your Neon project in the Neon Console.
- Go to the "Compute" section.
- Click "Add compute endpoint."
- Select the desired PostgreSQL version (e.g., 15 or 16) for your new endpoint.
- Give the new endpoint a descriptive name (e.g.,
myproject-pg16).
-
Migrate Your Data:
- Method A:
pg_dumpandpsql(for smaller databases or controlled downtime)- Connect to your existing (older) compute endpoint.
- Use
pg_dumpto create a logical backup:
(Replace placeholders with your actual connection details and database name.pg_dump -h <old_host> -U <user> -d <database_name> -F c -b -v -f backup.dump-F ccreates a custom-format archive,-bincludes blobs,-vis verbose.) - Connect to your new compute endpoint (which will have an empty database initially).
- Use
psqlto restore the dump:psql -h <new_host> -U <user> -d <database_name> -c "CREATE DATABASE <database_name>;" # If database doesn't exist pg_restore -h <new_host> -U <user> -d <database_name> -v backup.dump
- Method B: Neon’s Branching and Logical Replication (for minimal downtime)
- Create a new branch from your primary branch in the Neon Console. This new branch will inherit the current PostgreSQL version.
- Upgrade the new branch: In the Neon Console, find the new branch, click the "Branch actions" menu, and select "Upgrade branch." Choose the target PostgreSQL version (e.g., 16). Neon will provision a new compute instance for this branch with the upgraded version.
- Set up Logical Replication: Once the new branch is running the target version, you can set up logical replication from your old primary branch to the new, upgraded branch. This allows for continuous data synchronization.
- On the source (old) branch: Enable logical replication (
wal_level = logicalin Neon’s config or via the console). Create a publication for the tables you want to replicate. - On the target (new) branch: Create a subscription to the publication on the source branch.
- On the source (old) branch: Enable logical replication (
- Cutover: Once replication is caught up, stop writes to the old branch, wait for the replication lag to reach zero, and then point your application to the new branch’s compute endpoint.
- Method A:
-
Update Application Connection Strings:
- After data migration and verification, update your application’s database connection strings to point to the hostname of the new compute endpoint.
-
Decommission Old Compute Endpoint:
- Once you are confident that the new environment is stable and your application is running correctly, you can delete the old compute endpoint to avoid incurring unnecessary costs.
Considerations for Upgrades
- Testing: Always perform upgrades in a staging or development environment first. Test your application thoroughly with the new PostgreSQL version.
- Downtime: While Neon minimizes downtime, some interruption is usually unavoidable during the final cutover. Plan accordingly.
- Extensions: Ensure that any PostgreSQL extensions you use are compatible with the target PostgreSQL version. You may need to update or re-install them.
- SQL Differences: Be aware of any deprecated or changed SQL syntax or functions between versions. PostgreSQL release notes are your best friend here.
The next step after successfully upgrading your PostgreSQL version is often exploring new performance tuning techniques specific to the upgraded version.