Starting with AlloyDB Omni 15.5.4, you control AlloyDB Omni with common package-management tools.
If you have an existing installation of AlloyDB Omni, follow the instructions on this page to migrate to the new, single-image installation.
Prerequisites
Before you can start upgrading to the latest version of AlloyDB Omni, complete the following prerequisites, if you haven't done so already.
Upgrade to AlloyDB Omni 15.5.2
The latest AlloyDB Omni version that supports the AlloyDB Omni CLI is 15.5.2. To check the version of AlloyDB Omni, run the following command:
sudo alloydb versionThe output looks similar to the following:
AlloyDB Omni CLI version: 1.6
AlloyDB Omni database server version: 15.5.2
If the output displays a database version earlier than 15.5.2, run the following command to upgrade:
sudo alloydb database-server upgradeGather information about your existing installation
Run the following command:
cat /var/alloydb/config/dataplane.confFrom the output of the
catcommand, note the values of the following variables for your reference:DATADIR_PATH—for example,/var/alloydb/mainENABLE_ALLOYDB_AI—for example,FALSEPGPORT—for example,5432INSTANCE_TYPE—for example,PRIMARY/READ_REPLICA
Drop ScaNN indexes created with postgres_ann extension
The postgres_ann extension is renamed to alloydb_scann. If you have installed the postgres_ann extension and created ScaNN indexes using the extension, you must drop all ScaNN indexes and uninstall the extension before performing an upgrade.
To handle any impact to your database due to the renaming of the postgres_ann extension, complete the following steps:
- Run and connect to AlloyDB Omni.
Identify all tables that use the
ScaNNindex.\c DATABASE_NAME select schemaname, relname, indexrelname, indextype, indexconfig, indexsize, indexscan FROM pg_stat_ann_indexes;Replace
DATABASE_NAMEwith the name of the database where you want to run the query.Save index definitions and parameters as a dump DDL using a utility like
pg_dumpto recreate theScaNNindexes later.pg_dump -st TABLE_NAME DATABASE_NAMEReplace the following:
DATABASE_NAME: the name of the database.TABLE_NAME: the name of the table.
Drop
ScaNNIndexes that were created using thepostgres_annindex.DROP INDEX INDEX_NAME;Replace
INDEX_NAMEwith the name of the database where you want to run the query.Verify that none of your databases include
ScaNNindexes. Use the following SQL query to verify the deletion: The following sql should return an empty result set.\c DATABASE_NAME select schemaname, relname, indexrelname, indextype, indexconfig, indexsize, indexscan FROM pg_stat_ann_indexes;Drop the
postgres_annextension using the following steps:- Verify that the
postgres_annextension is installed in your database.
select * from pg_extension;- Drop the
postgres_annextension.
DROP EXTENSION postgres_ann CASCADE;- Verify that the
postgres_annextension is no longer installed in your database.
select * from pg_extension;- Verify that the
Perform an in-place upgrade
Stop the existing database:
sudo alloydb database-server stopStart the new single-image AlloyDB Omni, mounting your existing data directory from before:
docker run --name CONTAINER_NAME \ -e POSTGRES_PASSWORD=PASSWORD \ -e PGDATA=/var/lib/postgresql/data \ -v /var/alloydb/main/data:/var/lib/postgresql/data \ -v /dev/shm:/dev/shm \ -p PGPORT:5432 \ --network=host \ --ulimit=nice=-20:-20 \ --ulimit=core=-1:-1 \ --log-driver=journald \ -d google/alloydbomniReplace the following:
CONTAINER_NAME: The name to assign this new AlloyDB Omni container in your host machine's container registry—for example,my-omni.PASSWORD: The password assigned the new container'spostgresuser after its creation.PGPORT: The IP address of the port the AlloyDB Omni runs on. This is the value you noted down in step 2 of Gather information about your existing installation.
The arguments to
docker runare the same as in earlier versions of AlloyDB Omni, but you may further customize them. See Customize your AlloyDB Omni installation for details.If your database instance type is
PRIMARY, run the following command to create the following users. These are usernames which are unused at the moment, but reserved for future extensions.for name in alloydbagent alloydbexport alloydbiamgroupuser alloydbiamuser alloydbimportexport alloydbobservability alloydbsqllogical alloydbsuperuser; do echo docker exec -it CONTAINER_NAME psql -h localhost -U postgres alloydbadmin \ -c "CREATE ROLE ${name} NOLOGIN;" \ -c "CREATE TABLE ${name}_table();" \ -c "ALTER TABLE ${name}_table OWNER TO ${name};" doneIf
ENABLE_ALLOYDB_AIisTRUE, follow the instructions in Install AlloyDB Omni with AlloyDB AI to set up AlloyDB AI.Connect to the database to verify that the data is unchanged:
docker exec -it CONTAINER_NAME psql -h localhost -U postgresUninstall the AlloyDB Omni CLI:
sudo alloydb database-server uninstallThe AlloyDB Omni CLI uninstallation does not affect your data stored in AlloyDB Omni.
Recreate ScaNN indexes using alloydb_scann extension
After you upgrade AlloyDB Omni, the alloydb_scann extension is also installed. Complete the following steps to recreate ScaNN indexes that you dropped in the Drop ScaNN indexes created with postgres_ann extension section before the upgrade.
Create the
alloydb_scannextension using the following steps:- To create the
alloydb_scannextension, run the following query:
create extension alloydb_scann cascade;- Verify that the
alloydb_scannextension was created successfully.
select * from pg_extension;- To create the
Recreate
ScaNNindex for your table, and then restore the previouspg_dumpDDL index definitions.- Create
ScaNNindex on the table:
CREATE INDEX INDEX_NAME ON TABLE_NAME USING scann (VECTOR_COLUMN DISTANCE) WITH (num_leaves = NUM_LEAVES_VALUE);Replace the following:
- INDEX_NAME: the name of the index.
- TABLE_NAME: the name of the table.
- VECTOR_COLUMN: the name of the column that stores vector data.
- DISTANCE: the distance function to use with this index.
- NUM_LEAVES_VALUE: the number of partitions to apply to the index.
- Verify that the index is created.
\d TABLE_NAME- Recommended: Backup your indexes data. We recommend creating a backup of your database and indexes as a best practice.
- Create