Skip to content

Instantly share code, notes, and snippets.

@cabecada
Created March 16, 2024 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cabecada/e831c11011d28bd3347f2ee7e9fb14ee to your computer and use it in GitHub Desktop.
Save cabecada/e831c11011d28bd3347f2ee7e9fb14ee to your computer and use it in GitHub Desktop.
citus migrate from pg14 worker to pg15 worker
postgres@pg:~/citusdb/migration/14$ /usr/lib/postgresql/14/bin/psql -p 5432 citusdb
psql (14.9 (Ubuntu 14.9-1.pgdg22.04+1), server 14.10 (Ubuntu 14.10-1.pgdg22.04+1))
Type "help" for help.
citusdb=#
citusdb=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | dist_t | table | postgres
public | local_t | table | postgres
public | ref_t | table | postgres
(3 rows)
citusdb=# SELECT * FROM citus_get_active_worker_nodes();
node_name | node_port
-----------+-----------
localhost | 5434
localhost | 5433
localhost | 5435
(3 rows)
citusdb=# select count(1) from dist_t;
count
-------
10000
(1 row)
citusdb=# SELECT * from citus_add_node('localhost', 6432);
citus_add_node
----------------
5
(1 row)
citusdb=# SELECT * FROM citus_get_active_worker_nodes();
node_name | node_port
-----------+-----------
localhost | 5434 --pg14
localhost | 6432 --pg15
localhost | 5433 --pg14(we drain and remove this one with 6432)
localhost | 5435 --pg14
(4 rows)
citusdb=# SELECT * from citus_drain_node('localhost', 5433);
NOTICE: replicating reference table 'ref_t' to localhost:6432 ...
NOTICE: Moving shard 102009 from localhost:5433 to localhost:5434 ...
NOTICE: Moving shard 102012 from localhost:5433 to localhost:5435 ...
NOTICE: Moving shard 102015 from localhost:5433 to localhost:6432 ...
NOTICE: Moving shard 102018 from localhost:5433 to localhost:5434 ...
NOTICE: Moving shard 102021 from localhost:5433 to localhost:5435 ...
NOTICE: Moving shard 102024 from localhost:5433 to localhost:6432 ...
NOTICE: Moving shard 102027 from localhost:5433 to localhost:5434 ...
NOTICE: Moving shard 102030 from localhost:5433 to localhost:5435 ...
NOTICE: Moving shard 102033 from localhost:5433 to localhost:6432 ...
NOTICE: Moving shard 102036 from localhost:5433 to localhost:5434 ...
NOTICE: Moving shard 102039 from localhost:5433 to localhost:5435 ...
citus_drain_node
------------------
(1 row)
citusdb=# CALL citus_cleanup_orphaned_resources();
NOTICE: cleaned up 1 orphaned resources
CALL
citusdb=# SELECT * from citus_remove_node('localhost', 5433);
citus_remove_node
-------------------
(1 row)
citusdb=# SELECT * FROM citus_get_active_worker_nodes();
node_name | node_port
-----------+-----------
localhost | 5434
localhost | 6432
localhost | 5435
(3 rows)
citusdb=# SELECT * FROM citus_get_active_worker_nodes();
node_name | node_port
-----------+-----------
localhost | 5434
localhost | 6432
localhost | 5435
(3 rows)
postgres@pg:~/citusdb/migration/14$ /usr/lib/postgresql/14/bin/psql citusdb -p 5433
psql (14.9 (Ubuntu 14.9-1.pgdg22.04+1), server 14.10 (Ubuntu 14.10-1.pgdg22.04+1))
Type "help" for help.
citusdb=#
citusdb=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | dist_t | table | postgres
public | ref_t | table | postgres
(2 rows)
citusdb=# select count(1) from dist_t;
count
-------
10000
(1 row)
citusdb=#
\q
#we stop one of the worker which is pg14 which we moved to pg15 port 6432
postgres@pg:~/citusdb/migration/14$ /usr/lib/postgresql/14/bin/pg_ctl -D db2 stop
waiting for server to shut down.... done
server stopped
#confirm by running queries from pg15 workers, data returned fine
postgres@pg:~/citusdb/migration/15$ /usr/lib/postgresql/15/bin/psql -p 6432
psql (15.0 (Ubuntu 15.0-1.pgdg22.04+1), server 15.6 (Ubuntu 15.6-1.pgdg22.04+1))
Type "help" for help.
postgres=# \c citusdb
psql (15.0 (Ubuntu 15.0-1.pgdg22.04+1), server 15.6 (Ubuntu 15.6-1.pgdg22.04+1))
You are now connected to database "citusdb" as user "postgres".
citusdb=# select count(1) from dist_t;
count
-------
10000
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment