Skip to content

Instantly share code, notes, and snippets.

@cabecada
Last active March 27, 2024 19:28
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/977e95f654a38a5e7e92418966b966e1 to your computer and use it in GitHub Desktop.
Save cabecada/977e95f654a38a5e7e92418966b966e1 to your computer and use it in GitHub Desktop.
citus upgrade with ssl
postgres@pg:~/demo$ cat post_upgrade.sh
#!/bin/bash
killall /usr/lib/postgresql/15/bin/postgres
killall /usr/lib/postgresql/16/bin/postgres
rm -rf /var/lib/postgresql/demo/15
rm -rf /var/lib/postgresql/demo/16
mkdir -p /var/lib/postgresql/demo/{15,16}
echo "################### pg15 start #####################"
cd /var/lib/postgresql/demo/15
export PATH=/usr/lib/postgresql/15/bin:$PATH
port=5432
for i in db1 db2 db3
do
pg_ctl -D $i stop
[[ -f ${i}.log ]] && rm ${i}.log
[[ -d ${i} ]] && rm -rf ${i}
if [[ $1x == "start"x ]]; then
initdb -D $i
echo "listen_addresses='*'" >> $i/postgresql.auto.conf
echo "shared_preload_libraries = 'citus'" >> $i/postgresql.auto.conf
echo "port=$port" >> $i/postgresql.auto.conf
echo "wal_level=logical" >> $i/postgresql.auto.conf
port=$(( port + 1 ))
fi
done
for i in 1 2 3
do
db=db${i}
pg_ctl -D ${db} -l ${db}.log start
done
for p in 5432 5433 5434
do
createdb -p $p citusdb
psql -p $p -d citusdb -c "create extension citus;"
done
psql -p 5432 citusdb <<'EOF'
SET citus.shard_count = 32;
SELECT citus_set_coordinator_host('localhost', 5432);
SELECT * from citus_add_node('localhost', 5433);
SELECT * from citus_add_node('localhost', 5434);
SELECT * FROM citus_get_active_worker_nodes();
CREATE TABLE dist_t(dist_id int primary key, col1 int, col2 text);
insert into dist_t select x,x,x from generate_series(1, 10000) x;
CREATE TABLE ref_t(ref_id int primary key, col1 int, col2 int);
insert into ref_t select x,x,x from generate_series(1, 100000) x;
SELECT create_reference_table('ref_t');
SELECT create_distributed_table('dist_t', 'dist_id');
create table local_t(id int primary key);
insert into local_t select 1;
EOF
for p in 5432 5433 5434
do
psql -p $p -d citusdb -c "SELECT citus_prepare_pg_upgrade();"
done
for i in 1 2 3
do
db=db${i}
pg_ctl -D ${db} -l ${db}.log stop
done
sleep 5
echo "################### pg15 end #####################"
echo "################### pg16 start #####################"
cd /var/lib/postgresql/demo/16
export PATH=/usr/lib/postgresql/16/bin:$PATH
port=5432
for i in db1 db2 db3
do
pg_ctl -D $i stop
[[ -f ${i}.log ]] && rm ${i}.log
[[ -d ${i} ]] && rm -rf ${i}
if [[ $1x == "start"x ]]; then
initdb -D $i
echo "listen_addresses='*'" >> $i/postgresql.auto.conf
echo "shared_preload_libraries = 'citus'" >> $i/postgresql.auto.conf
echo "port=$port" >> $i/postgresql.auto.conf
echo "wal_level=logical" >> $i/postgresql.auto.conf
echo "ssl=on" >> $i/postgresql.auto.conf
port=$(( port + 1 ))
cp ../15/$i/server.* $i/
fi
done
echo "################### pg16 end #####################"
echo "################### start upgrade #####################"
cd /var/lib/postgresql/demo
for i in db1 db2 db3; do /usr/lib/postgresql/16/bin/pg_upgrade -b /usr/lib/postgresql/15/bin -B /usr/lib/postgresql/16/bin -d 15/$i -D 16/$i --link -c; done
for i in db1 db2 db3; do /usr/lib/postgresql/16/bin/pg_upgrade -b /usr/lib/postgresql/15/bin -B /usr/lib/postgresql/16/bin -d 15/$i -D 16/$i --link ; done
cd /var/lib/postgresql/demo/16
for i in db1 db2 db3; do /usr/lib/postgresql/16/bin/pg_ctl -D $i -l $i.log start; done
for i in 5432 5433 5434; do /usr/lib/postgresql/16/bin/psql -p $i -d citusdb -c 'SELECT citus_finish_pg_upgrade();'; done
psql -p 5432 citusdb -c 'select count(1) from dist_t;'
echo "################### finish upgrade #####################"
--------------------------------------------------------------------------------------------------------------
postgres@pg:~/demo$ bash post_upgrade.sh start
/usr/lib/postgresql/15/bin/postgres: no process found
################### pg15 start #####################
pg_ctl: directory "db1" does not exist
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory db1 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D db1 -l logfile start
pg_ctl: directory "db2" does not exist
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory db2 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D db2 -l logfile start
pg_ctl: directory "db3" does not exist
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory db3 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D db3 -l logfile start
waiting for server to start.... done
server started
waiting for server to start.... done
server started
waiting for server to start.... done
server started
CREATE EXTENSION
CREATE EXTENSION
CREATE EXTENSION
SET
citus_set_coordinator_host
----------------------------
(1 row)
citus_add_node
----------------
2
(1 row)
citus_add_node
----------------
3
(1 row)
node_name | node_port
-----------+-----------
localhost | 5434
localhost | 5433
(2 rows)
CREATE TABLE
INSERT 0 10000
CREATE TABLE
INSERT 0 100000
NOTICE: Copying data from local table...
NOTICE: copying the data has completed
DETAIL: The local data in the table is no longer visible, but is still on disk.
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$public.ref_t$$)
create_reference_table
------------------------
(1 row)
NOTICE: Copying data from local table...
NOTICE: copying the data has completed
DETAIL: The local data in the table is no longer visible, but is still on disk.
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$public.dist_t$$)
create_distributed_table
--------------------------
(1 row)
CREATE TABLE
INSERT 0 1
NOTICE: aggregate array_cat_agg(anyarray) does not exist, skipping
NOTICE: table "pg_dist_partition" does not exist, skipping
NOTICE: table "pg_dist_shard" does not exist, skipping
NOTICE: table "pg_dist_placement" does not exist, skipping
NOTICE: table "pg_dist_node_metadata" does not exist, skipping
NOTICE: table "pg_dist_node" does not exist, skipping
NOTICE: table "pg_dist_local_group" does not exist, skipping
NOTICE: table "pg_dist_transaction" does not exist, skipping
NOTICE: table "pg_dist_colocation" does not exist, skipping
NOTICE: table "pg_dist_authinfo" does not exist, skipping
NOTICE: table "pg_dist_poolinfo" does not exist, skipping
NOTICE: table "pg_dist_rebalance_strategy" does not exist, skipping
NOTICE: table "pg_dist_object" does not exist, skipping
NOTICE: table "pg_dist_cleanup" does not exist, skipping
NOTICE: table "pg_dist_schema" does not exist, skipping
NOTICE: table "pg_dist_clock_logical_seq" does not exist, skipping
citus_prepare_pg_upgrade
--------------------------
(1 row)
NOTICE: aggregate array_cat_agg(anyarray) does not exist, skipping
NOTICE: table "pg_dist_partition" does not exist, skipping
NOTICE: table "pg_dist_shard" does not exist, skipping
NOTICE: table "pg_dist_placement" does not exist, skipping
NOTICE: table "pg_dist_node_metadata" does not exist, skipping
NOTICE: table "pg_dist_node" does not exist, skipping
NOTICE: table "pg_dist_local_group" does not exist, skipping
NOTICE: table "pg_dist_transaction" does not exist, skipping
NOTICE: table "pg_dist_colocation" does not exist, skipping
NOTICE: table "pg_dist_authinfo" does not exist, skipping
NOTICE: table "pg_dist_poolinfo" does not exist, skipping
NOTICE: table "pg_dist_rebalance_strategy" does not exist, skipping
NOTICE: table "pg_dist_object" does not exist, skipping
NOTICE: table "pg_dist_cleanup" does not exist, skipping
NOTICE: table "pg_dist_schema" does not exist, skipping
NOTICE: table "pg_dist_clock_logical_seq" does not exist, skipping
citus_prepare_pg_upgrade
--------------------------
(1 row)
NOTICE: aggregate array_cat_agg(anyarray) does not exist, skipping
NOTICE: table "pg_dist_partition" does not exist, skipping
NOTICE: table "pg_dist_shard" does not exist, skipping
NOTICE: table "pg_dist_placement" does not exist, skipping
NOTICE: table "pg_dist_node_metadata" does not exist, skipping
NOTICE: table "pg_dist_node" does not exist, skipping
NOTICE: table "pg_dist_local_group" does not exist, skipping
NOTICE: table "pg_dist_transaction" does not exist, skipping
NOTICE: table "pg_dist_colocation" does not exist, skipping
NOTICE: table "pg_dist_authinfo" does not exist, skipping
NOTICE: table "pg_dist_poolinfo" does not exist, skipping
NOTICE: table "pg_dist_rebalance_strategy" does not exist, skipping
NOTICE: table "pg_dist_object" does not exist, skipping
NOTICE: table "pg_dist_cleanup" does not exist, skipping
NOTICE: table "pg_dist_schema" does not exist, skipping
NOTICE: table "pg_dist_clock_logical_seq" does not exist, skipping
citus_prepare_pg_upgrade
--------------------------
(1 row)
waiting for server to shut down.... done
server stopped
waiting for server to shut down.... done
server stopped
waiting for server to shut down.... done
server stopped
################### pg15 end #####################
################### pg16 start #####################
pg_ctl: directory "db1" does not exist
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory db1 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D db1 -l logfile start
pg_ctl: directory "db2" does not exist
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory db2 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D db2 -l logfile start
pg_ctl: directory "db3" does not exist
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory db3 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D db3 -l logfile start
################### pg16 end #####################
################### start upgrade #####################
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
*Clusters are compatible*
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
*Clusters are compatible*
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
*Clusters are compatible*
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Setting locale and encoding for new cluster ok
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Adding ".old" suffix to old global/pg_control ok
If you want to start the old cluster, you will need to remove
the ".old" suffix from 15/db1/global/pg_control.old.
Because "link" mode was used, the old cluster cannot be safely
started once the new cluster has been started.
Linking user relation files
ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/usr/lib/postgresql/16/bin/vacuumdb --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Setting locale and encoding for new cluster ok
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Adding ".old" suffix to old global/pg_control ok
If you want to start the old cluster, you will need to remove
the ".old" suffix from 15/db2/global/pg_control.old.
Because "link" mode was used, the old cluster cannot be safely
started once the new cluster has been started.
Linking user relation files
ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/usr/lib/postgresql/16/bin/vacuumdb --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for incompatible "aclitem" data type in user tables ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Setting locale and encoding for new cluster ok
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Adding ".old" suffix to old global/pg_control ok
If you want to start the old cluster, you will need to remove
the ".old" suffix from 15/db3/global/pg_control.old.
Because "link" mode was used, the old cluster cannot be safely
started once the new cluster has been started.
Linking user relation files
ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/usr/lib/postgresql/16/bin/vacuumdb --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
waiting for server to start.... done
server started
waiting for server to start.... done
server started
waiting for server to start.... done
server started
citus_finish_pg_upgrade
-------------------------
(1 row)
citus_finish_pg_upgrade
-------------------------
(1 row)
citus_finish_pg_upgrade
-------------------------
(1 row)
count
-------
10000
(1 row)
################### finish upgrade #####################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment