/* * Remove the master standby. * * gp_remove_master_standby() * * Returns: * true upon success otherwise false */ Datum gp_remove_master_standby(PG_FUNCTION_ARGS) { int numDel; cqContext cqc; mirroring_sanity_check(SUPERUSER | MASTER_ONLY | UTILITY_MODE, "gp_remove_master_standby"); if (!standby_exists()) elog(ERROR, "no master standby defined"); Relation rel = heap_open(GpSegmentConfigRelationId, AccessExclusiveLock); numDel= caql_getcount(caql_addrel(cqclr(&cqc), rel), cql("DELETE FROM gp_segment_configuration " " WHERE role = :1", CharGetDatum(SEGMENT_ROLE_STANDBY_CONFIG))); elog(LOG, "Remove standby, count : %d.", numDel); heap_close(rel, NoLock); update_gp_master_mirroring("Not Configured"); PG_RETURN_BOOL(true); }
/* * Add a master standby. * * gp_add_master_standby(hostname, address) * * Args: * hostname - as above * address - as above * * Returns: * dbid of the new standby */ Datum gp_add_master_standby(PG_FUNCTION_ARGS) { CdbComponentDatabaseInfo *master = NULL; Relation gprel; Datum values[Natts_gp_segment_configuration]; bool nulls[Natts_gp_segment_configuration]; HeapTuple tuple; cqContext cqc; cqContext *pcqCtx = NULL; if (PG_ARGISNULL(0)) elog(ERROR, "host name cannot be NULL"); if (PG_ARGISNULL(1)) elog(ERROR, "address cannot be NULL"); mirroring_sanity_check(MASTER_ONLY | UTILITY_MODE, "gp_add_master_standby"); if (standby_exists()) elog(ERROR, "only a single master standby may be defined"); /* master */ master = registration_order_get_dbinfo(MASTER_ORDER_ID); /* Lock exclusively to avoid concurrent changes */ gprel = heap_open(GpSegmentConfigRelationId, AccessExclusiveLock); pcqCtx = caql_beginscan( caql_addrel(cqclr(&cqc), gprel), cql("INSERT INTO gp_segment_configuration ", NULL)); MemSet(nulls, false, sizeof(nulls)); values[Anum_gp_segment_configuration_registration_order - 1] = Int32GetDatum(STANDBY_ORDER_ID); values[Anum_gp_segment_configuration_role - 1] = CharGetDatum(SEGMENT_ROLE_STANDBY_CONFIG); values[Anum_gp_segment_configuration_status - 1] = CharGetDatum('u'); values[Anum_gp_segment_configuration_port - 1] = Int32GetDatum(master->port); values[Anum_gp_segment_configuration_hostname - 1] = PG_GETARG_DATUM(0); values[Anum_gp_segment_configuration_address - 1] = PG_GETARG_DATUM(1); nulls[Anum_gp_segment_configuration_description - 1] = true; tuple = caql_form_tuple(pcqCtx, values, nulls); /* insert a new tuple */ caql_insert(pcqCtx, tuple); /* implicit update of index as well */ caql_endscan(pcqCtx); if(master) pfree(master); heap_close(gprel, NoLock); PG_RETURN_INT16(1); }