Skip to content

Commit 70657b7

Browse files
committed
auto delete alone node when create postgre node.
1 parent d7757b4 commit 70657b7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

image/postgresql/docker-entrypoint.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ main() {
189189
# pg_autoctl config set replication.password
190190
# alter user pgautofailover_replicator password 'h4ckm3m0r3';
191191
if [ ! -s "$PGDATA/PG_VERSION" ]; then
192-
primary_information_num=$(psql -p $run_port -t -A -d "postgres://autoctl_node:$AUTOCTL_NODE_PASSWORD@$MONITOR_HOSTNAME:$monitor_port/pg_auto_failover?sslmode=prefer" -c "select count(*) from pgautofailover.node where formationid='primary' ")
192+
alone_node=$(psql -t -A -d "postgres://autoctl_node:$AUTOCTL_NODE_PASSWORD@$MONITOR_HOSTNAME:$monitor_port/pg_auto_failover?sslmode=prefer" -c "select count(*) from pgautofailover.node where nodehost='$EXTERNAL_HOSTNAME' ")
193+
if [ "$alone_node" = 1 ]; then
194+
psql -t -A -d "postgres://autoctl_node:$AUTOCTL_NODE_PASSWORD@$MONITOR_HOSTNAME:$monitor_port/pg_auto_failover?sslmode=prefer" -c "delete from pgautofailover.node where nodehost='$EXTERNAL_HOSTNAME' "
195+
fi
196+
197+
primary_information_num=$(psql -t -A -d "postgres://autoctl_node:$AUTOCTL_NODE_PASSWORD@$MONITOR_HOSTNAME:$monitor_port/pg_auto_failover?sslmode=prefer" -c "select count(*) from pgautofailover.node where formationid='primary' ")
193198
if [ "$PG_MODE" = readwrite -a "$primary_information_num" = 0 ]; then
194199
temp_start_auto_failover "$cmd" 300
195200

0 commit comments

Comments
 (0)